Passed
Pull Request — master (#6127)
by Angel Fernando Quiroz
07:52
created

PluginEventSubscriberPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 16 4
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
declare(strict_types=1);
6
7
namespace Chamilo\CoreBundle\DependencyInjection\Compiler;
8
9
use SplFileInfo;
10
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
11
use Symfony\Component\DependencyInjection\ContainerBuilder;
12
use Symfony\Component\DependencyInjection\Definition;
13
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
14
use Symfony\Component\Finder\Finder;
15
16
class PluginEventSubscriberPass implements CompilerPassInterface
17
{
18
    /**
19
     * @inheritDoc
20
     */
21
    public function process(ContainerBuilder $container): void
22
    {
23
        $pluginSubscriberDir = __DIR__.'/../../../../public/plugin';
24
25
        $finder = new Finder();
26
        $finder->files()->in($pluginSubscriberDir)->name('*EventSubscriber.php');
27
28
        /** @var SplFileInfo $file */
29
        foreach ($finder as $file) {
30
            $className = pathinfo($file->getFilename(), PATHINFO_FILENAME);
31
32
            if (class_exists($className) && is_subclass_of($className, EventSubscriberInterface::class)) {
33
                $definition = new Definition($className);
34
                $definition->setAutowired(true);
35
                $definition->addTag('kernel.event_subscriber');
36
                $container->setDefinition($className, $definition);
37
            }
38
        }
39
    }
40
}