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