ConsoleListener::handle()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 14
ccs 0
cts 11
cp 0
rs 9.4286
cc 3
eloc 7
nc 3
nop 1
crap 12
1
<?php
2
3
namespace Innmind\ProvisionerBundle\EventListener;
4
5
use Innmind\ProvisionerBundle\DecisionManager;
6
use Innmind\ProvisionerBundle\TriggerManager;
7
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
8
9
/**
10
 * Check if the provisioner must be runned when a command finishes
11
 */
12
class ConsoleListener
13
{
14
    protected $decision;
15
    protected $trigger;
16
17
    /**
18
     * Set the decision manager
19
     *
20
     * @param DecisionManager $manager
21
     */
22
    public function setDecisionManager(DecisionManager $manager)
23
    {
24
        $this->decision = $manager;
25
    }
26
27
    /**
28
     * Set the manager used to know if the provisioning should be started
29
     *
30
     * @param string $manager
31
     */
32
    public function setTriggerManager(TriggerManager $manager)
33
    {
34
        $this->trigger = $manager;
35
    }
36
37
    /**
38
     * Handle event
39
     *
40
     * @param ConsoleTerminateEvent $event
41
     */
42
    public function handle(ConsoleTerminateEvent $event)
43
    {
44
        if ($event->getExitCode() !== 0) {
45
            //do not try to provision failling commands
46
            return;
47
        }
48
49
        $command = $event->getCommand()->getName();
50
        $input = $event->getInput();
51
52
        if ($this->trigger->decide($command, $input)) {
53
            $this->decision->provision($command, $input);
54
        }
55
    }
56
}
57