Conditions | 11 |
Paths | 7 |
Total Lines | 66 |
Code Lines | 37 |
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 |
||
26 | * @inheritdoc |
||
27 | */ |
||
28 | protected function leaveField(FieldNode $node): ?NodeInterface |
||
29 | { |
||
30 | $fieldDefinition = $this->context->getFieldDefinition(); |
||
31 | |||
32 | if (null === $fieldDefinition) { |
||
33 | return null; |
||
34 | } |
||
35 | |||
36 | $argumentNodes = $node->getArguments(); |
||
37 | $argumentNodeMap = keyMap($argumentNodes, function (ArgumentNode $argument) { |
||
38 | return $argument->getNameValue(); |
||
39 | }); |
||
40 | |||
41 | foreach ($fieldDefinition->getArguments() as $argumentDefinition) { |
||
42 | $argumentNode = $argumentNodeMap[$argumentDefinition->getName()] ?? null; |
||
43 | $argumentType = $argumentDefinition->getType(); |
||
44 | |||
45 | if (null === $argumentNode && $argumentType instanceof NonNullType) { |
||
46 | $this->context->reportError( |
||
47 | new ValidationException( |
||
48 | missingFieldArgumentMessage( |
||
49 | (string)$node, |
||
50 | (string)$argumentDefinition, |
||
51 | (string)$argumentType |
||
52 | ), |
||
53 | [$node] |
||
54 | ) |
||
55 | ); |
||
56 | } |
||
57 | } |
||
58 | |||
59 | return $node; |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @inheritdoc |
||
64 | */ |
||
65 | protected function leaveDirective(DirectiveNode $node): ?NodeInterface |
||
66 | { |
||
67 | $directiveDefinition = $this->context->getDirective(); |
||
68 | |||
69 | if (null === $directiveDefinition) { |
||
70 | return null; |
||
71 | } |
||
72 | |||
73 | $argumentNodes = $node->getArguments(); |
||
74 | $argumentNodeMap = keyMap($argumentNodes, function (ArgumentNode $argument) { |
||
75 | return $argument->getNameValue(); |
||
76 | }); |
||
77 | |||
78 | foreach ($directiveDefinition->getArguments() as $argumentDefinition) { |
||
79 | $argumentNode = $argumentNodeMap[$argumentDefinition->getName()] ?? null; |
||
80 | $argumentType = $argumentDefinition->getType(); |
||
81 | |||
82 | if (null === $argumentNode && $argumentType instanceof NonNullType) { |
||
83 | $this->context->reportError( |
||
84 | new ValidationException( |
||
85 | missingDirectiveArgumentMessage( |
||
86 | (string)$node, |
||
87 | (string)$argumentDefinition, |
||
88 | (string)$argumentType |
||
89 | ), |
||
90 | [$node] |
||
91 | ) |
||
92 | ); |
||
99 |