Conditions | 13 |
Paths | 20 |
Total Lines | 75 |
Code Lines | 42 |
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 |
||
71 | protected function configureReaderFields( |
||
72 | ReflectionClass $class, |
||
73 | MapperInterface $mapper, |
||
74 | ?string $annotationClass = null, |
||
75 | ?string $action = null |
||
76 | ): void { |
||
77 | $propertiesAndMethods = array_merge( |
||
78 | $this->getClassPropertiesAnnotations($class, $annotationClass), |
||
79 | $this->getClassMethodsAnnotations($class, $annotationClass) |
||
80 | ); |
||
81 | |||
82 | $fields = []; |
||
83 | $propertiesWithPosition = []; |
||
84 | $propertiesWithoutPosition = []; |
||
85 | |||
86 | foreach ($propertiesAndMethods as $name => $annotations) { |
||
87 | foreach ($annotations as $annotation) { |
||
88 | if ($annotation instanceof ActionAnnotationInterface |
||
89 | && $action !== null |
||
90 | && isset($annotation->action) |
||
91 | && $annotation->action !== $action |
||
92 | ) { |
||
93 | continue; |
||
94 | } |
||
95 | |||
96 | if ($annotation instanceof AssociationFieldInterface) { |
||
97 | $name = sprintf('%s.%s', $name, $annotation->field); |
||
98 | } |
||
99 | |||
100 | if ($annotation instanceof PositionAnnotationInterface) { |
||
101 | if (!isset($annotation->position)) { |
||
102 | $propertiesWithoutPosition[] = [ |
||
103 | 'name' => $name, |
||
104 | 'annotation' => $annotation, |
||
105 | ]; |
||
106 | continue; |
||
107 | } |
||
108 | |||
109 | if (array_key_exists( |
||
110 | $annotation->position, |
||
111 | $propertiesWithPosition |
||
112 | )) { |
||
113 | throw new InvalidArgumentException( |
||
114 | sprintf( |
||
115 | 'Position "%s" is already in use by "%s", try setting a different position for "%s".', |
||
116 | $annotation->position, |
||
117 | $propertiesWithPosition[$annotation->position]['name'], |
||
118 | $name |
||
119 | ) |
||
120 | ); |
||
121 | } |
||
122 | |||
123 | $propertiesWithPosition[$annotation->position] = [ |
||
124 | 'name' => $name, |
||
125 | 'annotation' => $annotation, |
||
126 | ]; |
||
127 | } |
||
128 | } |
||
129 | } |
||
130 | |||
131 | if (!empty($propertiesWithPosition) |
||
132 | || !empty($propertiesWithoutPosition) |
||
133 | ) { |
||
134 | ksort($propertiesWithPosition); |
||
135 | |||
136 | $fields = array_merge( |
||
137 | $propertiesWithPosition, |
||
138 | $propertiesWithoutPosition |
||
139 | ); |
||
140 | } |
||
141 | |||
142 | |||
143 | array_walk( |
||
144 | $fields, |
||
145 | fn(array $field) => $this->addMapperProperty($mapper, $field) |
||
146 | ); |
||
174 | } |