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