Completed
Pull Request — master (#94)
by Alessandro
03:26
created

CoveragePrinter   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 49
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getSubscribedEvents() 0 6 1
A onEngineBeforeStart() 0 18 4
1
<?php
2
declare(strict_types=1);
3
4
namespace Paraunit\Printer;
5
6
use Paraunit\Configuration\PHPDbgBinFile;
7
use Paraunit\Lifecycle\EngineEvent;
8
use Paraunit\Proxy\XDebugProxy;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
11
12
/**
13
 * Class CoveragePrinter
14
 * @package Paraunit\Printer
15
 */
16
class CoveragePrinter implements EventSubscriberInterface
17
{
18
    /** @var  PHPDbgBinFile */
19
    private $phpdgbBin;
20
21
    /** @var  XDebugProxy */
22
    private $xdebug;
23
24
    /** @var OutputInterface */
25
    private $output;
26
27
    /**
28
     * CoveragePrinter constructor.
29
     * @param PHPDbgBinFile $phpdgbBin
30
     * @param XDebugProxy $xdebug
31
     */
32 4
    public function __construct(PHPDbgBinFile $phpdgbBin, XDebugProxy $xdebug, OutputInterface $output)
33
    {
34 4
        $this->phpdgbBin = $phpdgbBin;
35 4
        $this->xdebug = $xdebug;
36 4
        $this->output = $output;
37
    }
38
39 9
    public static function getSubscribedEvents(): array
40
    {
41
        return [
42 9
            EngineEvent::BEFORE_START => ['onEngineBeforeStart', 100],
43
        ];
44
    }
45
46 4
    public function onEngineBeforeStart()
47
    {
48 4
        $this->output->write('Coverage driver in use: ');
49
50 4
        if ($this->phpdgbBin->isAvailable()) {
51 3
            $this->output->writeln('PHPDBG');
52
53 3
            if ($this->xdebug->isLoaded()) {
54 2
                $this->output->writeln('WARNING: both drivers enabled; this may lead to memory exhaustion!');
55
56 2
                return;
57
            }
58
        }
59
60 2
        if ($this->xdebug->isLoaded()) {
61 1
            $this->output->writeln('xDebug');
62
        }
63
    }
64
}
65