I would like to post a public method of one of my models for your review. What would you add/change to improve readability and/or testability and code quality.
Application_Procedure_Model and Application_Customer_Model are external services simply wrapped by model objects and will eventually be brought into context via service locator so to mock the objects as opposed to stubbing them as I currently do.
What would you test for/validate? Would you use a repository to abstract the query construction? Can you show me examples?
public function createWorkOrder
(
$id_type = self::TYPE_OVERHAUL,
$id_options = 0,
$id_customer = 0,
$id_manufacturer = 0,
$serial_number = 'NSN',
$quantity = 1,
$model_number = 'NA',
$part_number = '',
$part_name = 'UNKNOWN',
$purchase_order = '',
$rpi_number = '1',
$notes = ''
)
{
$rpi_revision = 0;
$id_stage = self::STAGE_PREQUOTING;
$id_warehouse = self::WAREHOUSE_WIP;
$time_received = time();
$time_approved = ($id_options & self::OPTION_APPROVED ? $time_received : 0);
$params = array
(
'id_type' => $id_type,
'id_station' => Application_Sequence_Model::STATION_RECEIVING,
'id_stage' => $id_stage,
'id_options' => $id_options,
'id_warehouse' => $id_warehouse,
'id_customer' => $id_customer,
'id_manufacturer' => $id_manufacturer,
'date_received' => $time_received,
'date_approved' => $time_approved,
'date_promised' => 0,
'date_inspected' => 0,
'date_scheduled' => 0,
'date_completed' => 0,
'quantity' => $quantity,
'rpi_revision' => $rpi_revision,
'rpi_number' => $rpi_number,
'purchase_order' => $purchase_order,
'serial_number' => $serial_number,
'model_number' => $model_number,
'part_number' => $part_number,
'part_name' => $part_name,
'status' => '',
'quote' => '',
'notes' => $notes
);
$id_workorder = $this->erp->getGateway()->createRecord(self::T_ERP_WORKORDER, $params);
$procedure = new Application_Procedure_Model();
$master = $procedure->selectProcedureMaster($rpi_number);
$this->buildWorkOrderFromRpi($procedure, $id_workorder, $rpi_number, $master['quote_step']);
// NOTE: Update RPI revision on work order according details returned by $procedure object
// there is no way of us knowing before we clone RPI so we do it now :)
$this->erp->getGateway()->updateRecord
(
self::T_ERP_WORKORDER,
array(
'cost_overhaul' => $master['cost_overhaul'],
'rpi_revision' => $master['revision']
),
array('id_primary' => $id_workorder)
);
// NOTE: Notify the RPI system via a automated task of the incoming part
if($rpi_number == '1'){
$customer = new Application_Customer_Model();
$customer = $customer->returnCustomer($id_customer);
$procedure->createProcedureTaskForRpi($id_workorder, $part_name, $part_number, $customer['name']);
}
$time_estimate = $this->scheduleWorkOrder($id_workorder, $time_received);
return $id_workorder;
}
Cheers,
Alex