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 |
||
| 16 | class GraphQLParser implements ParserInterface |
||
| 17 | { |
||
| 18 | /** @var self */ |
||
| 19 | private static $parser; |
||
| 20 | |||
| 21 | const DEFINITION_TYPE_MAPPING = [ |
||
| 22 | NodeKind::OBJECT_TYPE_DEFINITION => 'object', |
||
| 23 | NodeKind::INTERFACE_TYPE_DEFINITION => 'interface', |
||
| 24 | NodeKind::ENUM_TYPE_DEFINITION => 'enum', |
||
| 25 | NodeKind::UNION_TYPE_DEFINITION => 'union', |
||
| 26 | NodeKind::INPUT_OBJECT_TYPE_DEFINITION => 'input-object', |
||
| 27 | ]; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * {@inheritdoc} |
||
| 31 | */ |
||
| 32 | 6 | public static function parse(\SplFileInfo $file, ContainerBuilder $container) |
|
| 59 | |||
| 60 | 4 | protected function typeDefinitionToConfig(Node $typeDef) |
|
| 89 | |||
| 90 | /** |
||
| 91 | * @param Node $typeDef |
||
| 92 | * @param array $config |
||
| 93 | */ |
||
| 94 | 2 | private function addTypeFields(Node $typeDef, array &$config) |
|
| 110 | |||
| 111 | /** |
||
| 112 | * @param Node $fieldDef |
||
| 113 | * @param array $fieldConf |
||
| 114 | */ |
||
| 115 | 2 | private function addFieldArguments(Node $fieldDef, array &$fieldConf) |
|
| 130 | |||
| 131 | /** |
||
| 132 | * @param Node $typeDef |
||
| 133 | * @param array $config |
||
| 134 | */ |
||
| 135 | 2 | View Code Duplication | private function addInterfaces(Node $typeDef, array &$config) |
| 145 | |||
| 146 | /** |
||
| 147 | * @param Node $typeDef |
||
| 148 | * @param array $config |
||
| 149 | */ |
||
| 150 | 2 | View Code Duplication | private function addTypes(Node $typeDef, array &$config) |
| 160 | |||
| 161 | /** |
||
| 162 | * @param Node $typeDef |
||
| 163 | * @param array $config |
||
| 164 | */ |
||
| 165 | 2 | View Code Duplication | private function addValues(Node $typeDef, array &$config) |
| 175 | |||
| 176 | /** |
||
| 177 | * @param Node $definition |
||
| 178 | * @param array $config |
||
| 179 | */ |
||
| 180 | 2 | private function addType(Node $definition, array &$config) |
|
| 186 | |||
| 187 | /** |
||
| 188 | * @param Node $definition |
||
| 189 | * @param array $config |
||
| 190 | */ |
||
| 191 | 2 | private function addDescription(Node $definition, array &$config) |
|
| 200 | |||
| 201 | /** |
||
| 202 | * @param InputValueDefinitionNode|FieldDefinitionNode $definition |
||
| 203 | * @param array $config |
||
| 204 | */ |
||
| 205 | 2 | private function addDefaultValue($definition, array &$config) |
|
| 211 | |||
| 212 | 2 | private function astTypeNodeToString(TypeNode $typeNode) |
|
| 231 | |||
| 232 | 2 | private function astValueNodeToConfig(ValueNode $valueNode) |
|
| 258 | |||
| 259 | 2 | private function cleanAstDescription($description) |
|
| 265 | } |
||
| 266 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: