Conditions | 10 |
Paths | 41 |
Total Lines | 23 |
Code Lines | 13 |
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 |
||
57 | protected function getMessagesAndViolations(ConstraintViolationListInterface $constraintViolationList): array |
||
58 | { |
||
59 | $violations = $messages = []; |
||
60 | |||
61 | foreach ($constraintViolationList as $violation) { |
||
62 | $class = \is_object($root = $violation->getRoot()) ? \get_class($root) : null; |
||
63 | $violationData = [ |
||
64 | 'propertyPath' => $this->nameConverter ? $this->nameConverter->normalize($violation->getPropertyPath(), $class, static::FORMAT) : $violation->getPropertyPath(), |
||
|
|||
65 | 'message' => $violation->getMessage(), |
||
66 | ]; |
||
67 | |||
68 | $constraint = $violation->getConstraint(); |
||
69 | if ($this->serializePayloadFields && $constraint && $constraint->payload) { |
||
70 | // If some fields are whitelisted, only them are added |
||
71 | $payloadFields = null === $this->serializePayloadFields ? $constraint->payload : array_intersect_key($constraint->payload, array_flip($this->serializePayloadFields)); |
||
72 | $payloadFields && $violationData['payload'] = $payloadFields; |
||
73 | } |
||
74 | |||
75 | $violations[] = $violationData; |
||
76 | $messages[] = ($violationData['propertyPath'] ? "{$violationData['propertyPath']}: " : '').$violationData['message']; |
||
77 | } |
||
78 | |||
79 | return [$messages, $violations]; |
||
80 | } |
||
82 |
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.