| Conditions | 11 |
| Paths | 7 |
| Total Lines | 28 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 61 | public function supports(string $type, int $options = self::EXACT|self::COVARIANCE): bool |
||
| 62 | { |
||
| 63 | if (!$this->hasType()) { |
||
| 64 | // no type-hint so any type is supported |
||
| 65 | return true; |
||
| 66 | } |
||
| 67 | |||
| 68 | if ('null' === \mb_strtolower($type) && $this->parameter->allowsNull()) { |
||
| 69 | return true; |
||
| 70 | } |
||
| 71 | |||
| 72 | $type = self::TYPE_NORMALIZE_MAP[$type] ?? $type; |
||
| 73 | |||
| 74 | foreach ($this->types() as $supportedType) { |
||
| 75 | if ($options & self::EXACT && $supportedType === $type) { |
||
| 76 | return true; |
||
| 77 | } |
||
| 78 | |||
| 79 | if ($options & self::COVARIANCE && \is_a($type, $supportedType, true)) { |
||
| 80 | return true; |
||
| 81 | } |
||
| 82 | |||
| 83 | if ($options & self::CONTRAVARIANCE && \is_a($supportedType, $type, true)) { |
||
| 84 | return true; |
||
| 85 | } |
||
| 86 | } |
||
| 87 | |||
| 88 | return false; |
||
| 89 | } |
||
| 116 |