| Conditions | 7 |
| Paths | 6 |
| Total Lines | 61 |
| Code Lines | 33 |
| 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 |
||
| 20 | public function evaluate(): void |
||
| 21 | { |
||
| 22 | $directives = $this->context->getSchema()->getDirectives(); |
||
| 23 | |||
| 24 | foreach ($directives as $directive) { |
||
| 25 | if (!($directive instanceof DirectiveInterface)) { |
||
| 26 | $this->context->reportError( |
||
| 27 | new ValidationException( |
||
| 28 | \sprintf( |
||
| 29 | 'Expected directive but got: %s.', |
||
| 30 | $directive instanceof NodeAwareInterface ? $directive->getAstNode() : $directive |
||
|
|
|||
| 31 | ) |
||
| 32 | ) |
||
| 33 | ); |
||
| 34 | |||
| 35 | return; |
||
| 36 | } |
||
| 37 | |||
| 38 | // Ensure they are named correctly. |
||
| 39 | $this->validateName($this->context, $directive); |
||
| 40 | |||
| 41 | // TODO: Ensure proper locations. |
||
| 42 | |||
| 43 | // Ensure the arguments are valid. |
||
| 44 | $argumentNames = []; |
||
| 45 | |||
| 46 | foreach ($directive->getArguments() as $argument) { |
||
| 47 | $argumentName = $argument->getName(); |
||
| 48 | |||
| 49 | // Ensure they are named correctly. |
||
| 50 | $this->validateName($this->context, $argument); |
||
| 51 | |||
| 52 | // Ensure they are unique per directive. |
||
| 53 | if (isset($argumentNames[$argumentName])) { |
||
| 54 | $this->context->reportError( |
||
| 55 | new ValidationException( |
||
| 56 | \sprintf( |
||
| 57 | 'Argument @%s(%s:) can only be defined once.', |
||
| 58 | $directive->getName(), |
||
| 59 | $argumentName |
||
| 60 | ), |
||
| 61 | $this->getAllDirectiveArgumentNodes($directive, $argumentName) |
||
| 62 | ) |
||
| 63 | ); |
||
| 64 | |||
| 65 | continue; |
||
| 66 | } |
||
| 67 | |||
| 68 | $argumentNames[$argumentName] = true; |
||
| 69 | |||
| 70 | // Ensure the type is an input type. |
||
| 71 | if (!isInputType($argument->getType())) { |
||
| 72 | $this->context->reportError( |
||
| 73 | new ValidationException( |
||
| 74 | \sprintf( |
||
| 75 | 'The type of @%s(%s:) must be Input Type but got: %s.', |
||
| 76 | $directive->getName(), |
||
| 77 | $argumentName, |
||
| 78 | (string)$argument->getType() |
||
| 79 | ), |
||
| 80 | $this->getAllDirectiveArgumentNodes($directive, $argumentName) |
||
| 81 | ) |
||
| 111 |