We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 18 |
Paths | 72 |
Total Lines | 67 |
Code Lines | 48 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
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 |
||
102 | protected function collectFieldASTsAndDefs(ValidationContext $context, $parentType, SelectionSet $selectionSet, \ArrayObject $visitedFragmentNames = null, \ArrayObject $astAndDefs = null) |
||
103 | { |
||
104 | $_visitedFragmentNames = $visitedFragmentNames ?: new \ArrayObject(); |
||
105 | $_astAndDefs = $astAndDefs ?: new \ArrayObject(); |
||
106 | |||
107 | foreach ($selectionSet->selections as $selection) { |
||
108 | switch ($selection->kind) { |
||
|
|||
109 | case Node::FIELD: |
||
110 | $fieldName = $selection->name->value; |
||
111 | $fieldDef = null; |
||
112 | if ($parentType && method_exists($parentType, 'getFields')) { |
||
113 | $tmp = $parentType->getFields(); |
||
114 | $schemaMetaFieldDef = Introspection::schemaMetaFieldDef(); |
||
115 | $typeMetaFieldDef = Introspection::typeMetaFieldDef(); |
||
116 | $typeNameMetaFieldDef = Introspection::typeNameMetaFieldDef(); |
||
117 | |||
118 | if ($fieldName === $schemaMetaFieldDef->name && $context->getSchema()->getQueryType() === $parentType) { |
||
119 | $fieldDef = $schemaMetaFieldDef; |
||
120 | } elseif ($fieldName === $typeMetaFieldDef->name && $context->getSchema()->getQueryType() === $parentType) { |
||
121 | $fieldDef = $typeMetaFieldDef; |
||
122 | } elseif ($fieldName === $typeNameMetaFieldDef->name) { |
||
123 | $fieldDef = $typeNameMetaFieldDef; |
||
124 | } elseif (isset($tmp[$fieldName])) { |
||
125 | $fieldDef = $tmp[$fieldName]; |
||
126 | } |
||
127 | } |
||
128 | $responseName = $this->getFieldName($selection); |
||
129 | if (!isset($_astAndDefs[$responseName])) { |
||
130 | $_astAndDefs[$responseName] = new \ArrayObject(); |
||
131 | } |
||
132 | // create field context |
||
133 | $_astAndDefs[$responseName][] = [$selection, $fieldDef]; |
||
134 | break; |
||
135 | case Node::INLINE_FRAGMENT: |
||
136 | /* @var InlineFragment $inlineFragment */ |
||
137 | $_astAndDefs = $this->collectFieldASTsAndDefs( |
||
138 | $context, |
||
139 | TypeInfo::typeFromAST($context->getSchema(), $selection->typeCondition), |
||
140 | $selection->selectionSet, |
||
141 | $_visitedFragmentNames, |
||
142 | $_astAndDefs |
||
143 | ); |
||
144 | break; |
||
145 | case Node::FRAGMENT_SPREAD: |
||
146 | /* @var FragmentSpread $selection */ |
||
147 | $fragName = $selection->name->value; |
||
148 | |||
149 | if (empty($_visitedFragmentNames[$fragName])) { |
||
150 | $_visitedFragmentNames[$fragName] = true; |
||
151 | $fragment = $context->getFragment($fragName); |
||
152 | |||
153 | if ($fragment) { |
||
154 | $_astAndDefs = $this->collectFieldASTsAndDefs( |
||
155 | $context, |
||
156 | TypeInfo::typeFromAST($context->getSchema(), $fragment->typeCondition), |
||
157 | $fragment->selectionSet, |
||
158 | $_visitedFragmentNames, |
||
159 | $_astAndDefs |
||
160 | ); |
||
161 | } |
||
162 | } |
||
163 | break; |
||
164 | } |
||
165 | } |
||
166 | |||
167 | return $_astAndDefs; |
||
168 | } |
||
169 | |||
180 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: