Conditions | 9 |
Paths | 9 |
Total Lines | 52 |
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 |
||
45 | public function collectFields( |
||
46 | ObjectType $runtimeType, |
||
47 | SelectionSetNode $selectionSet, |
||
48 | array &$fields, |
||
49 | array &$visitedFragmentNames |
||
50 | ): array { |
||
51 | foreach ($selectionSet->getSelections() as $selection) { |
||
52 | // Check if this Node should be included first |
||
53 | if (!$this->shouldIncludeNode($selection)) { |
||
54 | continue; |
||
55 | } |
||
56 | |||
57 | // Collect fields |
||
58 | if ($selection instanceof FieldNode) { |
||
59 | $fieldName = $selection->getAliasOrNameValue(); |
||
60 | |||
61 | if (!isset($fields[$fieldName])) { |
||
62 | $fields[$fieldName] = []; |
||
63 | } |
||
64 | |||
65 | $fields[$fieldName][] = $selection; |
||
66 | |||
67 | continue; |
||
68 | } |
||
69 | |||
70 | if ($selection instanceof InlineFragmentNode) { |
||
71 | if (!$this->doesFragmentConditionMatch($selection, $runtimeType)) { |
||
72 | continue; |
||
73 | } |
||
74 | |||
75 | $this->collectFields($runtimeType, $selection->getSelectionSet(), $fields, $visitedFragmentNames); |
||
76 | |||
77 | continue; |
||
78 | } |
||
79 | |||
80 | if ($selection instanceof FragmentSpreadNode) { |
||
81 | $fragmentName = $selection->getNameValue(); |
||
82 | |||
83 | if (!empty($visitedFragmentNames[$fragmentName])) { |
||
84 | continue; |
||
85 | } |
||
86 | |||
87 | $visitedFragmentNames[$fragmentName] = true; |
||
88 | /** @var FragmentDefinitionNode $fragment */ |
||
89 | $fragment = $this->context->getFragments()[$fragmentName]; |
||
90 | $this->collectFields($runtimeType, $fragment->getSelectionSet(), $fields, $visitedFragmentNames); |
||
91 | |||
92 | continue; |
||
93 | } |
||
94 | } |
||
95 | |||
96 | return $fields; |
||
97 | } |
||
152 |