Conditions | 11 |
Paths | 9 |
Total Lines | 35 |
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 |
||
55 | private function walkObjectTree($objectOrArray, $query) |
||
56 | { |
||
57 | $node = $objectOrArray; |
||
58 | $objectPath = explode('.', $query); |
||
59 | |||
60 | // walk through the tree |
||
61 | foreach ($objectPath as $pathNode) { |
||
62 | if (is_array($node)) { |
||
63 | if (isset($node[$pathNode])) { |
||
64 | $node = $node[$pathNode]; |
||
65 | continue; |
||
66 | } |
||
67 | } elseif (is_object($node)) { |
||
68 | if (isset($node->{$pathNode}) || (method_exists($node, '__get') && $node->{$pathNode})) { |
||
69 | $node = $node->{$pathNode}; |
||
70 | continue; |
||
71 | } elseif (method_exists($node, $pathNode)) { |
||
72 | $node = $node->{$pathNode}(); |
||
73 | continue; |
||
74 | } elseif (method_exists($node, 'get' . $pathNode)) { |
||
75 | $pathNode = 'get' . $pathNode; |
||
76 | $node = $node->{$pathNode}(); |
||
77 | continue; |
||
78 | } elseif (method_exists($node, 'is' . $pathNode)) { |
||
79 | $pathNode = 'is' . $pathNode; |
||
80 | $node = $node->{$pathNode}(); |
||
81 | continue; |
||
82 | } |
||
83 | } |
||
84 | |||
85 | return null; |
||
86 | } |
||
87 | |||
88 | return $node; |
||
89 | } |
||
90 | } |
||
91 |