| 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 |
||
| 26 | protected function enterArgument(ArgumentNode $node): ?NodeInterface |
||
| 27 | { |
||
| 28 | $argumentDefinition = $this->context->getArgument(); |
||
| 29 | |||
| 30 | if (null === $argumentDefinition) { |
||
| 31 | $argumentOf = $node->getAncestor(); |
||
| 32 | |||
| 33 | if ($argumentOf instanceof FieldNode) { |
||
| 34 | return $this->validateField($node); |
||
| 35 | } |
||
| 36 | |||
| 37 | if ($argumentOf instanceof DirectiveNode) { |
||
| 38 | return $this->validateDirective($node); |
||
| 39 | } |
||
| 40 | } |
||
| 41 | |||
| 42 | return $node; |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @param NodeInterface $node |
||
| 47 | * @return NodeInterface|null |
||
| 48 | */ |
||
| 49 | protected function validateField(NodeInterface $node): ?NodeInterface |
||
| 50 | { |
||
| 51 | $fieldDefinition = $this->context->getFieldDefinition(); |
||
| 52 | $parentType = $this->context->getParentType(); |
||
| 53 | |||
| 54 | if (null !== $fieldDefinition && null !== $parentType) { |
||
| 55 | $options = array_map(function (Argument $argument) { |
||
| 56 | return $argument->getName(); |
||
| 57 | }, $fieldDefinition->getArguments()); |
||
| 58 | |||
| 59 | /** @noinspection PhpUndefinedMethodInspection */ |
||
| 60 | $suggestions = suggestionList($node->getNameValue(), $options); |
||
|
|
|||
| 61 | |||
| 62 | $this->context->reportError( |
||
| 63 | new ValidationException( |
||
| 64 | unknownArgumentMessage((string)$node, (string)$fieldDefinition, (string)$parentType, $suggestions), |
||
| 65 | [$node] |
||
| 66 | ) |
||
| 67 | ); |
||
| 68 | } |
||
| 69 | |||
| 70 | return $node; |
||
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @param NodeInterface $node |
||
| 75 | * @return NodeInterface|null |
||
| 76 | */ |
||
| 77 | protected function validateDirective(NodeInterface $node): ?NodeInterface |
||
| 78 | { |
||
| 79 | $directive = $this->context->getDirective(); |
||
| 80 | |||
| 99 |