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

CliController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 37
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 0 5 1
A execute() 0 10 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