| Conditions | 14 |
| Paths | 132 |
| Total Lines | 65 |
| Code Lines | 47 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 23 | public function updateCMSFields(FieldList $fields) |
||
| 24 | { |
||
| 25 | $currentStatus = $this->owner->Status(); |
||
| 26 | //start hack |
||
| 27 | if($currentStatus && $currentStatus->ClassName === 'OrderStep_Sent') { |
||
| 28 | $orderStepGood = OrderStep::get()->filter(array('Code' => 'OrderStep_QuickDispatch'))->first(); |
||
| 29 | if($orderStepGood && $this->owner->StatusID != $orderStepGood->ID) { |
||
| 30 | $orderStepBad = OrderStep::get()->filter(array('Code' => 'OrderStep_Sent'))->first(); |
||
| 31 | if($orderStepBad && $this->owner->StatusID == $orderStepBad->ID) { |
||
| 32 | $this->owner->StatusID = $orderStepGood->ID; |
||
| 33 | $this->owner->write(); |
||
| 34 | } |
||
| 35 | } |
||
| 36 | } |
||
| 37 | //end hack |
||
| 38 | if($currentStatus && $currentStatus instanceof OrderStep_QuickDispatch) { |
||
| 39 | $allFields = Config::inst()->get('Order_QuickDispatch', 'remove_parent_log_field') ? false : true; |
||
| 40 | if($allFields) { |
||
| 41 | $headerField1 = HeaderField::create('QuickDispatchHeader1', ' - Option A: Quick Dispatch', 5); |
||
| 42 | } else { |
||
| 43 | $headerField1 = HiddenField::create('QuickDispatchHeader1'); |
||
| 44 | } |
||
| 45 | $checkboxfield = OptionSetField::create( |
||
| 46 | 'HasBeenDispatched', |
||
| 47 | 'Has been dispatched', |
||
| 48 | array( |
||
| 49 | 0 => _t('Order_QuickDispatch.NOT_YET', 'Not yet'), |
||
| 50 | 1 => _t('Order_QuickDispatch.GONE', 'It\'s Gone') |
||
| 51 | ) |
||
| 52 | ); |
||
| 53 | if(class_exists('DataObjectOneFieldUpdateController')) { |
||
| 54 | $link = DataObjectOneFieldUpdateController::popup_link( |
||
| 55 | $ClassName = 'Order', |
||
| 56 | $FieldName = 'HasBeenDispatched', |
||
| 57 | $where = 'StatusID = '.$this->owner->StatusID, |
||
| 58 | $sort = 'ID', |
||
| 59 | $linkText = 'Batch Dispatch', |
||
| 60 | $titleField = "Title" |
||
| 61 | ); |
||
| 62 | $checkboxfield->setDescription('You can also do a: '.$link); |
||
| 63 | } |
||
| 64 | if($allFields) { |
||
| 65 | $headerField2 = HeaderField::create('QuickDispatchHeader2', ' - Option B: Detailed Dispatch', 5); |
||
| 66 | } else { |
||
| 67 | $headerField2 = HiddenField::create('QuickDispatchHeader2'); |
||
| 68 | } |
||
| 69 | $fields->addFieldsToTab( |
||
| 70 | 'Root.Next', |
||
| 71 | array( |
||
| 72 | $headerField1, |
||
| 73 | $checkboxfield, |
||
| 74 | $headerField2 |
||
| 75 | ), |
||
| 76 | 'OrderStatusLog_DispatchPhysicalOrder' |
||
| 77 | ); |
||
| 78 | if(! $allFields) { |
||
| 79 | $fields->removeFieldFromTab( |
||
| 80 | 'Root.Next', |
||
| 81 | 'OrderStatusLog_DispatchPhysicalOrder' |
||
| 82 | ); |
||
| 83 | } |
||
| 84 | } else { |
||
| 85 | $fields->removeByName('HasBeenDispatched'); |
||
| 86 | } |
||
| 87 | } |
||
| 88 | |||
| 109 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.