Conditions | 10 |
Paths | 14 |
Total Lines | 23 |
Code Lines | 15 |
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 |
||
41 | public function validate($data, array $context = []) |
||
42 | { |
||
43 | if (null !== $validationGroups = $context['groups'] ?? null) { |
||
44 | if ( |
||
45 | $this->container && |
||
46 | \is_string($validationGroups) && |
||
47 | $this->container->has($validationGroups) && |
||
48 | ($service = $this->container->get($validationGroups)) && |
||
49 | \is_callable($service) |
||
50 | ) { |
||
51 | $validationGroups = $service($data); |
||
52 | } elseif (\is_callable($validationGroups)) { |
||
53 | $validationGroups = $validationGroups($data); |
||
54 | } |
||
55 | |||
56 | if (!$validationGroups instanceof GroupSequence) { |
||
57 | $validationGroups = (array) $validationGroups; |
||
58 | } |
||
59 | } |
||
60 | |||
61 | $violations = $this->validator->validate($data, null, $validationGroups); |
||
62 | if (0 !== \count($violations)) { |
||
63 | throw new ValidationException($violations); |
||
64 | } |
||
67 |