Completed
Push — master ( d89681...8e123d )
by Andreas
20s
created

ConsoleOutputResultKeeper   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 55
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A addError() 0 5 1
A addFailure() 0 5 1
A addCreated() 0 5 1
A addUpdated() 0 5 1
A print() 0 15 2
1
<?php
2
3
/*
4
 * Copyright (c) Andreas Heigl<[email protected]
5
 *
6
 * Licensed under the MIT License. See LICENSE.md file in the project root
7
 * for full license information.
8
 */
9
10
namespace Callingallpapers\ResultKeeper;
11
12
use Symfony\Component\Console\Output\OutputInterface;
13
14
class ConsoleOutputResultKeeper extends ResultKeeper
15
{
16
    private $style;
17
18
    private $total;
19
20
    private $line;
21
22
    public function __construct(OutputInterface $style)
23
    {
24
        $this->style = $style;
25
        $this->total = 0;
26
        $this->line  = 0;
27
    }
28
29
    public function addError(Error $error) : void
30
    {
31
        parent::addError($error);
32
        $this->print('<fg=red>E</>');
33
    }
34
35
    public function addFailure(Failure $failure) : void
36
    {
37
        parent::addFailure($failure);
38
        $this->print('<fg=red>F</>');
39
    }
40
41
    public function addCreated(Created $created) : void
42
    {
43
        parent::addCreated($created);
44
        $this->print('<info>C</info>');
45
    }
46
47
    public function addUpdated(Updated $updated) : void
48
    {
49
        parent::addUpdated($updated);
50
        $this->print('<info>U</info>');
51
    }
52
53
    private function print(string $s) : void
54
    {
55
        $this->total++;
56
        $this->line++;
57
58
        $this->style->write($s);
59
60
        if ($this->line > 63) {
61
            $this->style->writeln(sprintf(
62
                '  %03d',
63
                $this->total
64
            ));
65
            $this->line = 0;
66
        }
67
    }
68
}
69