ConsoleFormatter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 4
dl 0
loc 26
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 6 1
A onEngineBeforeStart() 0 11 1
A createNewStyle() 0 4 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