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