We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 10 |
| Paths | 22 |
| Total Lines | 36 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 20 |
| CRAP Score | 10.0107 |
| 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 |
||
| 19 | 6 | public function assert($input) |
|
| 20 | { |
||
| 21 | 6 | $exceptions = array(); |
|
| 22 | |||
| 23 | 6 | if (!is_array($input) || $input instanceof Traversable) { |
|
| 24 | 1 | throw $this->reportError($input); |
|
| 25 | } |
||
| 26 | |||
| 27 | 5 | if (empty($input)) { |
|
| 28 | return true; |
||
| 29 | } |
||
| 30 | |||
| 31 | 5 | foreach ($input as $key => $item) { |
|
| 32 | 5 | if (isset($this->itemValidator)) { |
|
| 33 | try { |
||
| 34 | 3 | $this->itemValidator->assert($item); |
|
| 35 | 3 | } catch (ValidationException $e) { |
|
| 36 | 1 | $exceptions[] = $e; |
|
| 37 | } |
||
| 38 | 3 | } |
|
| 39 | |||
| 40 | 5 | if (isset($this->keyValidator)) { |
|
| 41 | try { |
||
| 42 | 3 | $this->keyValidator->assert($key); |
|
| 43 | 3 | } catch (ValidationException $e) { |
|
| 44 | 1 | $exceptions[] = $e; |
|
| 45 | } |
||
| 46 | 3 | } |
|
| 47 | 5 | } |
|
| 48 | |||
| 49 | 5 | if (!empty($exceptions)) { |
|
| 50 | 2 | throw $this->reportError($input)->setRelated($exceptions); |
|
| 51 | } |
||
| 52 | |||
| 53 | 3 | return true; |
|
| 54 | } |
||
| 55 | |||
| 102 |