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\FormBundle\DependencyInjection; |
||
4 | |||
5 | use Symfony\Component\Config\FileLocator; |
||
6 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
||
7 | use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
||
8 | use Symfony\Component\DependencyInjection\Loader; |
||
9 | use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
||
10 | use Symfony\Component\HttpKernel\Kernel; |
||
11 | |||
12 | /** |
||
13 | * This is the class that loads and manages your bundle configuration |
||
14 | * |
||
15 | * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} |
||
16 | */ |
||
17 | class KunstmaanFormExtension extends Extension implements PrependExtensionInterface |
||
18 | { |
||
19 | /** |
||
20 | * {@inheritdoc} |
||
21 | */ |
||
22 | 1 | View Code Duplication | public function load(array $configs, ContainerBuilder $container) |
0 ignored issues
–
show
|
|||
23 | { |
||
24 | 1 | $configuration = new Configuration(); |
|
25 | 1 | $config = $this->processConfiguration($configuration, $configs); |
|
26 | |||
27 | 1 | $container->setParameter('kunstmaan_form.deletable_formsubmissions', $config['deletable_formsubmissions']); |
|
28 | |||
29 | 1 | $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
30 | 1 | $loader->load('services.yml'); |
|
31 | 1 | } |
|
32 | |||
33 | 1 | public function prepend(ContainerBuilder $container) |
|
34 | { |
||
35 | 1 | if (!$container->hasParameter('form_submission_rootdir')) { |
|
36 | 1 | $container->setParameter('form_submission_rootdir', |
|
37 | 1 | sprintf('%s/%s/uploads/formsubmissions', $container->getParameter('kernel.project_dir'), Kernel::VERSION_ID >= 40000 ? 'public' : 'web')); |
|
38 | } |
||
39 | |||
40 | 1 | if (!$container->hasParameter('form_submission_webdir')) { |
|
41 | 1 | $container->setParameter('form_submission_webdir', '/uploads/formsubmissions/'); |
|
42 | } |
||
43 | |||
44 | 1 | $twigConfig['globals']['form_submission_webdir'] = $container->getParameter('form_submission_webdir'); |
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$twigConfig was never initialized. Although not strictly required by PHP, it is generally a good practice to add $twigConfig = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.
Loading history...
|
|||
45 | 1 | $container->prependExtensionConfig('twig', $twigConfig); |
|
46 | 1 | $configs = $container->getExtensionConfig($this->getAlias()); |
|
47 | 1 | $this->processConfiguration(new Configuration(), $configs); |
|
48 | 1 | } |
|
49 | } |
||
50 |
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.