Completed
Push — master ( 769748...7b8fb0 )
by Baptiste
12s
created

DebugController::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
namespace Behapi\Cli;
3
4
use Symfony\Component\Console\Command\Command;
5
use Symfony\Component\Console\Output\OutputInterface;
6
7
use Symfony\Component\Console\Input\InputOption;
8
use Symfony\Component\Console\Input\InputInterface;
9
10
use Behat\Testwork\Cli\Controller;
11
use Behat\Testwork\Output\OutputManager;
12
13
use Behapi\Tools\Debug;
14
15
final class DebugController implements Controller
16
{
17
    /** @var Debug */
18
    private $debug;
19
20
    /** @var OutputManager */
21
    private $manager;
22
23
    /** @var string Formatter's name to use on debug occasions */
24
    private $formatter;
25
26
    public function __construct(OutputManager $manager, Debug $debug, string $formatter = 'pretty')
27
    {
28
        $this->debug = $debug;
29
        $this->manager = $manager;
30
        $this->formatter = $formatter;
31
    }
32
33
    /** {@inheritDoc} */
34
    public function configure(Command $command)
35
    {
36
        $command
37
            ->addOption('behapi-debug', null, InputOption::VALUE_NONE, 'Activates the debug mode for behapi');
38
    }
39
40
    /** {@inheritDoc} */
41
    public function execute(InputInterface $input, OutputInterface $output)
42
    {
43
        $this->debug->setStatus($input->getOption('behapi-debug'));
44
45
        if (true === $this->debug->getStatus()) {
46
            // disable all formatters, enable only the pretty one
47
            $this->manager->disableAllFormatters();
48
            $this->manager->enableFormatter($this->formatter);
49
        }
50
    }
51
}
52