Conditions | 11 |
Paths | 56 |
Total Lines | 46 |
Code Lines | 28 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 0 | Features | 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 |
||
98 | public function updateCMSFields(FieldList $fields) |
||
99 | { |
||
100 | $main = $fields->findOrMakeTab("Root.Main"); |
||
101 | $statuses = $this->owner->config()->get("statuses"); |
||
102 | $details = null; |
||
103 | $totals = null; |
||
104 | $misc = null; |
||
105 | $discounts = $fields->dataFieldByName('Discounts'); |
||
106 | |||
107 | // Switch unlink action to delete |
||
108 | if ($discounts) { |
||
109 | $discounts |
||
110 | ->getConfig() |
||
111 | ->removeComponentsByType(GridFieldDeleteAction::class) |
||
112 | ->removeComponentsByType(GridFieldAddExistingAutocompleter::class) |
||
113 | ->addComponent(new GridFieldDeleteAction()); |
||
114 | } |
||
115 | |||
116 | $discount_code = $fields->dataFieldByName('DiscountCode'); |
||
117 | $discount_amount = $fields->dataFieldByName('DiscountTotal'); |
||
118 | |||
119 | // Manually loop through fields to find info composite field, as |
||
120 | // fieldByName cannot reliably find this. |
||
121 | foreach ($main->getChildren() as $field) { |
||
122 | if ($field->getName() == "OrdersDetails") { |
||
123 | foreach ($field->getChildren() as $field) { |
||
124 | if ($field->getName() == "OrdersDetailsTotals") { |
||
125 | $totals = $field; |
||
126 | } |
||
127 | if ($field->getName() == "OrdersDetailsMisc") { |
||
128 | $misc = $field; |
||
129 | } |
||
130 | } |
||
131 | } |
||
132 | } |
||
133 | |||
134 | if ($totals && $discount_amount) { |
||
135 | $totals->insertBefore( |
||
136 | "TotalValue", |
||
137 | $discount_amount |
||
138 | ); |
||
139 | } |
||
140 | |||
141 | if ($misc && $discount_code) { |
||
142 | $misc->push( |
||
143 | $discount_code |
||
144 | ); |
||
160 |