Conditions | 17 |
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 |
||
112 | public function supports(string $type, int $options = self::EXACT|self::COVARIANCE): bool |
||
113 | { |
||
114 | if (!$this->hasType()) { |
||
115 | // no type-hint so any type is supported |
||
116 | return true; |
||
117 | } |
||
118 | |||
119 | if ('null' === \mb_strtolower($type) && $this->parameter->allowsNull()) { |
||
120 | return true; |
||
121 | } |
||
122 | |||
123 | $type = self::TYPE_NORMALIZE_MAP[$type] ?? $type; |
||
124 | |||
125 | foreach ($this->types() as $supportedType) { |
||
126 | if ($supportedType === $type) { |
||
127 | return true; |
||
128 | } |
||
129 | |||
130 | if ($options & self::COVARIANCE && \is_a($type, $supportedType, true)) { |
||
131 | return true; |
||
132 | } |
||
133 | |||
134 | if ($options & self::CONTRAVARIANCE && \is_a($supportedType, $type, true)) { |
||
135 | return true; |
||
136 | } |
||
137 | |||
138 | if ($options & self::VERY_STRICT) { |
||
139 | continue; |
||
140 | } |
||
141 | |||
142 | if ('float' === $supportedType && 'int' === $type) { |
||
143 | // strict typing allows int to pass a float validation |
||
144 | return true; |
||
145 | } |
||
146 | |||
147 | if ($options & self::STRICT) { |
||
148 | continue; |
||
149 | } |
||
150 | |||
151 | if (\in_array($type, self::ALLOWED_TYPE_MAP[$supportedType] ?? [], true)) { |
||
152 | return true; |
||
153 | } |
||
154 | |||
155 | if ('string' === $supportedType && \method_exists($type, '__toString')) { |
||
156 | return true; |
||
157 | } |
||
158 | } |
||
159 | |||
160 | return false; |
||
161 | } |
||
208 |