| Conditions | 11 |
| Paths | 10 |
| Total Lines | 27 |
| Code Lines | 20 |
| 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 |
||
| 26 | protected static function getArgument($argument, $arrayToSequence = true) |
||
| 27 | { |
||
| 28 | if (is_array($argument)) { |
||
| 29 | if (empty($argument)) { |
||
| 30 | throw new \InvalidArgumentException('Empty array argument'); |
||
| 31 | } elseif (count($argument) === 1) { |
||
| 32 | return self::getArgument(reset($argument)); |
||
| 33 | } |
||
| 34 | |||
| 35 | return $arrayToSequence ? new Sequence(...$argument) : new Choice(...$argument); |
||
| 36 | } elseif (is_string($argument)) { |
||
| 37 | switch (strlen($argument)) { |
||
| 38 | case 0: |
||
| 39 | throw new \InvalidArgumentException('Empty argument'); |
||
| 40 | case 1: |
||
| 41 | return new Char($argument); |
||
| 42 | default: |
||
| 43 | return new Text($argument); |
||
| 44 | } |
||
| 45 | } elseif (is_int($argument)) { |
||
| 46 | return new Char($argument); |
||
| 47 | } elseif ($argument instanceof Parser) { |
||
| 48 | return $argument; |
||
| 49 | } |
||
| 50 | |||
| 51 | throw new \InvalidArgumentException(sprintf('Invalid argument type `%1$s`', |
||
| 52 | is_object($argument) ? get_class($argument) : gettype($argument))); |
||
| 53 | } |
||
| 62 |