Passed
Pull Request — master (#30)
by Baptiste
03:36 queued 01:24
created

DebugController   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
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