ProvisionListener::handle()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
ccs 0
cts 17
cp 0
rs 9.4286
cc 3
eloc 12
nc 3
nop 1
crap 12
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