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 | |||
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 KunstmaanFormExtension extends Extension implements PrependExtensionInterface |
||
17 | { |
||
18 | /** |
||
19 | * {@inheritDoc} |
||
20 | */ |
||
21 | public function load(array $configs, ContainerBuilder $container) |
||
22 | { |
||
23 | |||
24 | $configuration = new Configuration(); |
||
25 | $config = $this->processConfiguration($configuration, $configs); |
||
26 | |||
27 | $container->setParameter('kunstmaan_form.deletable_formsubmissions' , $config['deletable_formsubmissions']); |
||
28 | |||
29 | $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
||
30 | $loader->load('services.yml'); |
||
31 | } |
||
32 | |||
33 | public function prepend(ContainerBuilder $container) |
||
34 | { |
||
35 | if(!$container->hasParameter('form_submission_rootdir')) { |
||
36 | $container->setParameter('form_submission_rootdir', |
||
37 | sprintf('%s/../web/uploads/formsubmissions', $container->getParameter('kernel.root_dir'))); |
||
38 | } |
||
39 | |||
40 | if(!$container->hasParameter('form_submission_webdir')) { |
||
41 | $container->setParameter('form_submission_webdir', '/uploads/formsubmissions/'); |
||
42 | } |
||
43 | |||
44 | $twigConfig['globals']['form_submission_webdir'] = $container->getParameter('form_submission_webdir'); |
||
0 ignored issues
–
show
|
|||
45 | $container->prependExtensionConfig('twig', $twigConfig); |
||
46 | $configs = $container->getExtensionConfig($this->getAlias()); |
||
47 | $this->processConfiguration(new Configuration(), $configs); |
||
48 | } |
||
49 | } |
||
50 |
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:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.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.