Completed
Pull Request — master (#94)
by Alessandro
05:58
created

ConsoleFormatter::onEngineBeforeStart()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 10
cts 10
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 0
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Paraunit\Printer;
5
6
use Paraunit\Lifecycle\EngineEvent;
7
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
8
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9
10
/**
11
 * Class ConsoleFormatter
12
 * @package Paraunit\Printer
13
 */
14
class ConsoleFormatter extends AbstractPrinter implements EventSubscriberInterface
15
{
16 55
    public static function getSubscribedEvents(): array
17
    {
18
        return [
19 55
            EngineEvent::BEFORE_START => 'onEngineBeforeStart',
20
        ];
21
    }
22
23 21
    public function onEngineBeforeStart()
24
    {
25 21
        $formatter = $this->getOutput()->getFormatter();
26
27 21
        if ($formatter) {
28 21
            $formatter->setStyle('ok', $this->createNewStyle('green'));
29 21
            $formatter->setStyle('skip', $this->createNewStyle('yellow'));
30 21
            $formatter->setStyle('warning', $this->createNewStyle('yellow'));
31 21
            $formatter->setStyle('incomplete', $this->createNewStyle('blue'));
32 21
            $formatter->setStyle('fail', $this->createNewStyle('red'));
33 21
            $formatter->setStyle('error', $this->createNewStyle('red'));
34 21
            $formatter->setStyle('abnormal', $this->createNewStyle('magenta'));
35
        }
36
    }
37
38 21
    private function createNewStyle(string $color): OutputFormatterStyle
39
    {
40 21
        return new OutputFormatterStyle($color, null, ['bold', 'blink']);
41
    }
42
}
43