Conditions | 9 |
Paths | 9 |
Total Lines | 53 |
Code Lines | 38 |
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 |
||
156 | protected function addAssociations(array &$fields): void |
||
157 | { |
||
158 | $classMetadata = $this->entityManager->getClassMetadata($this->getEntityClass()); |
||
159 | |||
160 | foreach ($classMetadata->getAssociationNames() as $associationName) { |
||
161 | if (! in_array($associationName, array_keys($this->metadata['fields']))) { |
||
162 | continue; |
||
163 | } |
||
164 | |||
165 | $associationMetadata = $classMetadata->getAssociationMapping($associationName); |
||
166 | |||
167 | switch ($associationMetadata['type']) { |
||
168 | case ClassMetadataInfo::ONE_TO_ONE: |
||
169 | case ClassMetadataInfo::MANY_TO_ONE: |
||
170 | case ClassMetadataInfo::TO_ONE: |
||
171 | $targetEntity = $associationMetadata['targetEntity']; |
||
172 | $fields[$associationName] = function () use ($targetEntity) { |
||
173 | $entity = $this->typeManager->build(self::class, $targetEntity); |
||
174 | |||
175 | return [ |
||
176 | 'type' => $entity->getGraphQLType(), |
||
177 | 'description' => $entity->getDescription(), |
||
178 | ]; |
||
179 | }; |
||
180 | break; |
||
181 | case ClassMetadataInfo::ONE_TO_MANY: |
||
182 | case ClassMetadataInfo::MANY_TO_MANY: |
||
183 | case ClassMetadataInfo::TO_MANY: |
||
184 | $targetEntity = $associationMetadata['targetEntity']; |
||
185 | $fields[$associationName] = function () use ($targetEntity, $associationName) { |
||
186 | $entity = $this->typeManager->build(self::class, $targetEntity); |
||
187 | $shortName = $this->getTypeName() . '_' . $associationName; |
||
188 | |||
189 | return [ |
||
190 | 'type' => $this->typeManager->build( |
||
191 | Connection::class, |
||
192 | $shortName . '_Connection', |
||
193 | $entity->getGraphQLType(), |
||
194 | ), |
||
195 | 'args' => [ |
||
196 | 'filter' => $this->criteriaFactory->get( |
||
197 | $entity, |
||
198 | $this, |
||
199 | $associationName, |
||
200 | $this->metadata['fields'][$associationName], |
||
201 | ), |
||
202 | 'pagination' => $this->typeManager->get('pagination'), |
||
203 | ], |
||
204 | 'description' => $this->metadata['fields'][$associationName]['description'], |
||
205 | 'resolve' => $this->collectionFactory->get($entity), |
||
206 | ]; |
||
207 | }; |
||
208 | break; |
||
209 | } |
||
213 |