FindExecutableDefinitionsSubscriber   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 44
ccs 0
cts 18
cp 0
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 4 1
A __construct() 0 4 1
A onFindExecutableDefinitions() 0 8 4
1
<?php
2
3
namespace Deployee\Plugins\DeployEnv\Subscriber;
4
5
use Deployee\Components\DocBlock\DocBlock;
6
use Deployee\Components\Environment\EnvironmentInterface;
7
use Deployee\Plugins\Deploy\Events\FindExecutableDefinitionFilesEvent;
8
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9
10
class FindExecutableDefinitionsSubscriber implements EventSubscriberInterface
11
{
12
    /**
13
     * @var DocBlock
14
     */
15
    private $docBlock;
16
17
    /**
18
     * @var EnvironmentInterface
19
     */
20
    private $env;
21
22
    /**
23
     * @return array
24
     */
25
    public static function getSubscribedEvents(): array
26
    {
27
        return [
28
            FindExecutableDefinitionFilesEvent::class => 'onFindExecutableDefinitions'
29
        ];
30
    }
31
32
    /**
33
     * @param DocBlock $docBlock
34
     * @param EnvironmentInterface $env
35
     */
36
    public function __construct(DocBlock $docBlock, EnvironmentInterface $env)
37
    {
38
        $this->docBlock = $docBlock;
39
        $this->env = $env;
40
    }
41
42
    /**
43
     * @param FindExecutableDefinitionFilesEvent $event
44
     * @throws \ReflectionException
45
     */
46
    public function onFindExecutableDefinitions(FindExecutableDefinitionFilesEvent $event)
47
    {
48
        $collection = $event->getDefinitionFileCollection();
49
50
        foreach($collection->getArrayCopy() as $index => $class){
51
            $tagValues = $this->docBlock->getTagsByName($class, 'env');
52
            if($this->docBlock->hasTag($class, 'env') && !in_array($this->env->getName(), $tagValues, false)){
53
                $collection->offsetUnset($index);
54
            }
55
        }
56
    }
57
}