Conditions | 10 |
Paths | 3 |
Total Lines | 37 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
34 | protected function hydrateAssociations($entity, $data) |
||
35 | { |
||
36 | if (isset($data['relationships']) && is_array($data['relationships'])) { |
||
37 | $metadata = $this->entityManager->getClassMetadata(get_class($entity)); |
||
38 | |||
39 | foreach ($data['relationships'] as $name => $data) { |
||
40 | if (!isset($metadata->associationMappings[$name])) { |
||
41 | throw new \Exception(sprintf('Relation `%s` association not found', $name)); |
||
42 | } |
||
43 | |||
44 | if (is_array($data['data'])) { |
||
45 | if (isset($data['data']['id']) && isset($data['data']['type'])) { |
||
46 | $this->hydrateToOneAssociation($entity, $name, |
||
47 | $metadata->associationMappings[$name], |
||
48 | $data['data']['id'] |
||
49 | ); |
||
50 | } else { |
||
51 | $this->hydrateToManyAssociation($entity, $name, |
||
52 | $metadata->associationMappings[$name], |
||
53 | array_map( |
||
54 | function ($relation) { |
||
55 | if (isset($relation['id']) && isset($relation['type'])) { |
||
56 | return $relation['id']; |
||
57 | } |
||
58 | |||
59 | return ['attributes' => $relation]; |
||
60 | }, |
||
61 | $data['data'] |
||
62 | ) |
||
63 | ); |
||
64 | } |
||
65 | } |
||
66 | } |
||
67 | } |
||
68 | |||
69 | return $entity; |
||
70 | } |
||
71 | } |
||
72 |