10
10
use TheSeer \phpDox \Generator \InterfaceStartEvent ;
11
11
use TheSeer \phpDox \Generator \TraitStartEvent ;
12
12
13
- class PHPCs extends AbstractEnricher implements ClassEnricherInterface, TraitEnricherInterface, InterfaceEnricherInterface {
13
+ class PHPCs extends CheckStyle {
14
14
15
15
private $ config ;
16
16
private $ findings = NULL ;
@@ -28,25 +28,6 @@ public function getName() {
28
28
return 'PHPCS XML ' ;
29
29
}
30
30
31
- public function enrichClass (ClassStartEvent $ event ) {
32
- $ this ->enrichUnit ($ event ->getClass ());
33
- }
34
-
35
- public function enrichInterface (InterfaceStartEvent $ event ) {
36
- $ this ->enrichUnit ($ event ->getInterface ());
37
- }
38
-
39
- public function enrichTrait (TraitStartEvent $ event ) {
40
- $ this ->enrichUnit ($ event ->getTrait ());
41
- }
42
-
43
- private function enrichUnit (AbstractUnitObject $ ctx ) {
44
- $ file = $ ctx ->getSourceFile ();
45
- if (isset ($ this ->findings [$ file ])) {
46
- $ this ->processFindings ($ ctx ->asDom (), $ this ->findings [$ file ]);
47
- }
48
- }
49
-
50
31
private function loadFindings ($ xmlFile ) {
51
32
$ this ->findings = array ();
52
33
try {
@@ -69,31 +50,18 @@ private function loadFindings($xmlFile) {
69
50
}
70
51
}
71
52
72
- private function processFindings (fDOMDocument $ dom , \DOMNodeList $ findings ) {
73
-
74
- foreach ($ findings as $ finding ) {
75
- /** @var fDOMElement $finding */
76
- $ line = $ finding ->getAttribute ('line ' );
77
- $ ref = $ dom ->queryOne (sprintf ('//phpdox:*/*[@line = %d or (@start <= %d and @end >= %d)] ' , $ line , $ line , $ line ));
78
- if (!$ ref ) {
79
- // One src file may contain multiple classes/traits/interfaces, so the
80
- // finding might not apply to the current object since findings are based on filenames
81
- // but we have individual objects - so we just ignore the finding for this context
53
+ protected function processFinding (fDOMDocument $ dom , $ ref , \DOMElement $ finding )
54
+ {
55
+ $ enrichment = $ this ->getEnrichtmentContainer ($ ref , 'checkstyle ' );
56
+ $ enrichFinding = $ dom ->createElementNS (self ::XMLNS , $ finding ->tagName );
57
+ $ enrichment ->appendChild ($ enrichFinding );
58
+ foreach ($ finding ->attributes as $ attr ) {
59
+ if ($ attr ->localName == 'severity ' ) {
82
60
continue ;
83
61
}
84
-
85
- $ enrichment = $ this ->getEnrichtmentContainer ($ ref , 'checkstyle ' );
86
- $ enrichFinding = $ dom ->createElementNS (self ::XMLNS , $ finding ->tagName );
87
- $ enrichment ->appendChild ($ enrichFinding );
88
- foreach ($ finding ->attributes as $ attr ) {
89
- if ($ attr ->localName == 'severity ' ) {
90
- continue ;
91
- }
92
- $ enrichFinding ->setAttributeNode ($ dom ->importNode ($ attr , true ));
93
- }
94
- $ enrichFinding ->setAttribute ('message ' , $ finding ->nodeValue );
62
+ $ enrichFinding ->setAttributeNode ($ dom ->importNode ($ attr , true ));
95
63
}
96
-
64
+ $ enrichFinding -> setAttribute ( ' message ' , $ finding -> nodeValue );
97
65
}
98
66
}
99
67
0 commit comments