Conditions | 11 |
Paths | 33 |
Total Lines | 39 |
Code Lines | 20 |
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 |
||
47 | public function apply(array $clauseBody, string $resourceClass, ?string $operationName = null, array $context = []): array |
||
48 | { |
||
49 | if (!\is_array($properties = $context['filters'][$this->orderParameterName] ?? [])) { |
||
50 | return $clauseBody; |
||
51 | } |
||
52 | |||
53 | $orders = []; |
||
54 | |||
55 | foreach ($properties as $property => $direction) { |
||
56 | [$type] = $this->getMetadata($resourceClass, $property); |
||
57 | |||
58 | if (!$type) { |
||
59 | continue; |
||
60 | } |
||
61 | |||
62 | if (empty($direction) && null !== $defaultDirection = $this->properties[$property] ?? null) { |
||
63 | $direction = $defaultDirection; |
||
64 | } |
||
65 | |||
66 | if (!\in_array($direction = strtolower($direction), ['asc', 'desc'], true)) { |
||
67 | continue; |
||
68 | } |
||
69 | |||
70 | $order = ['order' => $direction]; |
||
71 | |||
72 | if (null !== $nestedPath = $this->getNestedFieldPath($resourceClass, $property)) { |
||
73 | $nestedPath = null === $this->nameConverter ? $nestedPath : $this->nameConverter->normalize($nestedPath, $resourceClass, null, $context); |
||
|
|||
74 | $order['nested'] = ['path' => $nestedPath]; |
||
75 | } |
||
76 | |||
77 | $property = null === $this->nameConverter ? $property : $this->nameConverter->normalize($property, $resourceClass, null, $context); |
||
78 | $orders[] = [$property => $order]; |
||
79 | } |
||
80 | |||
81 | if (!$orders) { |
||
82 | return $clauseBody; |
||
83 | } |
||
84 | |||
85 | return array_merge_recursive($clauseBody, $orders); |
||
86 | } |
||
112 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.