Conditions | 5 |
Paths | 3 |
Total Lines | 52 |
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 |
||
37 | public function Content() |
||
38 | { |
||
39 | $submittedOrders = $this->submittedOrders(); |
||
40 | $submittedOrders = $submittedOrders->filter(array('CurrencyUsedID' => $this->EcommerceCurrencyID)); |
||
41 | $count = $submittedOrders->count(); |
||
42 | $sum = 0; |
||
43 | $itemCount = 0; |
||
44 | $html = ' |
||
45 | <dl>'; |
||
46 | $html .= ' |
||
47 | <dt>Count of orders</dt> |
||
48 | <dd>'.$count.'</dd>'; |
||
49 | if ($count < $this->maxOrdersForLoop() && $count > 0) { |
||
50 | foreach ($submittedOrders as $order) { |
||
51 | $sum += $order->getSubTotal(); |
||
52 | $itemCount += $order->getTotalItemsTimesQuantity(); |
||
53 | } |
||
54 | $sumDBField = DBField::create_field('Currency', $sum); |
||
55 | $html .= ' |
||
56 | <dt>Sum of sub-totals</dt> |
||
57 | <dd>'.$sumDBField->Nice().'</dd>'; |
||
58 | $averagePerOrder = ($sum / $count); |
||
59 | $averagePerOrderDBField = DBField::create_field('Currency', $averagePerOrder); |
||
60 | $html .= ' |
||
61 | <dt>Average sub-total per order</dt> |
||
62 | <dd>'.$averagePerOrderDBField->Nice().'</dd>'; |
||
63 | $html .= ' |
||
64 | <dt>Total count of items sold</dt> |
||
65 | <dd>'.$itemCount.'</dd>'; |
||
66 | $itemCountPerOrder = round($itemCount / $count, 3); |
||
67 | $html .= ' |
||
68 | <dt>Average items sold per order</dt> |
||
69 | <dd>'.$itemCountPerOrder.'</dd>'; |
||
70 | $costPerItem = $sum / $itemCount; |
||
71 | $costPerItemDBField = DBField::create_field('Currency', $costPerItem); |
||
72 | $html .= ' |
||
73 | <dt>Average cost per item</dt> |
||
74 | <dd>'.$costPerItemDBField->Nice().'</dd>'; |
||
75 | } elseif ($count >= $this->maxOrdersForLoop()) { |
||
76 | $html .= ' |
||
77 | <dt>Sum of sub-totals</dt> |
||
78 | <dd>Please reduce the number of orders to calculate the total.</dd>'; |
||
79 | } else { |
||
80 | //.. |
||
81 | } |
||
82 | |||
83 | |||
84 | $html .= ' |
||
85 | </dl>'; |
||
86 | |||
87 | return $html; |
||
88 | } |
||
89 | } |
||
90 |
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.