Conditions | 14 |
Paths | 17 |
Total Lines | 39 |
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 |
||
67 | private function validate($configuration, $path = null) |
||
68 | { |
||
69 | if (!is_array($configuration)) { |
||
70 | throw new InvalidArgument('configuration ' . (is_null($path) ? '' : ' in path "' . $path . '" ') . 'must be an array'); |
||
71 | } |
||
72 | |||
73 | if (empty($configuration)) { |
||
74 | throw new InvalidArgument('configuration ' . (is_null($path) ? '' : ' in path "' . $path . '" ') . 'can not be empty'); |
||
75 | } |
||
76 | |||
77 | foreach ($configuration as $index => $arrayOrCallable) { |
||
78 | $currentPath = (is_null($path)) ? $index : $path . '/' . $index; |
||
79 | |||
80 | if (is_string($arrayOrCallable)) { |
||
81 | if (!is_callable($arrayOrCallable)) { |
||
82 | throw new InvalidArgument('method in path "' . $currentPath . '" must be callable'); |
||
83 | } |
||
84 | } else if (is_array($arrayOrCallable)) { |
||
85 | $object = current($arrayOrCallable); |
||
86 | |||
87 | if (is_object($object) && $this->isNotAnClosure($object)) { |
||
88 | $methodName = $arrayOrCallable[1]; |
||
89 | if (!method_exists($object, $methodName)) { |
||
90 | throw new InvalidArgument( |
||
91 | 'provided instance of "' . get_class($object) . '" in path "' . $currentPath . '" does not have the method "' . $methodName . '"' |
||
92 | ); |
||
93 | } |
||
94 | } else { |
||
95 | $this->validate($arrayOrCallable, $currentPath); |
||
96 | } |
||
97 | } else { |
||
98 | if ($this->isNotAnClosure($arrayOrCallable)) { |
||
99 | throw new InvalidArgument( |
||
100 | 'can not handle value "' . var_export($arrayOrCallable, true) . '" in path "' . $currentPath . '"' |
||
101 | ); |
||
102 | } |
||
103 | } |
||
104 | } |
||
105 | } |
||
106 | |||
116 |