We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Complex classes like OverblogGraphQLExtension 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 OverblogGraphQLExtension, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
20 | class OverblogGraphQLExtension extends Extension implements PrependExtensionInterface |
||
21 | { |
||
22 | 25 | public function load(array $configs, ContainerBuilder $container) |
|
23 | { |
||
24 | 25 | $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
25 | 25 | $loader->load('services.yml'); |
|
26 | 25 | $loader->load('graphql_types.yml'); |
|
27 | |||
28 | 25 | $config = $this->treatConfigs($configs, $container); |
|
29 | |||
30 | 25 | $this->setBatchingMethod($config, $container); |
|
|
|||
31 | 25 | $this->setExpressionLanguageDefaultParser($container); |
|
32 | 25 | $this->setServicesAliases($config, $container); |
|
33 | 25 | $this->setSchemaBuilderArguments($config, $container); |
|
34 | 25 | $this->setSchemaArguments($config, $container); |
|
35 | 25 | $this->setErrorHandlerArguments($config, $container); |
|
36 | 25 | $this->setGraphiQLTemplate($config, $container); |
|
37 | 25 | $this->setSecurity($config, $container); |
|
38 | 25 | $this->setConfigBuilders($config, $container); |
|
39 | 25 | $this->setVersions($config, $container); |
|
40 | 25 | $this->setShowDebug($config, $container); |
|
41 | 25 | $this->setDefinitionParameters($config, $container); |
|
42 | 25 | $this->setClassLoaderListener($config, $container); |
|
43 | 25 | $this->setCompilerCacheWarmer($config, $container); |
|
44 | |||
45 | 25 | $container->setParameter($this->getAlias().'.resources_dir', realpath(__DIR__.'/../Resources')); |
|
46 | 25 | } |
|
47 | |||
48 | 23 | public function prepend(ContainerBuilder $container) |
|
58 | |||
59 | 25 | public function getAlias() |
|
63 | |||
64 | 25 | public function getConfiguration(array $config, ContainerBuilder $container) |
|
71 | |||
72 | 25 | private function setCompilerCacheWarmer(array $config, ContainerBuilder $container) |
|
83 | |||
84 | 25 | private function setClassLoaderListener(array $config, ContainerBuilder $container) |
|
97 | |||
98 | 25 | private function setDefinitionParameters(array $config, ContainerBuilder $container) |
|
108 | |||
109 | 25 | private function setBatchingMethod(array $config, ContainerBuilder $container) |
|
113 | |||
114 | 25 | private function setExpressionLanguageDefaultParser(ContainerBuilder $container) |
|
121 | |||
122 | 25 | private function setShowDebug(array $config, ContainerBuilder $container) |
|
126 | |||
127 | 25 | private function setVersions(array $config, ContainerBuilder $container) |
|
133 | |||
134 | 25 | private function setConfigBuilders(array $config, ContainerBuilder $container) |
|
151 | |||
152 | 25 | private function treatConfigs(array $configs, ContainerBuilder $container, $forceReload = false) |
|
163 | |||
164 | 25 | private function setSecurity(array $config, ContainerBuilder $container) |
|
170 | |||
171 | 25 | private function setGraphiQLTemplate(array $config, ContainerBuilder $container) |
|
175 | |||
176 | 25 | private function setErrorHandlerArguments(array $config, ContainerBuilder $container) |
|
177 | { |
||
178 | 25 | $errorHandlerDefinition = $container->getDefinition($this->getAlias().'.error_handler'); |
|
179 | |||
180 | 25 | if (isset($config['definitions']['internal_error_message'])) { |
|
181 | 2 | $errorHandlerDefinition->replaceArgument(0, $config['definitions']['internal_error_message']); |
|
182 | } |
||
183 | |||
184 | 25 | if (isset($config['definitions']['exceptions'])) { |
|
185 | $errorHandlerDefinition |
||
186 | 25 | ->replaceArgument(2, $this->buildExceptionMap($config['definitions']['exceptions'])) |
|
187 | 25 | ->addMethodCall('setUserWarningClass', [$config['definitions']['exceptions']['types']['warnings']]) |
|
188 | 25 | ->addMethodCall('setUserErrorClass', [$config['definitions']['exceptions']['types']['errors']]) |
|
189 | ; |
||
190 | } |
||
191 | 25 | } |
|
192 | |||
193 | 25 | private function setSchemaBuilderArguments(array $config, ContainerBuilder $container) |
|
198 | |||
199 | 25 | private function setSchemaArguments(array $config, ContainerBuilder $container) |
|
216 | |||
217 | 25 | private function setServicesAliases(array $config, ContainerBuilder $container) |
|
226 | |||
227 | /** |
||
228 | * Returns a list of custom exceptions mapped to error/warning classes. |
||
229 | * |
||
230 | * @param array $exceptionConfig |
||
231 | * |
||
232 | * @return array Custom exception map, [exception => UserError/UserWarning] |
||
233 | */ |
||
234 | 25 | private function buildExceptionMap(array $exceptionConfig) |
|
251 | } |
||
252 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.