CushonHealthExtension   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 43
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A load() 0 7 1
A createLoader() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cushon\HealthBundle\DependencyInjection;
6
7
use Cushon\HealthBundle\ApplicationHealth\DependencyCheck;
8
use Cushon\HealthBundle\CushonHealthBundle;
9
use Cushon\HealthBundle\Traits\BundleRootKeyTrait;
10
use Symfony\Component\Config\FileLocator;
11
use Symfony\Component\Config\Loader\FileLoader;
12
use Symfony\Component\DependencyInjection\ContainerBuilder;
13
use Symfony\Component\DependencyInjection\Extension\Extension;
14
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
15
16
final class CushonHealthExtension extends Extension
17
{
18
    use BundleRootKeyTrait;
19
20
    public const KEY_DEPENDENCY_CHECKS = 'dependency_check';
21
22
    /** @var FileLocator  */
23
    private FileLocator $fileLocator;
24
25
    /**
26
     * @param FileLocator $fileLocator
27
     * @param string $rootKey
28
     */
29
    public function __construct(
30
        FileLocator $fileLocator,
31
        string $rootKey = CushonHealthBundle::BUNDLE_ROOT_KEY
32
    ) {
33
        $this->fileLocator = $fileLocator;
34
        $this->rootKey = $rootKey;
35
    }
36
37
    /**
38
     * @param mixed[] $configs
39
     * @param ContainerBuilder $container
40
     * @throws \Exception
41
     * @SuppressWarnings(PHPMD.UnusedFormalParameter) Comes from the Symfony parent
42
     */
43
    public function load(array $configs, ContainerBuilder $container): void
44
    {
45
        $this->createLoader($container)->load('services.yaml');
46
        $dependencyCheckTag = $this->generateKeyFromRoot(self::KEY_DEPENDENCY_CHECKS);
47
48
        $container->registerForAutoconfiguration(DependencyCheck::class)
49
            ->addTag($dependencyCheckTag);
50
    }
51
52
    /**
53
     * @param ContainerBuilder $container
54
     * @return FileLoader
55
     */
56
    private function createLoader(ContainerBuilder $container): FileLoader
57
    {
58
        return new YamlFileLoader($container, $this->fileLocator);
59
    }
60
}
61