These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\SearchBundle\DependencyInjection; |
||
4 | |||
5 | use Symfony\Component\Config\FileLocator; |
||
6 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
||
7 | use Symfony\Component\DependencyInjection\Loader; |
||
8 | use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
||
9 | use Symfony\Component\Yaml\Yaml; |
||
10 | |||
11 | /** |
||
12 | * This is the class that loads and manages your bundle configuration |
||
13 | * |
||
14 | * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} |
||
15 | */ |
||
16 | class KunstmaanSearchExtension extends Extension |
||
17 | { |
||
18 | /** |
||
19 | * {@inheritdoc} |
||
20 | */ |
||
21 | 16 | public function load(array $configs, ContainerBuilder $container) |
|
22 | { |
||
23 | 16 | $configuration = new Configuration(); |
|
24 | 16 | $config = $this->processConfiguration($configuration, $configs); |
|
25 | |||
26 | 16 | if (\count($config['analyzer_languages']) <= 0) { |
|
27 | 16 | $config['analyzer_languages'] = $this->getDefaultAnalyzerLanguages(); |
|
28 | } |
||
29 | 16 | $container->setParameter('analyzer_languages', \array_change_key_case($config['analyzer_languages'], CASE_LOWER)); |
|
30 | |||
31 | 16 | $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
|
32 | 16 | $loader->load('services.yml'); |
|
33 | |||
34 | 16 | $this->loadConnectionParameters($container, $config); |
|
35 | |||
36 | 16 | $this->addSearchIndexPrefixParameter($container, $config); |
|
37 | 16 | } |
|
38 | |||
39 | 16 | public function getDefaultAnalyzerLanguages() |
|
40 | { |
||
41 | 16 | return Yaml::parse(file_get_contents(__DIR__ . '/../Resources/config/analyzer_languages.yml')); |
|
42 | } |
||
43 | |||
44 | 16 | private function loadConnectionParameters(ContainerBuilder $container, array $config) |
|
45 | { |
||
46 | 16 | $this->addHostParameter($container, $config); |
|
47 | 16 | $this->addPortParameter($container, $config); |
|
48 | 16 | $this->addUserParameter($container, $config); |
|
49 | 16 | $this->addPasswordParameter($container, $config); |
|
50 | 16 | } |
|
51 | |||
52 | 16 | View Code Duplication | private function addHostParameter(ContainerBuilder $container, array $config) |
0 ignored issues
–
show
|
|||
53 | { |
||
54 | 16 | $searchHost = $container->hasParameter('kunstmaan_search.hostname') ? $container->getParameter('kunstmaan_search.hostname') : 'localhost'; |
|
55 | 16 | if (null === $config['connection']['host'] && $searchHost !== 'localhost') { |
|
56 | 1 | @trigger_error('Not providing a value for the "kunstmaan_search.connection.host" config while setting the "kunstmaan_search.hostname" parameter is deprecated since KunstmaanDashboardBundle 5.2, this config value will replace the "kunstmaan_search.hostname" parameter in KunstmaanDashboardBundle 6.0.', E_USER_DEPRECATED); |
|
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
57 | } |
||
58 | |||
59 | 16 | if (null !== $config['connection']['host']) { |
|
60 | 1 | $searchHost = $config['connection']['host']; |
|
61 | } |
||
62 | |||
63 | 16 | $container->setParameter('kunstmaan_search.hostname', $searchHost); |
|
64 | 16 | } |
|
65 | |||
66 | 16 | View Code Duplication | private function addPortParameter(ContainerBuilder $container, array $config) |
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
67 | { |
||
68 | 16 | $searchPort = $container->hasParameter('kunstmaan_search.port') ? $container->getParameter('kunstmaan_search.port') : 9200; |
|
69 | 16 | if (null === $config['connection']['port'] && $searchPort !== 9200) { |
|
70 | 1 | @trigger_error('Not providing a value for the "kunstmaan_search.connection.port" config while setting the "kunstmaan_search.port" parameter is deprecated since KunstmaanDashboardBundle 5.2, this config value will replace the "kunstmaan_search.port" parameter in KunstmaanDashboardBundle 6.0.', E_USER_DEPRECATED); |
|
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
71 | } |
||
72 | |||
73 | 16 | if (null !== $config['connection']['port']) { |
|
74 | 1 | $searchPort = $config['connection']['port']; |
|
75 | } |
||
76 | |||
77 | 16 | $container->setParameter('kunstmaan_search.port', $searchPort); |
|
78 | 16 | } |
|
79 | |||
80 | 16 | View Code Duplication | private function addUserParameter(ContainerBuilder $container, array $config) |
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
81 | { |
||
82 | 16 | $searchUsername = $container->hasParameter('kunstmaan_search.username') ? $container->getParameter('kunstmaan_search.username') : null; |
|
83 | 16 | if (null === $config['connection']['username'] && null !== $searchUsername) { |
|
84 | 1 | @trigger_error('Not providing a value for the "kunstmaan_search.connection.username" config while setting the "kunstmaan_search.username" parameter is deprecated since KunstmaanDashboardBundle 5.2, this config value will replace the "kunstmaan_search.username" parameter in KunstmaanDashboardBundle 6.0.', E_USER_DEPRECATED); |
|
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
85 | } |
||
86 | |||
87 | 16 | if (null !== $config['connection']['username']) { |
|
88 | 1 | $searchUsername = $config['connection']['username']; |
|
89 | } |
||
90 | |||
91 | 16 | $container->setParameter('kunstmaan_search.username', $searchUsername); |
|
92 | 16 | } |
|
93 | |||
94 | 16 | View Code Duplication | private function addPasswordParameter(ContainerBuilder $container, array $config) |
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
95 | { |
||
96 | 16 | $searchPassword = $container->hasParameter('kunstmaan_search.password') ? $container->getParameter('kunstmaan_search.password') : null; |
|
97 | 16 | if (null === $config['connection']['password'] && null !== $searchPassword) { |
|
98 | 1 | @trigger_error('Not providing a value for the "kunstmaan_search.connection.password" config while setting the "kunstmaan_search.password" parameter is deprecated since KunstmaanDashboardBundle 5.2, this config value will replace the "kunstmaan_search.password" parameter in KunstmaanDashboardBundle 6.0.', E_USER_DEPRECATED); |
|
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
99 | } |
||
100 | |||
101 | 16 | if (null !== $config['connection']['password']) { |
|
102 | 1 | $searchPassword = $config['connection']['password']; |
|
103 | } |
||
104 | |||
105 | 16 | $container->setParameter('kunstmaan_search.password', $searchPassword); |
|
106 | 16 | } |
|
107 | |||
108 | 16 | View Code Duplication | private function addSearchIndexPrefixParameter(ContainerBuilder $container, array $config) |
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
109 | { |
||
110 | 16 | $indexPrefix = $container->hasParameter('searchindexprefix') ? $container->getParameter('searchindexprefix') : null; |
|
111 | 16 | if (null === $config['index_prefix'] && null !== $indexPrefix) { |
|
112 | 1 | @trigger_error('Not providing a value for the "kunstmaan_search.index_prefix" config while setting the "searchindexprefix" parameter is deprecated since KunstmaanDashboardBundle 5.2, this config value will replace the "searchindexprefix" parameter in KunstmaanDashboardBundle 6.0.', E_USER_DEPRECATED); |
|
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
113 | } |
||
114 | |||
115 | 16 | if (null !== $config['index_prefix']) { |
|
116 | 1 | $indexPrefix = $config['index_prefix']; |
|
117 | } |
||
118 | |||
119 | 16 | $container->setParameter('kunstmaan_search.index_prefix', $indexPrefix); |
|
120 | 16 | } |
|
121 | } |
||
122 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.