CommandPass   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 13
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 11 5
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the dotfiles project.
7
 *
8
 *     (c) Anthonius Munthi <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Dotfiles\Core\DI\Compiler;
15
16
use Dotfiles\Core\Application;
17
use Dotfiles\Core\Command\CommandInterface;
18
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
19
use Symfony\Component\DependencyInjection\ContainerBuilder;
20
use Symfony\Component\DependencyInjection\Reference;
21
22
class CommandPass implements CompilerPassInterface
23
{
24
    public function process(ContainerBuilder $container): void
25
    {
26
        $application = $container->findDefinition(Application::class);
27
        $definitions = $container->getDefinitions();
28
29
        foreach ($definitions as $definition) {
30
            $class = $definition->getClass();
31
            if (null !== $class && class_exists($class)) {
32
                $r = new \ReflectionClass($class);
33
                if ($r->implementsInterface(CommandInterface::class)) {
34
                    $application->addMethodCall('add', array(new Reference($class)));
35
                }
36
            }
37
        }
38
    }
39
}
40