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\NodeBundle\DependencyInjection; |
||
4 | |||
5 | use Symfony\Component\Config\FileLocator; |
||
6 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
||
7 | use Symfony\Component\DependencyInjection\Definition; |
||
8 | use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
||
9 | use Symfony\Component\DependencyInjection\Loader; |
||
10 | use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
||
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 KunstmaanNodeExtension extends Extension implements PrependExtensionInterface |
||
18 | { |
||
19 | /** |
||
20 | * {@inheritdoc} |
||
21 | */ |
||
22 | 1 | public function load(array $configs, ContainerBuilder $container) |
|
23 | { |
||
24 | 1 | $configuration = new Configuration(); |
|
25 | 1 | $config = $this->processConfiguration($configuration, $configs); |
|
26 | |||
27 | 1 | $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
28 | |||
29 | 1 | $container->setParameter('twig.form.resources', array_merge( |
|
30 | 1 | $container->getParameter('twig.form.resources'), |
|
31 | 1 | array('KunstmaanNodeBundle:Form:formWidgets.html.twig') |
|
32 | )); |
||
33 | |||
34 | 1 | $nodePagesDefinition = new Definition('Kunstmaan\NodeBundle\Helper\PagesConfiguration', [$config['pages']]); |
|
35 | 1 | $nodePagesDefinition->setPublic(true); |
|
36 | 1 | $container->setDefinition('kunstmaan_node.pages_configuration', $nodePagesDefinition); |
|
37 | |||
38 | 1 | $container->setParameter('kunstmaan_node.show_add_homepage', $config['show_add_homepage']); |
|
39 | 1 | $container->setParameter('kunstmaan_node.enable_export_page_template', $config['enable_export_page_template']); |
|
40 | 1 | $container->setParameter('kunstmaan_node.lock_check_interval', $config['lock']['check_interval']); |
|
41 | 1 | $container->setParameter('kunstmaan_node.lock_threshold', $config['lock']['threshold']); |
|
42 | 1 | $container->setParameter('kunstmaan_node.lock_enabled', $config['lock']['enabled']); |
|
43 | |||
44 | 1 | $loader->load('services.yml'); |
|
45 | 1 | $loader->load('commands.yml'); |
|
46 | 1 | } |
|
47 | |||
48 | 1 | public function prepend(ContainerBuilder $container) |
|
49 | { |
||
50 | 1 | $cmfRoutingExtraConfig['chain']['routers_by_id']['router.default'] = 100; |
|
0 ignored issues
–
show
|
|||
51 | 1 | $cmfRoutingExtraConfig['chain']['replace_symfony_router'] = true; |
|
52 | 1 | $container->prependExtensionConfig('cmf_routing', $cmfRoutingExtraConfig); |
|
53 | |||
54 | 1 | $configs = $container->getExtensionConfig($this->getAlias()); |
|
55 | 1 | $config = $this->processConfiguration(new Configuration(), $configs); |
|
56 | |||
57 | // set twig global params |
||
58 | 1 | $twigConfig['globals']['nodebundleisactive'] = true; |
|
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...
|
|||
59 | 1 | $twigConfig['globals']['publish_later_stepping'] = $config['publish_later_stepping']; |
|
60 | 1 | $twigConfig['globals']['unpublish_later_stepping'] = $config['unpublish_later_stepping']; |
|
61 | 1 | $container->prependExtensionConfig('twig', $twigConfig); |
|
62 | 1 | } |
|
63 | } |
||
64 |
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.