SymfonyCommandExecutor::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 14
ccs 7
cts 7
cp 1
rs 9.4285
cc 2
eloc 7
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Velikonja\LabbyBundle\Executor;
4
5
use Symfony\Component\Console\Application;
6
use Symfony\Component\Console\Event\ConsoleCommandEvent;
7
use Symfony\Component\Console\Input\StringInput;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
class SymfonyCommandExecutor implements ExecutorInterface
11
{
12
    /**
13
     * @var Application
14
     */
15
    private $app;
16
17
    /**
18
     * @param string               $command
19
     * @param OutputInterface|null $output
20
     *
21
     * @return int
22
     */
23 3
    public function execute($command, OutputInterface $output = null)
24
    {
25 3
        $input = new StringInput($command);
26
27 3
        $exitCode = $this->app->run($input, $output);
28
29 3
        if ($exitCode != 0) {
30 1
            throw new \RuntimeException(
31 1
                sprintf('Command `%s` failed.', $command)
32
            );
33
        }
34
35 3
        return $exitCode;
36
    }
37
38
    /**
39
     * @param ConsoleCommandEvent $event
40
     */
41 10
    public function onConsoleCommand(ConsoleCommandEvent $event)
42
    {
43 10
        $this->app = clone $event->getCommand()->getApplication();
44 10
        $this->app->setAutoExit(false);
45 10
    }
46
47
    /**
48
     * @return string
49
     */
50 4
    public function getName()
51
    {
52 4
        return 'sf';
53
    }
54
}
55