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:
1 | <?php |
||
20 | class OverblogGraphQLExtension extends Extension implements PrependExtensionInterface |
||
21 | { |
||
22 | 36 | public function load(array $configs, ContainerBuilder $container) |
|
23 | { |
||
24 | 36 | $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
25 | 36 | $loader->load('services.yml'); |
|
26 | 36 | $loader->load('graphql_types.yml'); |
|
27 | 36 | $loader->load('graphql_fields.yml'); |
|
28 | 36 | $loader->load('graphql_args.yml'); |
|
29 | |||
30 | 36 | $configuration = $this->getConfiguration($configs, $container); |
|
31 | 36 | $config = $this->processConfiguration($configuration, $configs); |
|
32 | |||
33 | 36 | $this->setServicesAliases($config, $container); |
|
34 | 36 | $this->setSchemaBuilderArguments($config, $container); |
|
35 | 36 | $this->setSchemaArguments($config, $container); |
|
36 | 36 | $this->setErrorHandlerArguments($config, $container); |
|
37 | 36 | $this->setGraphiQLTemplate($config, $container); |
|
38 | 36 | $this->setSecurity($config, $container); |
|
39 | 36 | } |
|
40 | |||
41 | 36 | public function prepend(ContainerBuilder $container) |
|
42 | { |
||
43 | 36 | $configs = $container->getExtensionConfig($this->getAlias()); |
|
44 | 36 | $configs = $container->getParameterBag()->resolveValue($configs); |
|
45 | 36 | $configuration = $this->getConfiguration($configs, $container); |
|
46 | 36 | $config = $this->processConfiguration($configuration, $configs); |
|
47 | |||
48 | /** @var OverblogGraphQLTypesExtension $typesExtension */ |
||
49 | 36 | $typesExtension = $container->getExtension($this->getAlias().'_types'); |
|
50 | 36 | $typesExtension->containerPrependExtensionConfig($config, $container); |
|
51 | 36 | } |
|
52 | |||
53 | 36 | View Code Duplication | private function setSecurity(array $config, ContainerBuilder $container) |
|
|||
54 | { |
||
55 | 36 | if (isset($config['security']['query_max_depth'])) { |
|
56 | $container |
||
57 | 36 | ->getDefinition($this->getAlias().'.request_validator_rule_max_query_depth') |
|
58 | 36 | ->addMethodCall('setMaxQueryDepth', [$config['security']['query_max_depth']]) |
|
59 | 36 | ->setPublic(true) |
|
60 | ; |
||
61 | 36 | } |
|
62 | 36 | } |
|
63 | |||
64 | 36 | private function setGraphiQLTemplate(array $config, ContainerBuilder $container) |
|
65 | { |
||
66 | 36 | if (isset($config['templates']['graphiql'])) { |
|
67 | 36 | $container->setParameter('overblog_graphql.graphiql_template', $config['templates']['graphiql']); |
|
68 | 36 | } |
|
69 | 36 | } |
|
70 | |||
71 | 36 | View Code Duplication | private function setErrorHandlerArguments(array $config, ContainerBuilder $container) |
72 | { |
||
73 | 36 | if (isset($config['definitions']['internal_error_message'])) { |
|
74 | $container |
||
75 | ->getDefinition($this->getAlias().'.error_handler') |
||
76 | ->replaceArgument(0, $config['definitions']['internal_error_message']) |
||
77 | ->setPublic(true) |
||
78 | ; |
||
79 | } |
||
80 | 36 | } |
|
81 | |||
82 | 36 | private function setSchemaBuilderArguments(array $config, ContainerBuilder $container) |
|
87 | |||
88 | 36 | private function setSchemaArguments(array $config, ContainerBuilder $container) |
|
100 | |||
101 | 36 | private function setServicesAliases(array $config, ContainerBuilder $container) |
|
102 | { |
||
103 | 36 | if (isset($config['services'])) { |
|
104 | 36 | foreach ($config['services'] as $name => $id) { |
|
105 | 36 | $alias = sprintf('%s.%s', $this->getAlias(), $name); |
|
110 | |||
111 | 36 | public function getAlias() |
|
115 | |||
116 | 36 | public function getConfiguration(array $config, ContainerBuilder $container) |
|
120 | } |
||
121 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.