| Conditions | 7 |
| Paths | 9 |
| Total Lines | 58 |
| Code Lines | 32 |
| 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 |
||
| 147 | private function loadPositionAnnotationFields( |
||
| 148 | ReflectionClass $class, |
||
| 149 | ?string $annotationClass, |
||
| 150 | ?string $action |
||
| 151 | ): array { |
||
| 152 | $propertiesAndMethods = array_merge( |
||
| 153 | $this->getClassPropertiesAnnotations($class, $annotationClass), |
||
| 154 | $this->getClassMethodsAnnotations($class, $annotationClass) |
||
| 155 | ); |
||
| 156 | |||
| 157 | $propertiesWithPosition = []; |
||
| 158 | $propertiesWithoutPosition = []; |
||
| 159 | |||
| 160 | foreach ($propertiesAndMethods as $name => $annotations) { |
||
| 161 | /** @var PositionAnnotationInterface $annotation */ |
||
| 162 | foreach ($annotations as $annotation) { |
||
| 163 | if (!$this->isSupported($annotation, $action)) { |
||
| 164 | continue; |
||
| 165 | } |
||
| 166 | |||
| 167 | if ($annotation instanceof AssociationFieldInterface) { |
||
| 168 | $name = sprintf('%s.%s', $name, $annotation->field); |
||
| 169 | } |
||
| 170 | |||
| 171 | if (!isset($annotation->position)) { |
||
| 172 | $propertiesWithoutPosition[] = [ |
||
| 173 | 'name' => $name, |
||
| 174 | 'annotation' => $annotation, |
||
| 175 | ]; |
||
| 176 | continue; |
||
| 177 | } |
||
| 178 | |||
| 179 | if (array_key_exists( |
||
| 180 | $annotation->position, |
||
| 181 | $propertiesWithPosition |
||
| 182 | )) { |
||
| 183 | throw new InvalidArgumentException( |
||
| 184 | sprintf( |
||
| 185 | 'Position "%s" is already in use by "%s", try setting a different position for "%s".', |
||
| 186 | $annotation->position, |
||
| 187 | $propertiesWithPosition[$annotation->position]['name'], |
||
| 188 | $name |
||
| 189 | ) |
||
| 190 | ); |
||
| 191 | } |
||
| 192 | |||
| 193 | $propertiesWithPosition[$annotation->position] = [ |
||
| 194 | 'name' => $name, |
||
| 195 | 'annotation' => $annotation, |
||
| 196 | ]; |
||
| 197 | } |
||
| 198 | } |
||
| 199 | |||
| 200 | ksort($propertiesWithPosition); |
||
| 201 | |||
| 202 | return array_merge( |
||
| 203 | $propertiesWithPosition, |
||
| 204 | $propertiesWithoutPosition |
||
| 205 | ); |
||
| 208 | } |