| Conditions | 9 |
| Paths | 9 |
| Total Lines | 53 |
| Code Lines | 23 |
| 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 |
||
| 55 | public function collectFields( |
||
| 56 | ObjectType $runtimeType, |
||
| 57 | SelectionSetNode $selectionSet, |
||
| 58 | array &$fields, |
||
| 59 | array &$visitedFragmentNames |
||
| 60 | ): array { |
||
| 61 | foreach ($selectionSet->getSelections() as $selection) { |
||
| 62 | // Check if this Node should be included first |
||
| 63 | if (!$this->shouldIncludeNode($selection)) { |
||
| 64 | continue; |
||
| 65 | } |
||
| 66 | |||
| 67 | // Collect fields |
||
| 68 | if ($selection instanceof FieldNode) { |
||
| 69 | $fieldName = $selection->getAliasOrNameValue(); |
||
| 70 | |||
| 71 | if (!isset($fields[$fieldName])) { |
||
| 72 | $fields[$fieldName] = []; |
||
| 73 | } |
||
| 74 | |||
| 75 | $fields[$fieldName][] = $selection; |
||
| 76 | |||
| 77 | continue; |
||
| 78 | } |
||
| 79 | |||
| 80 | if ($selection instanceof InlineFragmentNode) { |
||
| 81 | if (!$this->doesFragmentConditionMatch($selection, $runtimeType)) { |
||
| 82 | continue; |
||
| 83 | } |
||
| 84 | |||
| 85 | $this->collectFields($runtimeType, $selection->getSelectionSet(), $fields, $visitedFragmentNames); |
||
|
|
|||
| 86 | |||
| 87 | continue; |
||
| 88 | } |
||
| 89 | |||
| 90 | if ($selection instanceof FragmentSpreadNode) { |
||
| 91 | $fragmentName = $selection->getNameValue(); |
||
| 92 | |||
| 93 | if (isset($visitedFragmentNames[$fragmentName])) { |
||
| 94 | continue; |
||
| 95 | } |
||
| 96 | |||
| 97 | $visitedFragmentNames[$fragmentName] = true; |
||
| 98 | |||
| 99 | $fragment = $this->context->getFragments()[$fragmentName]; |
||
| 100 | |||
| 101 | $this->collectFields($runtimeType, $fragment->getSelectionSet(), $fields, $visitedFragmentNames); |
||
| 102 | |||
| 103 | continue; |
||
| 104 | } |
||
| 105 | } |
||
| 106 | |||
| 107 | return $fields; |
||
| 108 | } |
||
| 164 |