|
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, |
|
|
|
|
|
|
19
|
|
|
$reporter, |
|
20
|
|
|
$reportFilename, |
|
21
|
|
|
$currentFile; |
|
22
|
|
|
|
|
23
|
|
|
public function __construct(HTMLReporter $reporter) |
|
24
|
|
|
{ |
|
25
|
|
|
$this->defects = array(); |
|
|
|
|
|
|
26
|
|
|
$this->reporter = $reporter; |
|
|
|
|
|
|
27
|
|
|
$this->reportFilename = self::DEFAULT_REPORT_FILENAME; |
|
28
|
|
|
$this->currentFile = null; |
|
|
|
|
|
|
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() |
|
|
|
|
|
|
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()); |
|
|
|
|
|
|
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) |
|
|
|
|
|
|
75
|
|
|
{ |
|
76
|
|
|
$this->reporter |
|
77
|
|
|
->render($this->defects) |
|
78
|
|
|
->save($this->reportFilename); |
|
79
|
|
|
} |
|
80
|
|
|
} |
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.