| Conditions | 12 |
| Paths | 12 |
| Total Lines | 36 |
| 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 |
||
| 65 | private static function matchType(\ReflectionParameter $parameter, $value) : bool |
||
| 66 | { |
||
| 67 | if (!$type = $parameter->getType()) { |
||
| 68 | return true; |
||
| 69 | } |
||
| 70 | |||
| 71 | $typeName = $type->getName(); |
||
| 72 | |||
| 73 | if ('array' === $typeName) { |
||
| 74 | return \is_array($value); |
||
| 75 | } |
||
| 76 | |||
| 77 | if ('callable' === $typeName) { |
||
| 78 | return \is_callable($value); |
||
| 79 | } |
||
| 80 | |||
| 81 | if (!$type->isBuiltin()) { |
||
| 82 | if (!\is_object($value)) { |
||
| 83 | return false; |
||
| 84 | } |
||
| 85 | |||
| 86 | $class = new \ReflectionClass($typeName); |
||
| 87 | |||
| 88 | return $class && $class->isInstance($value); |
||
| 89 | } |
||
| 90 | |||
| 91 | switch ($typeName) { |
||
| 92 | case 'bool': return \is_bool($value); |
||
| 93 | case 'float': return \is_float($value); |
||
| 94 | case 'int': return \is_int($value); |
||
| 95 | case 'string': return \is_string($value); |
||
| 96 | case 'iterable': return \is_iterable($value); |
||
| 97 | } |
||
| 98 | |||
| 99 | return true; |
||
| 100 | } |
||
| 101 | |||
| 148 |