ProvisionListener   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 40
ccs 0
cts 21
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setAppDirectory() 0 4 1
A handle() 0 20 3
1
<?php
2
3
namespace Innmind\ProvisionerBundle\EventListener;
4
5
use Innmind\ProvisionerBundle\Event\ProvisionEvent;
6
use Symfony\Component\Process\Process;
7
8
/**
9
 * Listen when new commands must be run
10
 */
11
class ProvisionListener
12
{
13
    protected $appDir;
14
15
    /**
16
     * Set the application root directory
17
     *
18
     * @param string $directory
19
     */
20
    public function setAppDirectory($directory)
21
    {
22
        $this->appDir = (string) $directory;
23
    }
24
25
    /**
26
     * Run the specified number of symfony commands in the background
27
     *
28
     * @param ProvisionEvent $event
29
     */
30
    public function handle(ProvisionEvent $event)
31
    {
32
        $input = $event->getCommandInput();
33
        $toRun = $event->getCount();
34
35
        if ($toRun === 0) {
36
            return;
37
        }
38
39
        $command = sprintf(
40
            'cd %s && ./console %s',
41
            $this->appDir,
42
            (string) $input
43
        );
44
45
        for ($i = 0; $i < $toRun; $i++) {
46
            $process = new Process($command);
47
            $process->start();
48
        }
49
    }
50
}
51