| 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 |
||
| 68 | public function collectFields( |
||
| 69 | ObjectType $runtimeType, |
||
| 70 | SelectionSetNode $selectionSet, |
||
| 71 | array &$fields, |
||
| 72 | array &$visitedFragmentNames |
||
| 73 | ): array { |
||
| 74 | foreach ($selectionSet->getSelections() as $selection) { |
||
| 75 | // Check if this Node should be included first |
||
| 76 | if (!$this->shouldIncludeNode($selection)) { |
||
| 77 | continue; |
||
| 78 | } |
||
| 79 | |||
| 80 | // Collect fields |
||
| 81 | if ($selection instanceof FieldNode) { |
||
| 82 | $fieldName = $selection->getAliasOrNameValue(); |
||
| 83 | |||
| 84 | if (!isset($fields[$fieldName])) { |
||
| 85 | $fields[$fieldName] = []; |
||
| 86 | } |
||
| 87 | |||
| 88 | $fields[$fieldName][] = $selection; |
||
| 89 | |||
| 90 | continue; |
||
| 91 | } |
||
| 92 | |||
| 93 | if ($selection instanceof InlineFragmentNode) { |
||
| 94 | if (!$this->doesFragmentConditionMatch($selection, $runtimeType)) { |
||
| 95 | continue; |
||
| 96 | } |
||
| 97 | |||
| 98 | $this->collectFields($runtimeType, $selection->getSelectionSet(), $fields, $visitedFragmentNames); |
||
|
|
|||
| 99 | |||
| 100 | continue; |
||
| 101 | } |
||
| 102 | |||
| 103 | if ($selection instanceof FragmentSpreadNode) { |
||
| 104 | $fragmentName = $selection->getNameValue(); |
||
| 105 | |||
| 106 | if (isset($visitedFragmentNames[$fragmentName])) { |
||
| 107 | continue; |
||
| 108 | } |
||
| 109 | |||
| 110 | $visitedFragmentNames[$fragmentName] = true; |
||
| 111 | |||
| 112 | $fragment = $this->context->getFragments()[$fragmentName]; |
||
| 113 | |||
| 114 | $this->collectFields($runtimeType, $fragment->getSelectionSet(), $fields, $visitedFragmentNames); |
||
| 115 | |||
| 116 | continue; |
||
| 117 | } |
||
| 118 | } |
||
| 119 | |||
| 120 | return $fields; |
||
| 121 | } |
||
| 177 |