ConsoleReporter   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 71
Duplicated Lines 32.39 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 4
dl 23
loc 71
ccs 0
cts 32
cp 0
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 2
A setOutput() 0 4 1
A onAfterRun() 16 27 5
A onStart() 0 4 1
A onBeforeRun() 0 4 1
A onStop() 0 4 1
A onFinish() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Liip\MonitorBundle\Helper;
4
5
use Laminas\Diagnostics\Check\CheckInterface;
6
use Laminas\Diagnostics\Result\Collection as ResultsCollection;
7
use Laminas\Diagnostics\Result\ResultInterface;
8
use Laminas\Diagnostics\Result\SkipInterface;
9
use Laminas\Diagnostics\Result\SuccessInterface;
10
use Laminas\Diagnostics\Result\WarningInterface;
11
use Laminas\Diagnostics\Runner\Reporter\ReporterInterface;
12
use Symfony\Component\Console\Output\ConsoleOutput;
13
use Symfony\Component\Console\Output\OutputInterface;
14
15
/**
16
 * @author Kevin Bond <[email protected]>
17
 */
18
class ConsoleReporter implements ReporterInterface
19
{
20
    /**
21
     * @var OutputInterface
22
     */
23
    protected $output;
24
25
    /**
26
     * @param OutputInterface $output
27
     */
28 View Code Duplication
    public function __construct(OutputInterface $output = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
    {
30
        if (null === $output) {
31
            $output = new ConsoleOutput();
32
        }
33
        $this->output = $output;
34
    }
35
36
    public function setOutput(OutputInterface $output)
37
    {
38
        $this->output = $output;
39
    }
40
41
    public function onAfterRun(CheckInterface $check, ResultInterface $result, $checkAlias = null)
42
    {
43 View Code Duplication
        switch (true) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
            case $result instanceof SuccessInterface:
45
                $this->output->write('<info>OK</info>');
46
                break;
47
48
            case $result instanceof WarningInterface:
49
                $this->output->write('<comment>WARNING</comment>');
50
                break;
51
52
            case $result instanceof SkipInterface:
53
                $this->output->write('<question>SKIP</question>');
54
                break;
55
56
            default:
57
                $this->output->write('<error>FAIL</error>');
58
        }
59
60
        $this->output->write(sprintf(' %s', $check->getLabel()));
61
62
        if ($message = $result->getMessage()) {
63
            $this->output->write(sprintf(': %s', $message));
64
        }
65
66
        $this->output->writeln('');
67
    }
68
69
    public function onStart(\ArrayObject $checks, $runnerConfig)
70
    {
71
        return;
72
    }
73
74
    public function onBeforeRun(CheckInterface $check, $checkAlias = null)
75
    {
76
        return;
77
    }
78
79
    public function onStop(ResultsCollection $results)
80
    {
81
        return;
82
    }
83
84
    public function onFinish(ResultsCollection $results)
85
    {
86
        return;
87
    }
88
}
89