Console::setOutput()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Solidifier\EventSubscribers;
4
5
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
6
use Symfony\Component\Console\Output\NullOutput;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Solidifier\Events\TraverseEnd;
9
use Solidifier\Events\ChangeFile;
10
use Solidifier\Defect;
11
12
class Console implements EventSubscriberInterface
13
{
14
    private
15
        $counter,
0 ignored issues
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
Coding Style introduced by
The visibility should be declared for property $counter.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
16
        $currentFile,
17
        $output;
18
    
19 View Code Duplication
    public static function getSubscribedEvents()
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...
20
    {
21
        return array(
22
            Defect::EVENT_NAME => array('onDefect'),
23
            TraverseEnd::EVENT_NAME => array('postMortemReport'),
24
            ChangeFile::EVENT_NAME => array('setCurrentFile'),
25
        );
26
    }
27
28
    public function __construct()
29
    {
30
        $this->output = new NullOutput();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
31
        $this->currentFile = null;
32
        $this->counter = 0;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
33
    }
34
    
35
    public function setOutput(OutputInterface $output)
36
    {
37
        $this->output = $output;
38
        
39
        return $this;
40
    }
41
    
42
    public function setCurrentFile(ChangeFile $event)
43
    {
44
        $this->currentFile = $event->getCurrentFile();
45
46
        return $this;
47
    }    
48
    
49
    public function onDefect(Defect $event)
50
    {
51
        $this->output->writeln(sprintf(
52
            "<fg=white;options=bold>%s @ l%d</fg=white;options=bold> : %s",
53
            $this->currentFile,
54
            $event->getLine(),
55
            $this->formatMessage($event->getMessage())
56
        ));
57
        
58
        $this->counter++;
59
    }
60
    
61
    private function formatMessage($message)
62
    {
63
        return strtr($message, array(
64
            'id>' => 'comment>',
65
            'type>' => 'info>',
66
            'method>' => 'info>',
67
        ));
68
    }
69
    
70
    public function postMortemReport(TraverseEnd $event)
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
71
    {
72
        $this->output->writeln(sprintf(
73
            '<comment>%d defect%s found</comment>',
74
            $this->counter,
75
            $this->counter > 0 ? 's' : ''
76
        ));    
77
    }
78
}