CoveragePrinter::getSubscribedEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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