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

CoveragePrinter::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 2
cts 2
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 1
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