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