We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like GraphQLParser often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use GraphQLParser, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
18 | class GraphQLParser implements ParserInterface |
||
19 | { |
||
20 | /** @var self */ |
||
21 | private static $parser; |
||
22 | |||
23 | const DEFINITION_TYPE_MAPPING = [ |
||
24 | NodeKind::OBJECT_TYPE_DEFINITION => 'object', |
||
25 | NodeKind::INTERFACE_TYPE_DEFINITION => 'interface', |
||
26 | NodeKind::ENUM_TYPE_DEFINITION => 'enum', |
||
27 | NodeKind::UNION_TYPE_DEFINITION => 'union', |
||
28 | NodeKind::INPUT_OBJECT_TYPE_DEFINITION => 'input-object', |
||
29 | NodeKind::SCALAR_TYPE_DEFINITION => 'custom-scalar', |
||
30 | ]; |
||
31 | |||
32 | /** |
||
33 | * {@inheritdoc} |
||
34 | */ |
||
35 | 5 | public static function parse(\SplFileInfo $file, ContainerBuilder $container) |
|
65 | |||
66 | 1 | public static function mustOverrideConfig() |
|
70 | |||
71 | 2 | protected function typeDefinitionToConfig(DefinitionNode $typeDef) |
|
114 | |||
115 | 1 | private static function throwUnsupportedDefinitionNode(DefinitionNode $typeDef) |
|
125 | |||
126 | /** |
||
127 | * @param DefinitionNode $typeDef |
||
128 | * @param array $config |
||
129 | */ |
||
130 | 2 | private function addTypeFields(DefinitionNode $typeDef, array &$config) |
|
146 | |||
147 | /** |
||
148 | * @param Node $fieldDef |
||
149 | * @param array $fieldConf |
||
150 | */ |
||
151 | 2 | private function addFieldArguments(Node $fieldDef, array &$fieldConf) |
|
165 | |||
166 | /** |
||
167 | * @param DefinitionNode $typeDef |
||
168 | * @param array $config |
||
169 | */ |
||
170 | 2 | View Code Duplication | private function addInterfaces(DefinitionNode $typeDef, array &$config) |
180 | |||
181 | /** |
||
182 | * @param DefinitionNode $typeDef |
||
183 | * @param array $config |
||
184 | */ |
||
185 | 2 | View Code Duplication | private function addTypes(DefinitionNode $typeDef, array &$config) |
195 | |||
196 | /** |
||
197 | * @param DefinitionNode $typeDef |
||
198 | * @param array $config |
||
199 | */ |
||
200 | 2 | private function addValues(DefinitionNode $typeDef, array &$config) |
|
211 | |||
212 | /** |
||
213 | * @param Node $definition |
||
214 | * @param array $config |
||
215 | */ |
||
216 | 2 | private function addType(Node $definition, array &$config) |
|
222 | |||
223 | /** |
||
224 | * @param Node $definition |
||
225 | * @param array $config |
||
226 | */ |
||
227 | 2 | private function addDescription(Node $definition, array &$config) |
|
236 | |||
237 | /** |
||
238 | * @param Node $definition |
||
239 | * @param array $config |
||
240 | */ |
||
241 | 2 | private function addDefaultValue(Node $definition, array &$config) |
|
247 | |||
248 | 2 | private function astTypeNodeToString(TypeNode $typeNode) |
|
267 | |||
268 | 1 | private function astValueNodeToConfig(ValueNode $valueNode) |
|
294 | |||
295 | 1 | private function cleanAstDescription($description) |
|
304 | } |
||
305 |
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: