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 | NodeKind::SCALAR_TYPE_DEFINITION => 'custom-scalar', |
||
| 28 | ]; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * {@inheritdoc} |
||
| 32 | */ |
||
| 33 | public static function parse(\SplFileInfo $file, ContainerBuilder $container) |
||
| 60 | |||
| 61 | public static function mustOverrideConfig() |
||
| 65 | |||
| 66 | protected function typeDefinitionToConfig(Node $typeDef) |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @param Node $typeDef |
||
| 113 | * @param array $config |
||
| 114 | */ |
||
| 115 | private function addTypeFields(Node $typeDef, array &$config) |
||
| 131 | |||
| 132 | /** |
||
| 133 | * @param Node $fieldDef |
||
| 134 | * @param array $fieldConf |
||
| 135 | */ |
||
| 136 | private function addFieldArguments(Node $fieldDef, array &$fieldConf) |
||
| 151 | |||
| 152 | /** |
||
| 153 | * @param Node $typeDef |
||
| 154 | * @param array $config |
||
| 155 | */ |
||
| 156 | View Code Duplication | private function addInterfaces(Node $typeDef, array &$config) |
|
| 166 | |||
| 167 | /** |
||
| 168 | * @param Node $typeDef |
||
| 169 | * @param array $config |
||
| 170 | */ |
||
| 171 | View Code Duplication | private function addTypes(Node $typeDef, array &$config) |
|
| 181 | |||
| 182 | /** |
||
| 183 | * @param Node $typeDef |
||
| 184 | * @param array $config |
||
| 185 | */ |
||
| 186 | private function addValues(Node $typeDef, array &$config) |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @param Node $definition |
||
| 200 | * @param array $config |
||
| 201 | */ |
||
| 202 | private function addType(Node $definition, array &$config) |
||
| 208 | |||
| 209 | /** |
||
| 210 | * @param Node $definition |
||
| 211 | * @param array $config |
||
| 212 | */ |
||
| 213 | private function addDescription(Node $definition, array &$config) |
||
| 222 | |||
| 223 | /** |
||
| 224 | * @param InputValueDefinitionNode|FieldDefinitionNode $definition |
||
| 225 | * @param array $config |
||
| 226 | */ |
||
| 227 | private function addDefaultValue($definition, array &$config) |
||
| 233 | |||
| 234 | private function astTypeNodeToString(TypeNode $typeNode) |
||
| 253 | |||
| 254 | private function astValueNodeToConfig(ValueNode $valueNode) |
||
| 280 | |||
| 281 | private function cleanAstDescription($description) |
||
| 287 | } |
||
| 288 |
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: