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 |
||
99 | public function supports(string $type, int $options = self::EXACT|self::COVARIANCE): bool |
||
100 | { |
||
101 | if (!$this->hasType()) { |
||
102 | // no type-hint so any type is supported |
||
103 | return true; |
||
104 | } |
||
105 | |||
106 | if ('null' === \mb_strtolower($type) && $this->parameter->allowsNull()) { |
||
107 | return true; |
||
108 | } |
||
109 | |||
110 | $type = self::TYPE_NORMALIZE_MAP[$type] ?? $type; |
||
111 | |||
112 | foreach ($this->types() as $supportedType) { |
||
113 | if ($supportedType === $type) { |
||
114 | return true; |
||
115 | } |
||
116 | |||
117 | if ($options & self::COVARIANCE && \is_a($type, $supportedType, true)) { |
||
118 | return true; |
||
119 | } |
||
120 | |||
121 | if ($options & self::CONTRAVARIANCE && \is_a($supportedType, $type, true)) { |
||
122 | return true; |
||
123 | } |
||
124 | |||
125 | if ($options & self::VERY_STRICT) { |
||
126 | continue; |
||
127 | } |
||
128 | |||
129 | if ('float' === $supportedType && 'int' === $type) { |
||
130 | // strict typing allows int to pass a float validation |
||
131 | return true; |
||
132 | } |
||
133 | |||
134 | if ($options & self::STRICT) { |
||
135 | continue; |
||
136 | } |
||
137 | |||
138 | if (\in_array($type, self::ALLOWED_TYPE_MAP[$supportedType] ?? [], true)) { |
||
139 | return true; |
||
140 | } |
||
141 | |||
142 | if (\method_exists($type, '__toString')) { |
||
143 | return true; |
||
144 | } |
||
145 | } |
||
146 | |||
147 | return false; |
||
148 | } |
||
195 |