ConsoleFormatter::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\Lifecycle\EngineEvent;
8
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
9
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
10
11
/**
12
 * Class ConsoleFormatter
13
 * @package Paraunit\Printer
14
 */
15
class ConsoleFormatter extends AbstractPrinter implements EventSubscriberInterface
16
{
17 70
    public static function getSubscribedEvents(): array
18
    {
19
        return [
20 70
            EngineEvent::BEFORE_START => 'onEngineBeforeStart',
21
        ];
22
    }
23
24 31
    public function onEngineBeforeStart()
25
    {
26 31
        $formatter = $this->getOutput()->getFormatter();
27
        $formatter->setStyle('ok', $this->createNewStyle('green'));
28 31
        $formatter->setStyle('skip', $this->createNewStyle('yellow'));
29 31
        $formatter->setStyle('warning', $this->createNewStyle('yellow'));
30 31
        $formatter->setStyle('incomplete', $this->createNewStyle('blue'));
31 31
        $formatter->setStyle('fail', $this->createNewStyle('red'));
32 31
        $formatter->setStyle('error', $this->createNewStyle('red'));
33 31
        $formatter->setStyle('abnormal', $this->createNewStyle('magenta'));
34 31
    }
35 31
36
    private function createNewStyle(string $color): OutputFormatterStyle
37
    {
38
        return new OutputFormatterStyle($color, null, ['bold']);
39 31
    }
40
}
41