Passed
Pull Request — master (#43)
by Baptiste
02:06
created

CliController::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 declare(strict_types=1);
2
namespace Behapi\Debug;
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
final class CliController implements Controller
14
{
15
    /** @var Configuration */
16
    private $configuration;
17
18
    /** @var OutputManager */
19
    private $manager;
20
21
    /** @var string Formatter's name to use on debug occasions */
22
    private $formatter;
23
24
    public function __construct(OutputManager $manager, Configuration $configuration, string $formatter = 'pretty')
25
    {
26
        $this->manager = $manager;
27
        $this->formatter = $formatter;
28
        $this->configuration = $configuration;
29
    }
30
31
    /** {@inheritDoc} */
32
    public function configure(Command $command)
33
    {
34
        $command
35
            ->addOption('behapi-debug', null, InputOption::VALUE_NONE, 'Activates the debug mode for behapi');
36
    }
37
38
    /** {@inheritDoc} */
39
    public function execute(InputInterface $input, OutputInterface $output)
40
    {
41
        $this->configuration->setStatus($input->getOption('behapi-debug'));
42
43
        if (true === $this->configuration->getStatus()) {
44
            // disable all formatters, enable only the pretty one
45
            $this->manager->disableAllFormatters();
46
            $this->manager->enableFormatter($this->formatter);
47
        }
48
    }
49
}
50