Conditions | 8 |
Paths | 7 |
Total Lines | 54 |
Code Lines | 35 |
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 |
||
18 | public function enterNode(NodeInterface $node): ?NodeInterface |
||
19 | { |
||
20 | if ($node instanceof ArgumentNode) { |
||
21 | $argumentDefinition = $this->context->getArgument(); |
||
22 | |||
23 | if (null === $argumentDefinition) { |
||
24 | $argumentOf = $node->getClosestAncestor(); |
||
25 | if ($argumentOf instanceof FieldNode) { |
||
26 | $fieldDefinition = $this->context->getFieldDefinition(); |
||
27 | $parentType = $this->context->getParentType(); |
||
28 | |||
29 | if (null !== $fieldDefinition && null !== $parentType) { |
||
30 | $this->context->reportError( |
||
31 | new ValidationException( |
||
32 | unknownArgumentMessage( |
||
33 | (string)$node, |
||
34 | (string)$fieldDefinition, |
||
35 | (string)$parentType, |
||
36 | suggestionList( |
||
37 | $node->getNameValue(), |
||
38 | array_map(function (Argument $argument) { |
||
39 | return $argument->getName(); |
||
40 | }, $fieldDefinition->getArguments()) |
||
41 | ) |
||
42 | ), |
||
43 | [$node] |
||
44 | ) |
||
45 | ); |
||
46 | } |
||
47 | } elseif ($argumentOf instanceof DirectiveNode) { |
||
48 | $directive = $this->context->getDirective(); |
||
49 | |||
50 | if (null !== $directive) { |
||
51 | $this->context->reportError( |
||
52 | new ValidationException( |
||
53 | unknownDirectiveArgumentMessage( |
||
54 | (string)$node, |
||
55 | (string)$directive, |
||
56 | suggestionList( |
||
57 | (string)$node, |
||
58 | array_map(function (Argument $argument) { |
||
59 | return $argument->getName(); |
||
60 | }, $directive->getArguments()) |
||
61 | ) |
||
62 | ), |
||
63 | [$node] |
||
64 | ) |
||
65 | ); |
||
66 | } |
||
67 | } |
||
68 | } |
||
69 | } |
||
70 | |||
71 | return $node; |
||
72 | } |
||
74 |