| Conditions | 10 |
| Paths | 3 |
| Total Lines | 44 |
| 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 |
||
| 32 | public function Content() |
||
| 33 | { |
||
| 34 | $submittedOrders = $this->submittedOrders(); |
||
| 35 | $html = ' |
||
| 36 | <ul>'; |
||
| 37 | $buyableArray = array(); |
||
| 38 | $count = $submittedOrders->count(); |
||
| 39 | if ($count < $this->maxOrdersForLoop() && $count > 0) { |
||
| 40 | foreach ($submittedOrders as $order) { |
||
| 41 | foreach ($order->Items() as $item) { |
||
| 42 | $key = $item->BuyableClassName.".".$item->BuyableID; |
||
| 43 | if (! isset($buyableArray[$key])) { |
||
| 44 | $buyableArray[$key] = 0; |
||
| 45 | } |
||
| 46 | $buyableArray[$key]++; |
||
| 47 | } |
||
| 48 | } |
||
| 49 | arsort($buyableArray, SORT_NUMERIC); |
||
| 50 | for ($i = 0; $i < $this->NumberOfProducts; $i++) { |
||
| 51 | $oneRow = array_slice($buyableArray, $i, 1); |
||
| 52 | foreach ($oneRow as $key => $count) { |
||
| 53 | list($className, $id) = explode('.', $key); |
||
| 54 | $buyable = $className::get()->byID($id); |
||
| 55 | if ($buyable) { |
||
| 56 | $html .= '<li class="pos'.$i.'"><span><strong>'.$count.'</strong> × </span><a href="'.$buyable->Link().'">'.$buyable->FullName.'</a></li>'; |
||
| 57 | } else { |
||
| 58 | $html .= '<li class="pos'.$i.'">Error with '.$key.'</li>'; |
||
| 59 | } |
||
| 60 | } |
||
| 61 | } |
||
| 62 | } elseif ($count >= $this->maxOrdersForLoop()) { |
||
| 63 | $html .= ' |
||
| 64 | <li>There are too many orders to work out the favourite products, please reduce the time period.</li>'; |
||
| 65 | } else { |
||
| 66 | $html .= ' |
||
| 67 | <li>There are no favourite sellers.</li>'; |
||
| 68 | } |
||
| 69 | |||
| 70 | |||
| 71 | $html .= ' |
||
| 72 | </ul>'; |
||
| 73 | |||
| 74 | return $html; |
||
| 75 | } |
||
| 76 | } |
||
| 77 |
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.