Conditions | 10 |
Paths | 1 |
Total Lines | 36 |
Code Lines | 19 |
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 |
||
65 | public function getMatchers() |
||
66 | { |
||
67 | return array( |
||
68 | 'haveItem' => function(Item $menu, $itemName, $elementId = false) { |
||
69 | $items = $menu->getChildren(); |
||
70 | foreach ($items as $item) { |
||
71 | if ($item->getName() === $itemName) { |
||
72 | if (!$elementId) { |
||
73 | return true; |
||
74 | } |
||
75 | |||
76 | /** @var ElementItem $item */ |
||
77 | return $item->getElement()->getId() === $elementId; |
||
78 | } |
||
79 | } |
||
80 | return false; |
||
81 | }, |
||
82 | 'haveItemThatHaveChild' => function(Item $menu, $itemName, $childName, $elementId = false) { |
||
83 | foreach ($menu->getChildren() as $item) { |
||
84 | if ($item->getName() === $itemName && $item->hasChildren()) { |
||
85 | foreach ($item->getChildren() as $child) { |
||
86 | if ($child->getName() === $childName) { |
||
87 | if (!$elementId) { |
||
88 | return true; |
||
89 | } |
||
90 | |||
91 | /** @var ElementItem $child */ |
||
92 | return $child->getElement()->getId() === $elementId; |
||
93 | } |
||
94 | } |
||
95 | } |
||
96 | } |
||
97 | return false; |
||
98 | } |
||
99 | ); |
||
100 | } |
||
101 | } |
||
102 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.