SymfonyCommandExecutor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A execute() 0 14 2
A onConsoleCommand() 0 5 1
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