We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
1 | <?php |
||
20 | class OverblogGraphQLTypesExtension extends Extension |
||
21 | { |
||
22 | private static $configTypes = ['yml', 'xml']; |
||
23 | |||
24 | public function load(array $configs, ContainerBuilder $container) |
||
25 | { |
||
26 | $configuration = $this->getConfiguration($configs, $container); |
||
27 | $config = $this->processConfiguration($configuration, $configs); |
||
|
|||
28 | 19 | ||
29 | $container->setParameter($this->getAlias().'.config', $config); |
||
30 | 19 | } |
|
31 | 19 | ||
32 | public function containerPrependExtensionConfig(array $config, ContainerBuilder $container) |
||
41 | 14 | ||
42 | /** |
||
43 | * @param $type |
||
44 | 14 | * @param SplFileInfo[] $files |
|
45 | 14 | * @param ContainerBuilder $container |
|
46 | 12 | */ |
|
47 | 12 | private function prependExtensionConfigFromFiles($type, $files, ContainerBuilder $container) |
|
48 | { |
||
49 | /** @var SplFileInfo $file */ |
||
50 | foreach ($files as $file) { |
||
51 | $parserClass = sprintf('Overblog\\GraphQLBundle\\Config\\Parser\\%sParser', ucfirst($type)); |
||
52 | |||
53 | $typeConfig = call_user_func($parserClass.'::parse', $file, $container); |
||
54 | 14 | $container->prependExtensionConfig($this->getAlias(), $typeConfig); |
|
55 | } |
||
56 | } |
||
57 | 14 | ||
58 | 14 | private function mappingConfig(array $config, ContainerBuilder $container) |
|
59 | 12 | { |
|
60 | 12 | $typesMappings = empty($config['definitions']['mappings']['types']) ? [] : $config['definitions']['mappings']['types']; |
|
61 | 12 | ||
62 | // app only config files (yml or xml) |
||
63 | 2 | if ($container->hasParameter('kernel.root_dir')) { |
|
64 | $typesMappings[] = ['dir' => $container->getParameter('kernel.root_dir').'/config/graphql', 'type' => null]; |
||
65 | 2 | } |
|
66 | |||
67 | $mappingFromBundles = $this->mappingFromBundles($container); |
||
68 | $typesMappings = array_merge($typesMappings, $mappingFromBundles); |
||
69 | 2 | ||
70 | 1 | // from config |
|
71 | 1 | $typesMappings = array_filter(array_map( |
|
72 | 1 | function (array $typeMapping) use ($container) { |
|
73 | $params = $this->detectFilesByType($container, $typeMapping['dir'], $typeMapping['type']); |
||
74 | 1 | ||
75 | 1 | return $params; |
|
76 | 1 | }, |
|
77 | 1 | $typesMappings |
|
78 | 2 | )); |
|
79 | 1 | ||
80 | return $typesMappings; |
||
81 | } |
||
82 | 1 | ||
83 | private function mappingFromBundles(ContainerBuilder $container) |
||
99 | |||
100 | private function detectFilesByType(ContainerBuilder $container, $path, $type = null) |
||
101 | 14 | { |
|
102 | // add the closest existing directory as a resource |
||
103 | 14 | $resource = $path; |
|
104 | while (!is_dir($resource)) { |
||
105 | 14 | $resource = dirname($resource); |
|
106 | 13 | } |
|
107 | 13 | $container->addResource(new FileResource($resource)); |
|
108 | 13 | ||
109 | $finder = new Finder(); |
||
110 | 13 | ||
111 | 13 | $types = null === $type ? self::$configTypes : [$type]; |
|
112 | 13 | ||
113 | 13 | foreach ($types as $type) { |
|
114 | 13 | try { |
|
115 | $finder->files()->in($path)->name('*.types.'.$type); |
||
116 | 14 | } catch (\InvalidArgumentException $e) { |
|
117 | continue; |
||
118 | } |
||
119 | 14 | if ($finder->count() > 0) { |
|
120 | return [ |
||
121 | 14 | 'type' => $type, |
|
122 | 14 | 'files' => $finder, |
|
123 | ]; |
||
124 | } |
||
125 | 14 | } |
|
126 | 12 | ||
127 | 12 | return; |
|
128 | } |
||
129 | 12 | ||
130 | 12 | public function getAliasPrefix() |
|
131 | { |
||
132 | 12 | return 'overblog_graphql'; |
|
133 | 12 | } |
|
134 | 12 | ||
135 | 14 | public function getAlias() |
|
139 | |||
140 | 14 | public function getConfiguration(array $config, ContainerBuilder $container) |
|
144 | } |
||
145 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: