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 |
||
19 | class OverblogGraphQLExtension extends Extension implements PrependExtensionInterface |
||
20 | { |
||
21 | 50 | public function load(array $configs, ContainerBuilder $container) |
|
22 | { |
||
23 | 50 | $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
24 | 50 | $loader->load('services.yml'); |
|
25 | 50 | $loader->load('graphql_types.yml'); |
|
26 | |||
27 | 50 | $config = $this->treatConfigs($configs, $container); |
|
28 | |||
29 | 50 | $this->setBatchingMethod($config, $container); |
|
|
|||
30 | 50 | $this->setExpressionLanguageDefaultParser($container); |
|
31 | 50 | $this->setServicesAliases($config, $container); |
|
32 | 50 | $this->setSchemaBuilderArguments($config, $container); |
|
33 | 50 | $this->setSchemaArguments($config, $container); |
|
34 | 50 | $this->setErrorHandlerArguments($config, $container); |
|
35 | 50 | $this->setGraphiQLTemplate($config, $container); |
|
36 | 50 | $this->setSecurity($config, $container); |
|
37 | 50 | $this->setConfigBuilders($config, $container); |
|
38 | 50 | $this->setVersions($config, $container); |
|
39 | 50 | $this->setShowDebug($config, $container); |
|
40 | 50 | $this->setDefinitionParameters($config, $container); |
|
41 | 50 | $this->setClassLoaderListener($config, $container); |
|
42 | |||
43 | 50 | $container->setParameter($this->getAlias().'.resources_dir', realpath(__DIR__.'/../Resources')); |
|
44 | 50 | } |
|
45 | |||
46 | 48 | public function prepend(ContainerBuilder $container) |
|
56 | |||
57 | 50 | public function getAlias() |
|
58 | { |
||
59 | 50 | return 'overblog_graphql'; |
|
60 | } |
||
61 | |||
62 | 50 | public function getConfiguration(array $config, ContainerBuilder $container) |
|
63 | { |
||
64 | 50 | return new Configuration( |
|
65 | 50 | $container->getParameter('kernel.debug'), |
|
66 | 50 | $container->hasParameter('kernel.cache_dir') ? $container->getParameter('kernel.cache_dir') : null |
|
67 | ); |
||
68 | } |
||
69 | |||
70 | 50 | private function setClassLoaderListener(array $config, ContainerBuilder $container) |
|
71 | { |
||
72 | 50 | $container->setParameter($this->getAlias().'.use_classloader_listener', $config['definitions']['use_classloader_listener']); |
|
73 | 50 | if ($config['definitions']['use_classloader_listener']) { |
|
74 | 48 | $definition = $container->setDefinition( |
|
75 | 48 | $this->getAlias().'.event_listener.classloader_listener', |
|
76 | 48 | new Definition(ClassLoaderListener::class) |
|
77 | ); |
||
78 | 48 | $definition->setArguments([new Reference($this->getAlias().'.cache_compiler')]); |
|
79 | 48 | $definition->addTag('kernel.event_listener', ['event' => 'kernel.request', 'method' => 'load', 'priority' => 255]); |
|
80 | 48 | $definition->addTag('kernel.event_listener', ['event' => 'console.command', 'method' => 'load', 'priority' => 255]); |
|
81 | } |
||
82 | 50 | } |
|
83 | |||
84 | 50 | private function setDefinitionParameters(array $config, ContainerBuilder $container) |
|
94 | |||
95 | 50 | private function setBatchingMethod(array $config, ContainerBuilder $container) |
|
96 | { |
||
97 | 50 | $container->setParameter($this->getAlias().'.batching_method', $config['batching_method']); |
|
98 | 50 | } |
|
99 | |||
100 | 50 | private function setExpressionLanguageDefaultParser(ContainerBuilder $container) |
|
101 | { |
||
102 | 50 | $class = version_compare(Kernel::VERSION, '3.2.0', '>=') ? ArrayAdapter::class : ArrayParserCache::class; |
|
103 | 50 | $definition = new Definition($class); |
|
104 | 50 | $definition->setPublic(false); |
|
105 | 50 | $container->setDefinition($this->getAlias().'.cache_expression_language_parser.default', $definition); |
|
106 | 50 | } |
|
107 | |||
108 | 50 | private function setShowDebug(array $config, ContainerBuilder $container) |
|
109 | { |
||
110 | 50 | $container->getDefinition($this->getAlias().'.request_executor')->replaceArgument(4, $config['definitions']['show_debug_info']); |
|
111 | 50 | } |
|
112 | |||
113 | 50 | private function setVersions(array $config, ContainerBuilder $container) |
|
119 | |||
120 | 50 | private function setConfigBuilders(array $config, ContainerBuilder $container) |
|
121 | { |
||
122 | 50 | $useObjectToAddResource = method_exists($container, 'addObjectResource'); |
|
123 | 50 | $objectToAddResourceMethod = $useObjectToAddResource ? 'addObjectResource' : 'addClassResource'; |
|
124 | |||
125 | 50 | foreach (['args', 'field'] as $category) { |
|
126 | 50 | if (!empty($config['definitions']['builders'][$category])) { |
|
137 | |||
138 | 50 | private function treatConfigs(array $configs, ContainerBuilder $container, $forceReload = false) |
|
149 | |||
150 | 50 | private function setSecurity(array $config, ContainerBuilder $container) |
|
156 | |||
157 | 50 | private function setGraphiQLTemplate(array $config, ContainerBuilder $container) |
|
161 | |||
162 | 50 | private function setErrorHandlerArguments(array $config, ContainerBuilder $container) |
|
178 | |||
179 | 50 | private function setSchemaBuilderArguments(array $config, ContainerBuilder $container) |
|
184 | |||
185 | 50 | private function setSchemaArguments(array $config, ContainerBuilder $container) |
|
202 | |||
203 | 50 | private function setServicesAliases(array $config, ContainerBuilder $container) |
|
212 | |||
213 | /** |
||
214 | * Returns a list of custom exceptions mapped to error/warning classes. |
||
215 | * |
||
216 | * @param array $exceptionConfig |
||
217 | * |
||
218 | * @return array Custom exception map, [exception => UserError/UserWarning] |
||
219 | */ |
||
220 | 50 | private function buildExceptionMap(array $exceptionConfig) |
|
237 | } |
||
238 |
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.