Conditions | 12 |
Paths | 7 |
Total Lines | 39 |
Code Lines | 23 |
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 |
||
53 | private function getNestedFieldPath(string $resourceClass, string $property): ?string |
||
54 | { |
||
55 | $properties = explode('.', $property); |
||
56 | $currentProperty = array_shift($properties); |
||
57 | |||
58 | if (!$properties) { |
||
59 | return null; |
||
60 | } |
||
61 | |||
62 | try { |
||
63 | $propertyMetadata = $this->propertyMetadataFactory->create($resourceClass, $currentProperty); |
||
64 | } catch (PropertyNotFoundException $e) { |
||
65 | return null; |
||
66 | } |
||
67 | |||
68 | if (null === $type = $propertyMetadata->getType()) { |
||
69 | return null; |
||
70 | } |
||
71 | |||
72 | if ( |
||
73 | Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType() |
||
74 | && null !== ($nextResourceClass = $type->getClassName()) |
||
75 | && $this->resourceClassResolver->isResourceClass($nextResourceClass) |
||
76 | ) { |
||
77 | $nestedPath = $this->getNestedFieldPath($nextResourceClass, implode('.', $properties)); |
||
78 | |||
79 | return null === $nestedPath ? $nestedPath : "$currentProperty.$nestedPath"; |
||
80 | } |
||
81 | |||
82 | if ( |
||
83 | null !== ($type = $type->getCollectionValueType()) |
||
84 | && Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType() |
||
85 | && null !== ($className = $type->getClassName()) |
||
86 | && $this->resourceClassResolver->isResourceClass($className) |
||
87 | ) { |
||
88 | return $currentProperty; |
||
89 | } |
||
90 | |||
91 | return null; |
||
92 | } |
||
94 |