We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
1 | <?php |
||
24 | class OverblogGraphQLExtension extends Extension implements PrependExtensionInterface |
||
25 | { |
||
26 | public function load(array $configs, ContainerBuilder $container) |
||
27 | { |
||
28 | $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
||
29 | 16 | $loader->load('services.yml'); |
|
30 | $loader->load('graphql_types.yml'); |
||
31 | 16 | $loader->load('graphql_resolvers.yml'); |
|
32 | 16 | ||
33 | 16 | $config = $this->treatConfigs($configs, $container); |
|
34 | |||
35 | 16 | $this->setExpressionLanguageDefaultParser($container); |
|
36 | $this->setServicesAliases($config, $container); |
||
|
|||
37 | 16 | $this->setSchemaBuilderArguments($config, $container); |
|
38 | 16 | $this->setSchemaArguments($config, $container); |
|
39 | 16 | $this->setErrorHandlerArguments($config, $container); |
|
40 | 16 | $this->setGraphiQLTemplate($config, $container); |
|
41 | 16 | $this->setSecurity($config, $container); |
|
42 | 16 | $this->setConfigBuilders($config, $container); |
|
43 | 16 | $this->setVersions($config, $container); |
|
44 | 16 | $this->setShowDebug($config, $container); |
|
45 | 16 | ||
46 | 16 | $container->setParameter($this->getAlias().'.resources_dir', realpath(__DIR__.'/../Resources')); |
|
47 | 16 | } |
|
48 | 16 | ||
49 | public function prepend(ContainerBuilder $container) |
||
50 | 16 | { |
|
51 | 16 | $configs = $container->getExtensionConfig($this->getAlias()); |
|
52 | $configs = $container->getParameterBag()->resolveValue($configs); |
||
53 | 14 | $config = $this->treatConfigs($configs, $container, true); |
|
54 | |||
55 | 14 | /** @var OverblogGraphQLTypesExtension $typesExtension */ |
|
56 | 14 | $typesExtension = $container->getExtension($this->getAlias().'_types'); |
|
57 | 14 | $typesExtension->containerPrependExtensionConfig($config, $container); |
|
58 | } |
||
59 | |||
60 | 14 | private function setExpressionLanguageDefaultParser(ContainerBuilder $container) |
|
61 | 14 | { |
|
62 | 14 | $class = version_compare(Kernel::VERSION, '3.2.0', '>=') ? |
|
63 | 'Symfony\\Component\\Cache\Adapter\\ArrayAdapter' |
||
64 | 16 | : 'Symfony\\Component\\ExpressionLanguage\\ParserCache\\ArrayParserCache' |
|
65 | ; |
||
66 | 16 | $definition = new Definition($class); |
|
67 | $definition->setPublic(false); |
||
68 | $container->setDefinition($this->getAlias().'.cache_expression_language_parser.default', $definition); |
||
69 | 16 | } |
|
70 | |||
71 | 16 | private function setShowDebug(array $config, ContainerBuilder $container) |
|
72 | { |
||
73 | $container->getDefinition($this->getAlias().'.request_executor')->replaceArgument(4, $config['definitions']['show_debug_info']); |
||
74 | 16 | } |
|
75 | |||
76 | 16 | private function setVersions(array $config, ContainerBuilder $container) |
|
77 | 16 | { |
|
78 | 16 | $container->setParameter($this->getAlias().'.versions.graphiql', $config['versions']['graphiql']); |
|
79 | $container->setParameter($this->getAlias().'.versions.react', $config['versions']['react']); |
||
80 | 16 | $container->setParameter($this->getAlias().'.versions.fetch', $config['versions']['fetch']); |
|
81 | } |
||
82 | 16 | ||
83 | 16 | private function setConfigBuilders(array $config, ContainerBuilder $container) |
|
84 | { |
||
85 | 16 | foreach (['args', 'field'] as $category) { |
|
86 | if (!empty($config['definitions']['builders'][$category])) { |
||
87 | 16 | $method = 'add'.ucfirst($category).'BuilderClass'; |
|
88 | 16 | ||
89 | 16 | foreach ($config['definitions']['builders'][$category] as $params) { |
|
90 | 16 | $container->addClassResource(new \ReflectionClass($params['class'])); |
|
91 | 16 | TypeWithOutputFieldsDefinition::$method($params['alias'], $params['class']); |
|
92 | } |
||
93 | 16 | } |
|
94 | } |
||
95 | 16 | } |
|
96 | 16 | ||
97 | private function treatConfigs(array $configs, ContainerBuilder $container, $forceReload = false) |
||
108 | 16 | ||
109 | 1 | private function setSecurity(array $config, ContainerBuilder $container) |
|
114 | 1 | ||
115 | 1 | private function setGraphiQLTemplate(array $config, ContainerBuilder $container) |
|
119 | 16 | ||
120 | private function setErrorHandlerArguments(array $config, ContainerBuilder $container) |
||
121 | 16 | { |
|
122 | $errorHandlerDefinition = $container->getDefinition($this->getAlias().'.error_handler'); |
||
123 | 16 | ||
124 | 16 | if (isset($config['definitions']['internal_error_message'])) { |
|
125 | 16 | $errorHandlerDefinition->replaceArgument(0, $config['definitions']['internal_error_message']); |
|
136 | 16 | ||
137 | private function setSchemaBuilderArguments(array $config, ContainerBuilder $container) |
||
142 | |||
143 | 16 | private function setSchemaArguments(array $config, ContainerBuilder $container) |
|
160 | 16 | ||
161 | private function setServicesAliases(array $config, ContainerBuilder $container) |
||
170 | |||
171 | 16 | public function getAlias() |
|
175 | 13 | ||
176 | 13 | public function getConfiguration(array $config, ContainerBuilder $container) |
|
180 | 16 | ||
181 | 16 | /** |
|
182 | 16 | * Returns a list of custom exceptions mapped to error/warning classes. |
|
183 | * |
||
184 | 16 | * @param array $exceptionConfig |
|
185 | * |
||
186 | 16 | * @return array Custom exception map, [exception => UserError/UserWarning] |
|
187 | 16 | */ |
|
188 | 16 | private function buildExceptionMap(array $exceptionConfig) |
|
205 | } |
||
206 |
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.