Conditions | 11 |
Paths | 33 |
Total Lines | 39 |
Code Lines | 20 |
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 |
||
48 | public function apply(array $clauseBody, string $resourceClass, ?string $operationName = null, array $context = []): array |
||
49 | { |
||
50 | if (!\is_array($properties = $context['filters'][$this->orderParameterName] ?? [])) { |
||
51 | return $clauseBody; |
||
52 | } |
||
53 | |||
54 | $orders = []; |
||
55 | |||
56 | foreach ($properties as $property => $direction) { |
||
57 | [$type] = $this->getMetadata($resourceClass, $property); |
||
58 | |||
59 | if (!$type) { |
||
60 | continue; |
||
61 | } |
||
62 | |||
63 | if (empty($direction) && null !== $defaultDirection = $this->properties[$property] ?? null) { |
||
64 | $direction = $defaultDirection; |
||
65 | } |
||
66 | |||
67 | if (!\in_array($direction = strtolower($direction), ['asc', 'desc'], true)) { |
||
68 | continue; |
||
69 | } |
||
70 | |||
71 | $order = ['order' => $direction]; |
||
72 | |||
73 | if (null !== $nestedPath = $this->getNestedFieldPath($resourceClass, $property)) { |
||
74 | $nestedPath = null === $this->nameConverter ? $nestedPath : $this->nameConverter->normalize($nestedPath); |
||
75 | $order['nested'] = ['path' => $nestedPath]; |
||
76 | } |
||
77 | |||
78 | $property = null === $this->nameConverter ? $property : $this->nameConverter->normalize($property); |
||
79 | $orders[] = [$property => $order]; |
||
80 | } |
||
81 | |||
82 | if (!$orders) { |
||
83 | return $clauseBody; |
||
84 | } |
||
85 | |||
86 | return array_merge_recursive($clauseBody, $orders); |
||
87 | } |
||
113 |