Conditions | 13 |
Paths | 5 |
Total Lines | 50 |
Code Lines | 30 |
Lines | 10 |
Ratio | 20 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
109 | protected function walkQuery(AbstractAst $node, FieldInterface $current, VisitorInterface $visitor) { |
||
110 | $carry = $visitor->initial(); |
||
111 | |||
112 | if (!($node instanceof Field)) { |
||
113 | /** @var \Youshido\GraphQL\Parser\Ast\Field $field */ |
||
114 | foreach ($node->getFields() as $field) { |
||
115 | if ($field instanceof FragmentInterface) { |
||
116 | if ($field instanceof FragmentReference) { |
||
117 | $field = $this->request->getFragment($field->getName()); |
||
118 | } |
||
119 | |||
120 | $walker = $this->walkQuery($field, $current, $visitor); |
||
121 | $next = $walker->current(); |
||
122 | |||
123 | View Code Duplication | while ($walker->valid()) { |
|
124 | $received = (yield $next); |
||
125 | $carry = $visitor->reduce($carry, $received, $this->context); |
||
126 | $next = $walker->send($received); |
||
127 | } |
||
128 | } |
||
129 | else { |
||
130 | $type = $this->getType($node, $current); |
||
131 | $name = $field->getName(); |
||
132 | |||
133 | if ($name !== Processor::TYPE_NAME_QUERY && ($type instanceof AbstractObjectType || $type instanceof AbstractInterfaceType)) { |
||
134 | if (!$type->hasField($name)) { |
||
135 | $type = $type->getNamedType()->getName(); |
||
136 | $location = $field->getLocation(); |
||
137 | |||
138 | throw new ResolveException(sprintf('Unknown field %s for type %s.', $name, $type), $location); |
||
139 | } |
||
140 | |||
141 | $ast = $type->getField($name); |
||
142 | $walker = $this->walkQuery($field, $ast, $visitor); |
||
143 | $next = $walker->current(); |
||
144 | |||
145 | View Code Duplication | while ($walker->valid()) { |
|
146 | $received = (yield $next); |
||
147 | $carry = $visitor->reduce($carry, $received, $this->context); |
||
148 | $next = $walker->send($received); |
||
149 | } |
||
150 | } |
||
151 | } |
||
152 | } |
||
153 | } |
||
154 | |||
155 | if ($node instanceof Query || $node instanceof Field) { |
||
156 | yield [$node, $current, $carry]; |
||
157 | } |
||
158 | } |
||
159 | |||
178 | } |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.