Completed
Push — master ( b61e2e...b32211 )
by Alessandro
11s
created

ConsoleFormatter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 0
cbo 4
dl 0
loc 29
ccs 14
cts 14
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 6 1
A onEngineBeforeStart() 0 14 2
A createNewStyle() 0 4 1
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 56
    public static function getSubscribedEvents(): array
17
    {
18
        return [
19 56
            EngineEvent::BEFORE_START => 'onEngineBeforeStart',
20
        ];
21
    }
22
23 22
    public function onEngineBeforeStart()
24
    {
25 22
        $formatter = $this->getOutput()->getFormatter();
26
27 22
        if ($formatter) {
28 22
            $formatter->setStyle('ok', $this->createNewStyle('green'));
29 22
            $formatter->setStyle('skip', $this->createNewStyle('yellow'));
30 22
            $formatter->setStyle('warning', $this->createNewStyle('yellow'));
31 22
            $formatter->setStyle('incomplete', $this->createNewStyle('blue'));
32 22
            $formatter->setStyle('fail', $this->createNewStyle('red'));
33 22
            $formatter->setStyle('error', $this->createNewStyle('red'));
34 22
            $formatter->setStyle('abnormal', $this->createNewStyle('magenta'));
35
        }
36
    }
37
38 22
    private function createNewStyle(string $color): OutputFormatterStyle
39
    {
40 22
        return new OutputFormatterStyle($color, null, ['bold', 'blink']);
41
    }
42
}
43