Conditions | 17 |
Paths | 11 |
Total Lines | 63 |
Code Lines | 36 |
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 |
||
81 | protected function getMetadata(string $resourceClass, string $property): array |
||
82 | { |
||
83 | $noop = [null, null, null, null]; |
||
84 | |||
85 | if (!$this->hasProperty($resourceClass, $property)) { |
||
86 | return $noop; |
||
87 | } |
||
88 | |||
89 | $properties = explode('.', $property); |
||
90 | $totalProperties = \count($properties); |
||
91 | $currentResourceClass = $resourceClass; |
||
92 | $hasAssociation = false; |
||
93 | $currentProperty = null; |
||
94 | $type = null; |
||
95 | |||
96 | foreach ($properties as $index => $currentProperty) { |
||
97 | try { |
||
98 | $propertyMetadata = $this->propertyMetadataFactory->create($currentResourceClass, $currentProperty); |
||
99 | } catch (PropertyNotFoundException $e) { |
||
100 | return $noop; |
||
101 | } |
||
102 | |||
103 | if (null === $type = $propertyMetadata->getType()) { |
||
104 | return $noop; |
||
105 | } |
||
106 | |||
107 | ++$index; |
||
108 | $builtinType = $type->getBuiltinType(); |
||
109 | |||
110 | if (Type::BUILTIN_TYPE_OBJECT !== $builtinType && Type::BUILTIN_TYPE_ARRAY !== $builtinType) { |
||
111 | if ($totalProperties === $index) { |
||
112 | break; |
||
113 | } |
||
114 | |||
115 | return $noop; |
||
116 | } |
||
117 | |||
118 | if ($type->isCollection() && null === $type = $type->getCollectionValueType()) { |
||
119 | return $noop; |
||
120 | } |
||
121 | |||
122 | if (Type::BUILTIN_TYPE_ARRAY === $builtinType && Type::BUILTIN_TYPE_OBJECT !== $type->getBuiltinType()) { |
||
123 | if ($totalProperties === $index) { |
||
124 | break; |
||
125 | } |
||
126 | |||
127 | return $noop; |
||
128 | } |
||
129 | |||
130 | if (null === $className = $type->getClassName()) { |
||
131 | return $noop; |
||
132 | } |
||
133 | |||
134 | if ($isResourceClass = $this->resourceClassResolver->isResourceClass($className)) { |
||
135 | $currentResourceClass = $className; |
||
136 | } elseif ($totalProperties !== $index) { |
||
137 | return $noop; |
||
138 | } |
||
139 | |||
140 | $hasAssociation = $totalProperties === $index && $isResourceClass; |
||
141 | } |
||
142 | |||
143 | return [$type, $hasAssociation, $currentResourceClass, $currentProperty]; |
||
144 | } |
||
146 |