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