Conditions | 13 |
Paths | 1 |
Total Lines | 42 |
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 |
||
66 | public function getMatchers(): array |
||
67 | { |
||
68 | return [ |
||
69 | 'haveItem' => function(Item $menu, string $itemName, ?string $elementId = null, ?array $parameters = []) { |
||
70 | $items = $menu->getChildren(); |
||
71 | foreach ($items as $item) { |
||
72 | if ($item->getName() === $itemName) { |
||
73 | if (null === $elementId) { |
||
74 | return true; |
||
75 | } |
||
76 | |||
77 | if ($item instanceof ElementItem) { |
||
78 | /** @var ElementItem $item */ |
||
79 | return $item->getElement()->getId() === $elementId; |
||
80 | } |
||
81 | |||
82 | if ($item instanceof RoutableItem) { |
||
83 | return $item->getRoute() === $elementId && $item->getRouteParameters() === $parameters; |
||
84 | } |
||
85 | } |
||
86 | } |
||
87 | return false; |
||
88 | }, |
||
89 | 'haveItemThatHaveChild' => function(Item $menu, $itemName, $childName, $elementId = false) { |
||
90 | foreach ($menu->getChildren() as $item) { |
||
91 | if ($item->getName() === $itemName && $item->hasChildren()) { |
||
92 | foreach ($item->getChildren() as $child) { |
||
93 | if ($child->getName() === $childName) { |
||
94 | if (!$elementId) { |
||
95 | return true; |
||
96 | } |
||
97 | |||
98 | /** @var ElementItem $child */ |
||
99 | return $child->getElement()->getId() === $elementId; |
||
100 | } |
||
101 | } |
||
102 | } |
||
103 | } |
||
104 | return false; |
||
105 | } |
||
106 | ]; |
||
107 | } |
||
108 | } |
||
109 |
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.