Completed
Push — master ( c9d0f8...e25395 )
by Saulius
06:08 queued 03:54
created

loadSecurityAccessComponent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 3
dl 0
loc 11
ccs 7
cts 7
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the sauls/components-bundle package.
4
 *
5
 * @author    Saulius Vaičeliūnas <[email protected]>
6
 * @link      http://saulius.vaiceliunas.lt
7
 * @copyright 2018
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Sauls\Bundle\Components\DependencyInjection;
14
15
use function Sauls\Component\Helper\array_get_value;
16
use Sauls\Component\Widget\View\ViewInterface;
17
use Sauls\Component\Widget\WidgetInterface;
18
use Symfony\Component\Config\FileLocator;
19
use Symfony\Component\Config\Loader\LoaderInterface;
20
use Symfony\Component\DependencyInjection\ContainerBuilder;
21
use Symfony\Component\DependencyInjection\Extension\Extension;
22
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
23
24
class SaulsComponentsExtension extends Extension
25
{
26
    /**
27
     * @throws \Exception
28
     * @throws \Sauls\Component\Helper\Exception\PropertyNotAccessibleException
29
     * @throws \InvalidArgumentException When provided tag is not defined in this extension
30
     */
31 5
    public function load(array $configs, ContainerBuilder $container)
32
    {
33
34 5
        $configuration = $this->getConfiguration($configs, $container);
35 5
        $config = $this->processConfiguration($configuration, $configs);
36
37 5
        $loader = new YamlFileLoader($container, new FileLocator(\dirname(__DIR__).'/Resources/config'));
38
39 5
        $this->loadHelpersConfiguration($config, $container, $loader);
40 5
        $this->loadWidgetsConfiguration($config, $container, $loader);
41 5
        $this->loadComponentsConfiguration($config, $container, $loader);
42 5
    }
43
44
    /**
45
     * @throws \Exception
46
     * @throws \Sauls\Component\Helper\Exception\PropertyNotAccessibleException
47
     */
48 5
    private function loadHelpersConfiguration(array $configs, ContainerBuilder $container, LoaderInterface $loader)
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

48
    private function loadHelpersConfiguration(array $configs, /** @scrutinizer ignore-unused */ ContainerBuilder $container, LoaderInterface $loader)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
49
    {
50 5
        if ($this->componentIsNotEnabled('helpers', $configs)) {
51 1
            return;
52
        }
53
54 4
        $loader->load('helpers.yaml');
55 4
    }
56
57
    /**
58
     * @throws \Exception
59
     * @throws \Sauls\Component\Helper\Exception\PropertyNotAccessibleException
60
     */
61 5
    private function loadWidgetsConfiguration(array $configs, ContainerBuilder $container, LoaderInterface $loader)
62
    {
63 5
        if ($this->componentIsNotEnabled('widgets', $configs)) {
64 1
            return;
65
        }
66
67 4
        $loader->load('widgets.yaml');
68
69
        $container
70 4
            ->registerForAutoconfiguration(WidgetInterface::class)
71 4
            ->addTag('sauls_widget.widget')
72 4
            ->setPublic(true);
73
74
        $container
75 4
            ->registerForAutoconfiguration(ViewInterface::class)
76 4
            ->addTag('sauls_widget.view')
77 4
            ->setPrivate(true);
78 4
    }
79
80 5
    private function loadComponentsConfiguration(array $configs, ContainerBuilder $container, LoaderInterface $loader)
81
    {
82 5
        $this->loadSecurityAccessComponent($configs, $container, $loader);
83 5
    }
84
85 5
    private function loadSecurityAccessComponent(array $configs, ContainerBuilder $container, LoaderInterface $loader)
86
    {
87 5
        if ($this->componentIsNotEnabled('components.access', $configs)) {
88 4
            return;
89
        }
90
91 1
        $loader->load('component/security/access.yaml');
92
93 1
        $container->setParameter(
94 1
            'sauls_components.component.access.options',
95 1
            array_get_value($configs, 'components.access')
96
        );
97 1
    }
98
99
    /**
100
     * @throws \Exception
101
     * @throws \Sauls\Component\Helper\Exception\PropertyNotAccessibleException
102
     */
103 5
    private function componentIsNotEnabled(string $componentName, array $configs): bool
104
    {
105 5
        return false === array_get_value($configs, $componentName, false);
106
    }
107
}
108