Conditions | 10 |
Paths | 24 |
Total Lines | 61 |
Code Lines | 40 |
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 |
||
39 | public function getDescription(string $resourceClass): array |
||
40 | { |
||
41 | $description = []; |
||
42 | |||
43 | $properties = $this->getProperties(); |
||
44 | if (null === $properties) { |
||
45 | $properties = array_fill_keys($this->getClassMetadata($resourceClass)->getFieldNames(), null); |
||
46 | } |
||
47 | |||
48 | foreach ($properties as $property => $strategy) { |
||
49 | if (!$this->isPropertyMapped($property, $resourceClass, true)) { |
||
50 | continue; |
||
51 | } |
||
52 | |||
53 | if ($this->isPropertyNested($property, $resourceClass)) { |
||
54 | $propertyParts = $this->splitPropertyParts($property, $resourceClass); |
||
55 | $field = $propertyParts['field']; |
||
56 | $metadata = $this->getNestedMetadata($resourceClass, $propertyParts['associations']); |
||
57 | } else { |
||
58 | $field = $property; |
||
59 | $metadata = $this->getClassMetadata($resourceClass); |
||
60 | } |
||
61 | |||
62 | $propertyName = $this->normalizePropertyName($property); |
||
63 | if ($metadata->hasField($field)) { |
||
64 | $typeOfField = $this->getType($metadata->getTypeOfField($field)); |
||
65 | $strategy = $this->getProperties()[$property] ?? self::STRATEGY_EXACT; |
||
|
|||
66 | $filterParameterNames = [$propertyName]; |
||
67 | |||
68 | if (self::STRATEGY_EXACT === $strategy) { |
||
69 | $filterParameterNames[] = $propertyName.'[]'; |
||
70 | } |
||
71 | |||
72 | foreach ($filterParameterNames as $filterParameterName) { |
||
73 | $description[$filterParameterName] = [ |
||
74 | 'property' => $propertyName, |
||
75 | 'type' => $typeOfField, |
||
76 | 'required' => false, |
||
77 | 'strategy' => $strategy, |
||
78 | 'is_collection' => '[]' === substr((string) $filterParameterName, -2), |
||
79 | ]; |
||
80 | } |
||
81 | } elseif ($metadata->hasAssociation($field)) { |
||
82 | $filterParameterNames = [ |
||
83 | $propertyName, |
||
84 | $propertyName.'[]', |
||
85 | ]; |
||
86 | |||
87 | foreach ($filterParameterNames as $filterParameterName) { |
||
88 | $description[$filterParameterName] = [ |
||
89 | 'property' => $propertyName, |
||
90 | 'type' => 'string', |
||
91 | 'required' => false, |
||
92 | 'strategy' => self::STRATEGY_EXACT, |
||
93 | 'is_collection' => '[]' === substr((string) $filterParameterName, -2), |
||
94 | ]; |
||
95 | } |
||
96 | } |
||
97 | } |
||
98 | |||
99 | return $description; |
||
100 | } |
||
171 |