| Conditions | 16 |
| Paths | 12 |
| Total Lines | 49 |
| Code Lines | 23 |
| 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 |
||
| 86 | public function supports(string $type, int $options = self::EXACT|self::COVARIANCE): bool |
||
| 87 | { |
||
| 88 | if (!$this->hasType()) { |
||
| 89 | // no type-hint so any type is supported |
||
| 90 | return true; |
||
| 91 | } |
||
| 92 | |||
| 93 | if ('null' === \mb_strtolower($type) && $this->parameter->allowsNull()) { |
||
| 94 | return true; |
||
| 95 | } |
||
| 96 | |||
| 97 | $type = self::TYPE_NORMALIZE_MAP[$type] ?? $type; |
||
| 98 | |||
| 99 | foreach ($this->types() as $supportedType) { |
||
| 100 | if ($supportedType === $type) { |
||
| 101 | return true; |
||
| 102 | } |
||
| 103 | |||
| 104 | if ($options & self::COVARIANCE && \is_a($type, $supportedType, true)) { |
||
| 105 | return true; |
||
| 106 | } |
||
| 107 | |||
| 108 | if ($options & self::CONTRAVARIANCE && \is_a($supportedType, $type, true)) { |
||
| 109 | return true; |
||
| 110 | } |
||
| 111 | |||
| 112 | if ($options & self::VERY_STRICT) { |
||
| 113 | continue; |
||
| 114 | } |
||
| 115 | |||
| 116 | if ('float' === $supportedType && 'int' === $type) { |
||
| 117 | // strict typing allows int to pass a float validation |
||
| 118 | return true; |
||
| 119 | } |
||
| 120 | |||
| 121 | if ($options & self::STRICT) { |
||
| 122 | continue; |
||
| 123 | } |
||
| 124 | |||
| 125 | if (\in_array($type, self::ALLOWED_TYPE_MAP[$supportedType] ?? [], true)) { |
||
| 126 | return true; |
||
| 127 | } |
||
| 128 | |||
| 129 | if (\method_exists($type, '__toString')) { |
||
| 130 | return true; |
||
| 131 | } |
||
| 132 | } |
||
| 133 | |||
| 134 | return false; |
||
| 135 | } |
||
| 182 |