ProvisionListener::setAppDirectory()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
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