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