Completed
Push — master ( 6ccc0f...513904 )
by Saulius
01:59
created

SaulsComponentsExtension::loadCollectionsConfiguration()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 3
crap 2
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 Symfony\Component\Config\FileLocator;
17
use Symfony\Component\Config\Loader\LoaderInterface;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
use Symfony\Component\DependencyInjection\Extension\Extension;
20
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
21
use Sauls\Bundle\Components\DependencyInjection\Compiler\RegisterCollectionConvertersPass;
22
23
class SaulsComponentsExtension extends Extension
24
{
25
    /**
26
     * @throws \Exception
27
     * @throws \Sauls\Component\Helper\Exception\PropertyNotAccessibleException
28
     * @throws \InvalidArgumentException When provided tag is not defined in this extension
29
     */
30 4
    public function load(array $configs, ContainerBuilder $container)
31
    {
32 4
        $loader = new YamlFileLoader($container, new FileLocator(\dirname(__DIR__).'/Resources/config'));
33
34 4
        $this->loadHelpersConfiguration($configs, $container, $loader);
35 4
        $this->loadWidgetsConfiguration($configs, $container, $loader);
36
37 4
        $container->addCompilerPass(new RegisterCollectionConvertersPass());
38 4
    }
39
40
    /**
41
     * @throws \Exception
42
     * @throws \Sauls\Component\Helper\Exception\PropertyNotAccessibleException
43
     */
44 4
    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

44
    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...
45
    {
46 4
        if ($this->componentIsNotEnabled('helpers', $configs)) {
47 1
            return;
48
        }
49
50 3
        $loader->load('helpers.yaml');
51 3
    }
52
53
    /**
54
     * @throws \Exception
55
     * @throws \Sauls\Component\Helper\Exception\PropertyNotAccessibleException
56
     */
57 4
    private function loadWidgetsConfiguration(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

57
    private function loadWidgetsConfiguration(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...
58
    {
59 4
        if ($this->componentIsNotEnabled('widgets', $configs)) {
60 1
            return;
61
        }
62
63 3
        $loader->load('widgets.yaml');
64 3
    }
65
66
    /**
67
     * @throws \Exception
68
     * @throws \Sauls\Component\Helper\Exception\PropertyNotAccessibleException
69
     */
70 4
    private function componentIsNotEnabled(string $componentName, array $configs): bool
0 ignored issues
show
Unused Code introduced by
The parameter $componentName 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

70
    private function componentIsNotEnabled(/** @scrutinizer ignore-unused */ string $componentName, array $configs): bool

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...
71
    {
72 4
        return false === array_get_value($configs, 'helpers', false);
73
    }
74
}
75