| Conditions | 10 |
| Paths | 16 |
| Total Lines | 30 |
| Code Lines | 18 |
| 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 |
||
| 17 | public function validateViewModelBySkel(ViewModelNode $vm, $skel = null) |
||
| 18 | { |
||
| 19 | if ($skel === null) { |
||
| 20 | $skel = $this->skel; |
||
| 21 | } |
||
| 22 | |||
| 23 | foreach ($skel as $key => $value) { |
||
| 24 | if (!is_array($value)) { |
||
| 25 | if (!isset($vm[$value])) { |
||
| 26 | throw new \InvalidArgumentException("$value not exists"); |
||
| 27 | } |
||
| 28 | } elseif (empty($value)) { |
||
| 29 | if (!isset($vm[$key])) { |
||
| 30 | throw new \InvalidArgumentException("$key not exists"); |
||
| 31 | } |
||
| 32 | foreach ($vm[$key] as $k => $v) { |
||
| 33 | if (!is_numeric($k)) { |
||
| 34 | throw new \InvalidArgumentException("$key is not sequential array. Contains not numeric key ($k)"); |
||
| 35 | } |
||
| 36 | } |
||
| 37 | } else { |
||
| 38 | if (!isset($vm[$key])) { |
||
| 39 | throw new \InvalidArgumentException("$key not exists"); |
||
| 40 | } |
||
| 41 | $this->validateViewModelBySkel($vm[$key], $value); |
||
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 45 | return true; |
||
| 46 | } |
||
| 47 | } |
||
| 48 |