HTML::getSubscribedEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace Solidifier\EventSubscribers;
4
5
6
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
7
use Solidifier\Events\TraverseEnd;
8
use Solidifier\Events\ChangeFile;
9
use Solidifier\Defect;
10
use Solidifier\Reporters\HTMLReporter;
11
12
class HTML implements EventSubscriberInterface
13
{
14
    const
15
        DEFAULT_REPORT_FILENAME = 'report.html';
16
    
17
    private
18
        $defects,
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 $defects.

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...
19
        $reporter,
20
        $reportFilename,
21
        $currentFile;
22
    
23
    public function __construct(HTMLReporter $reporter)
24
    {
25
        $this->defects = array();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 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...
26
        $this->reporter = $reporter;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 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...
27
        $this->reportFilename = self::DEFAULT_REPORT_FILENAME;
28
        $this->currentFile = null;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 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...
29
    }
30
    
31
    public function setReportFilename($filename)
32
    {
33
        $this->reportFilename = $filename;
34
        
35
        return $this;
36
    }
37
    
38 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...
39
    {
40
        return array(
41
            Defect::EVENT_NAME => array('onDefect'),
42
            TraverseEnd::EVENT_NAME => array('postMortemReport'),
43
            ChangeFile::EVENT_NAME => array('setCurrentFile'),
44
        );
45
    }
46
    
47
    public function setCurrentFile(ChangeFile $event)
48
    {
49
        $this->currentFile = $event->getCurrentFile();
50
51
        return $this;
52
    }    
53
    
54
    public function onDefect(Defect $event)
55
    {
56
        if(! isset($this->defects[$this->currentFile]))
57
        {
58
            $this->defects[$this->currentFile] = array();
59
        }
60
        
61
        $event->formattedMessage = $this->formatMessage($event->getMessage());
0 ignored issues
show
Bug introduced by
The property formattedMessage does not seem to exist in Solidifier\Defect.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 13 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...
62
        $this->defects[$this->currentFile][] = $event;
63
    }
64
    
65
    private function formatMessage($message)
66
    {
67
        return strtr($message, array(
68
            'id>' => 'strong>',
69
            'type>' => 'strong>',
70
            'method>' => 'strong>',
71
        ));
72
    }
73
    
74
    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...
75
    {
76
        $this->reporter
77
            ->render($this->defects)
78
            ->save($this->reportFilename);
79
    }
80
}