1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* PMD |
5
|
|
|
* |
6
|
|
|
* PHP Version 5.2 |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2007-2010, Mayflower GmbH |
9
|
|
|
* All rights reserved. |
10
|
|
|
* |
11
|
|
|
* Redistribution and use in source and binary forms, with or without |
12
|
|
|
* modification, are permitted provided that the following conditions |
13
|
|
|
* are met: |
14
|
|
|
* |
15
|
|
|
* * Redistributions of source code must retain the above copyright |
16
|
|
|
* notice, this list of conditions and the following disclaimer. |
17
|
|
|
* |
18
|
|
|
* * Redistributions in binary form must reproduce the above copyright |
19
|
|
|
* notice, this list of conditions and the following disclaimer in |
20
|
|
|
* the documentation and/or other materials provided with the |
21
|
|
|
* distribution. |
22
|
|
|
* |
23
|
|
|
* * Neither the name of Mayflower GmbH nor the names of his |
24
|
|
|
* contributors may be used to endorse or promote products derived |
25
|
|
|
* from this software without specific prior written permission. |
26
|
|
|
* |
27
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
28
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
29
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
30
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
31
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
32
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
33
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
34
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
35
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
36
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
37
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
38
|
|
|
* POSSIBILITY OF SUCH DAMAGE. |
39
|
|
|
* |
40
|
|
|
* @category PHP_CodeBrowser |
41
|
|
|
* |
42
|
|
|
* @author Elger Thiele <[email protected]> |
43
|
|
|
* @author Michel Hartmann <[email protected]> |
44
|
|
|
* |
45
|
|
|
* @copyright 2007-2010 Mayflower GmbH |
46
|
|
|
* |
47
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
48
|
|
|
* |
49
|
|
|
* @link http://www.phpunit.de/ |
50
|
|
|
* |
51
|
|
|
* @since File available since 0.1.0 |
52
|
|
|
*/ |
53
|
|
|
|
54
|
|
|
namespace PHPCodeBrowser\Plugins; |
55
|
|
|
|
56
|
|
|
use DOMElement; |
57
|
|
|
use PHPCodeBrowser\AbstractPlugin; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* ErrorPMD |
61
|
|
|
* |
62
|
|
|
* @category PHP_CodeBrowser |
63
|
|
|
* |
64
|
|
|
* @author Elger Thiele <[email protected]> |
65
|
|
|
* @author Christopher Weckerle <[email protected]> |
66
|
|
|
* @author Michel Hartmann <[email protected]> |
67
|
|
|
* |
68
|
|
|
* @copyright 2007-2010 Mayflower GmbH |
69
|
|
|
* |
70
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
71
|
|
|
* |
72
|
|
|
* @version Release: @package_version@ |
73
|
|
|
* |
74
|
|
|
* @link http://www.phpunit.de/ |
75
|
|
|
* |
76
|
|
|
* @since Class available since 0.1.0 |
77
|
|
|
*/ |
78
|
|
|
class ErrorPMD extends AbstractPlugin |
79
|
|
|
{ |
80
|
|
|
/** |
81
|
|
|
* Name of this plugin. |
82
|
|
|
* Used to read issues from XML. |
83
|
|
|
* |
84
|
|
|
* @var string |
85
|
|
|
*/ |
86
|
|
|
protected $pluginName = 'pmd'; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Name of the attribute that holds the number of the first line |
90
|
|
|
* of the issue. |
91
|
|
|
* |
92
|
|
|
* @var string |
93
|
|
|
*/ |
94
|
|
|
protected $lineStartAttr = 'beginline'; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Name of the attribute that holds the number of the last line |
98
|
|
|
* of the issue. |
99
|
|
|
* |
100
|
|
|
* @var string |
101
|
|
|
*/ |
102
|
|
|
protected $lineEndAttr = 'endline'; |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Default string to use as source for issue. |
106
|
|
|
* |
107
|
|
|
* @var string |
108
|
|
|
*/ |
109
|
|
|
protected $source = 'PMD'; |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Get the severity of an issue. |
113
|
|
|
* Always return 'error'. |
114
|
|
|
* |
115
|
|
|
* @param DOMElement $element |
116
|
|
|
* |
117
|
|
|
* @phpcs:disable SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter |
118
|
|
|
* |
119
|
|
|
* @return string |
120
|
|
|
*/ |
121
|
|
|
protected function getSeverity(DOMElement $element): string |
122
|
|
|
{ |
123
|
|
|
return 'error'; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Get the description of an issue. |
128
|
|
|
* Use the textContent of the element. |
129
|
|
|
* |
130
|
|
|
* @param DOMElement $element |
131
|
|
|
* |
132
|
|
|
* @return string |
133
|
|
|
*/ |
134
|
|
|
protected function getDescription(DOMElement $element): string |
135
|
|
|
{ |
136
|
|
|
return \str_replace( |
137
|
|
|
' ', |
138
|
|
|
'', |
139
|
|
|
\htmlentities($element->textContent, ENT_COMPAT) |
140
|
|
|
); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|