| 1 |
17
|
mapi |
<?php |
|
| 2 |
↓
|
mapi |
/** |
|
| 3 |
↓
|
mapi |
* This file is part of PHP_PMD. |
|
| 4 |
↓
|
mapi |
* |
|
| 5 |
↓
|
mapi |
* PHP Version 5 |
|
| 6 |
↓
|
mapi |
* |
|
| 7 |
174
|
mapi |
* Copyright (c) 2009-2010, Manuel Pichler <mapi@phpmd.org>. |
|
| 8 |
17
|
mapi |
* All rights reserved. |
|
| 9 |
↓
|
mapi |
* |
|
| 10 |
↓
|
mapi |
* Redistribution and use in source and binary forms, with or without |
|
| 11 |
↓
|
mapi |
* modification, are permitted provided that the following conditions |
|
| 12 |
↓
|
mapi |
* are met: |
|
| 13 |
↓
|
mapi |
* |
|
| 14 |
↓
|
mapi |
* * Redistributions of source code must retain the above copyright |
|
| 15 |
↓
|
mapi |
* notice, this list of conditions and the following disclaimer. |
|
| 16 |
↓
|
mapi |
* |
|
| 17 |
↓
|
mapi |
* * Redistributions in binary form must reproduce the above copyright |
|
| 18 |
↓
|
mapi |
* notice, this list of conditions and the following disclaimer in |
|
| 19 |
↓
|
mapi |
* the documentation and/or other materials provided with the |
|
| 20 |
↓
|
mapi |
* distribution. |
|
| 21 |
↓
|
mapi |
* |
|
| 22 |
↓
|
mapi |
* * Neither the name of Manuel Pichler nor the names of his |
|
| 23 |
↓
|
mapi |
* contributors may be used to endorse or promote products derived |
|
| 24 |
↓
|
mapi |
* from this software without specific prior written permission. |
|
| 25 |
↓
|
mapi |
* |
|
| 26 |
↓
|
mapi |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
| 27 |
↓
|
mapi |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
| 28 |
↓
|
mapi |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
| 29 |
↓
|
mapi |
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
| 30 |
↓
|
mapi |
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
| 31 |
↓
|
mapi |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
| 32 |
↓
|
mapi |
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
| 33 |
↓
|
mapi |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
| 34 |
↓
|
mapi |
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
| 35 |
↓
|
mapi |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
| 36 |
↓
|
mapi |
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
| 37 |
↓
|
mapi |
* POSSIBILITY OF SUCH DAMAGE. |
|
| 38 |
↓
|
mapi |
* |
|
| 39 |
36
|
mapi |
* @category PHP |
|
| 40 |
↓
|
mapi |
* @package PHP_PMD |
|
| 41 |
174
|
mapi |
* @author Manuel Pichler <mapi@phpmd.org> |
|
| 42 |
150
|
mapi |
* @copyright 2009-2010 Manuel Pichler. All rights reserved. |
|
| 43 |
36
|
mapi |
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
| 44 |
↓
|
mapi |
* @version SVN: $Id$ |
|
| 45 |
174
|
mapi |
* @link http://phpmd.org |
|
| 46 |
17
|
mapi |
*/ |
|
| 47 |
↓
|
mapi |
|
|
| 48 |
↓
|
mapi |
/** |
|
| 49 |
36
|
mapi |
* This class is used as container for a single rule violation related to a source |
|
| 50 |
↓
|
mapi |
* node. |
|
| 51 |
17
|
mapi |
* |
|
| 52 |
36
|
mapi |
* @category PHP |
|
| 53 |
↓
|
mapi |
* @package PHP_PMD |
|
| 54 |
174
|
mapi |
* @author Manuel Pichler <mapi@phpmd.org> |
|
| 55 |
150
|
mapi |
* @copyright 2009-2010 Manuel Pichler. All rights reserved. |
|
| 56 |
36
|
mapi |
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
| 57 |
↓
|
mapi |
* @version Release: @package_version@ |
|
| 58 |
174
|
mapi |
* @link http://phpmd.org |
|
| 59 |
17
|
mapi |
*/ |
|
| 60 |
↓
|
mapi |
class PHP_PMD_RuleViolation |
|
| 61 |
↓
|
mapi |
{ |
|
| 62 |
↓
|
mapi |
/** |
|
| 63 |
↓
|
mapi |
* The rule that causes this violation. |
|
| 64 |
↓
|
mapi |
* |
|
| 65 |
98
|
mapi |
* @var PHP_PMD_AbstractRule |
|
| 66 |
17
|
mapi |
*/ |
|
| 67 |
↓
|
mapi |
private $_rule = null; |
|
| 68 |
↓
|
mapi |
|
|
| 69 |
↓
|
mapi |
/** |
|
| 70 |
↓
|
mapi |
* The context code node for this rule violation. |
|
| 71 |
↓
|
mapi |
* |
|
| 72 |
98
|
mapi |
* @var PHP_PMD_AbstractNode |
|
| 73 |
17
|
mapi |
*/ |
|
| 74 |
↓
|
mapi |
private $_node = null; |
|
| 75 |
↓
|
mapi |
|
|
| 76 |
↓
|
mapi |
/** |
|
| 77 |
↓
|
mapi |
* The description/message text that describes the violation. |
|
| 78 |
↓
|
mapi |
* |
|
| 79 |
98
|
mapi |
* @var string |
|
| 80 |
17
|
mapi |
*/ |
|
| 81 |
↓
|
mapi |
private $_description = ''; |
|
| 82 |
↓
|
mapi |
|
|
| 83 |
↓
|
mapi |
/** |
|
| 84 |
98
|
mapi |
* Name of the owning/context class or interface of this violation. |
|
| 85 |
17
|
mapi |
* |
|
| 86 |
98
|
mapi |
* @var string |
|
| 87 |
17
|
mapi |
*/ |
|
| 88 |
98
|
mapi |
private $_className = null; |
|
| 89 |
↓
|
mapi |
|
|
| 90 |
↓
|
mapi |
/** |
|
| 91 |
↓
|
mapi |
* The name of a method or <b>null</b> when this violation has no method |
|
| 92 |
↓
|
mapi |
* context. |
|
| 93 |
↓
|
mapi |
* |
|
| 94 |
↓
|
mapi |
* @var string |
|
| 95 |
↓
|
mapi |
*/ |
|
| 96 |
196
|
mapi |
private $_CodeMethodName = null; |
|
| 97 |
17
|
mapi |
|
|
| 98 |
↓
|
mapi |
/** |
|
| 99 |
↓
|
mapi |
* The name of a function or <b>null</b> when this violation has no function |
|
| 100 |
↓
|
mapi |
* context. |
|
| 101 |
↓
|
mapi |
* |
|
| 102 |
98
|
mapi |
* @var string |
|
| 103 |
17
|
mapi |
*/ |
|
| 104 |
↓
|
mapi |
private $_functionName = null; |
|
| 105 |
↓
|
mapi |
|
|
| 106 |
36
|
mapi |
/** |
|
| 107 |
↓
|
mapi |
* Constructs a new rule violation instance. |
|
| 108 |
↓
|
mapi |
* |
|
| 109 |
↓
|
mapi |
* @param PHP_PMD_AbstractRule $rule PHP_PMD rule for violation. |
|
| 110 |
↓
|
mapi |
* @param PHP_PMD_AbstractNode $node The source node of evil. |
|
| 111 |
↓
|
mapi |
* @param string $violationMessage The error/report message. |
|
| 112 |
↓
|
mapi |
*/ |
|
| 113 |
75
|
mapi |
public function __construct( |
|
| 114 |
↓
|
mapi |
PHP_PMD_AbstractRule $rule, |
|
| 115 |
↓
|
mapi |
PHP_PMD_AbstractNode $node, |
|
| 116 |
↓
|
mapi |
$violationMessage |
|
| 117 |
↓
|
mapi |
) { |
|
| 118 |
17
|
mapi |
$this->_rule = $rule; |
|
| 119 |
↓
|
mapi |
$this->_node = $node; |
|
| 120 |
↓
|
mapi |
$this->_description = $violationMessage; |
|
| 121 |
↓
|
mapi |
|
|
| 122 |
200
|
mapi |
if ($node instanceof PHP_PMD_Node_AbstractType) { |
|
| 123 |
98
|
mapi |
$this->_className = $node->getName(); |
|
| 124 |
200
|
mapi |
} else if ($node instanceof PHP_PMD_Node_Method) { |
|
| 125 |
98
|
mapi |
$this->_className = $node->getParentName(); |
|
| 126 |
196
|
mapi |
$this->_CodeMethodName = $node->getName(); |
|
| 127 |
200
|
mapi |
} else if ($node instanceof PHP_PMD_Node_Function) { |
|
| 128 |
17
|
mapi |
$this->_functionName = $node->getName(); |
|
| 129 |
↓
|
mapi |
} |
|
| 130 |
↓
|
mapi |
} |
|
| 131 |
↓
|
mapi |
|
|
| 132 |
↓
|
mapi |
/** |
|
| 133 |
↓
|
mapi |
* Returns the rule that causes this violation. |
|
| 134 |
↓
|
mapi |
* |
|
| 135 |
↓
|
mapi |
* @return PHP_PMD_AbstractRule |
|
| 136 |
↓
|
mapi |
*/ |
|
| 137 |
↓
|
mapi |
public function getRule() |
|
| 138 |
↓
|
mapi |
{ |
|
| 139 |
↓
|
mapi |
return $this->_rule; |
|
| 140 |
↓
|
mapi |
} |
|
| 141 |
↓
|
mapi |
|
|
| 142 |
↓
|
mapi |
/** |
|
| 143 |
↓
|
mapi |
* Returns the description/message text that describes the violation. |
|
| 144 |
↓
|
mapi |
* |
|
| 145 |
↓
|
mapi |
* @return string |
|
| 146 |
↓
|
mapi |
*/ |
|
| 147 |
↓
|
mapi |
public function getDescription() |
|
| 148 |
↓
|
mapi |
{ |
|
| 149 |
↓
|
mapi |
return $this->_description; |
|
| 150 |
↓
|
mapi |
} |
|
| 151 |
↓
|
mapi |
|
|
| 152 |
↓
|
mapi |
/** |
|
| 153 |
↓
|
mapi |
* Returns the file name where this rule violation was detected. |
|
| 154 |
↓
|
mapi |
* |
|
| 155 |
↓
|
mapi |
* @return string |
|
| 156 |
↓
|
mapi |
*/ |
|
| 157 |
↓
|
mapi |
public function getFileName() |
|
| 158 |
↓
|
mapi |
{ |
|
| 159 |
↓
|
mapi |
return $this->_node->getFileName(); |
|
| 160 |
↓
|
mapi |
} |
|
| 161 |
↓
|
mapi |
|
|
| 162 |
↓
|
mapi |
/** |
|
| 163 |
↓
|
mapi |
* Returns the first line of the node that causes this rule violation. |
|
| 164 |
↓
|
mapi |
* |
|
| 165 |
↓
|
mapi |
* @return integer |
|
| 166 |
↓
|
mapi |
*/ |
|
| 167 |
↓
|
mapi |
public function getBeginLine() |
|
| 168 |
↓
|
mapi |
{ |
|
| 169 |
↓
|
mapi |
return $this->_node->getBeginLine(); |
|
| 170 |
↓
|
mapi |
} |
|
| 171 |
↓
|
mapi |
|
|
| 172 |
↓
|
mapi |
/** |
|
| 173 |
↓
|
mapi |
* Returns the last line of the node that causes this rule violation. |
|
| 174 |
↓
|
mapi |
* |
|
| 175 |
↓
|
mapi |
* @return integer |
|
| 176 |
↓
|
mapi |
*/ |
|
| 177 |
↓
|
mapi |
public function getEndLine() |
|
| 178 |
↓
|
mapi |
{ |
|
| 179 |
↓
|
mapi |
return $this->_node->getEndLine(); |
|
| 180 |
↓
|
mapi |
} |
|
| 181 |
↓
|
mapi |
|
|
| 182 |
↓
|
mapi |
/** |
|
| 183 |
↓
|
mapi |
* Returns the name of the package that contains this violation. |
|
| 184 |
↓
|
mapi |
* |
|
| 185 |
↓
|
mapi |
* @return string |
|
| 186 |
↓
|
mapi |
*/ |
|
| 187 |
↓
|
mapi |
public function getPackageName() |
|
| 188 |
↓
|
mapi |
{ |
|
| 189 |
↓
|
mapi |
return $this->_node->getPackageName(); |
|
| 190 |
↓
|
mapi |
} |
|
| 191 |
↓
|
mapi |
|
|
| 192 |
↓
|
mapi |
/** |
|
| 193 |
↓
|
mapi |
* Returns the name of the parent class or interface or <b>null</b> when there |
|
| 194 |
↓
|
mapi |
* is no parent class. |
|
| 195 |
↓
|
mapi |
* |
|
| 196 |
↓
|
mapi |
* @return string |
|
| 197 |
↓
|
mapi |
*/ |
|
| 198 |
↓
|
mapi |
public function getClassName() |
|
| 199 |
↓
|
mapi |
{ |
|
| 200 |
98
|
mapi |
return $this->_className; |
|
| 201 |
17
|
mapi |
} |
|
| 202 |
↓
|
mapi |
|
|
| 203 |
↓
|
mapi |
/** |
|
| 204 |
↓
|
mapi |
* Returns the name of a method or <b>null</b> when this violation has no |
|
| 205 |
↓
|
mapi |
* method context. |
|
| 206 |
↓
|
mapi |
* |
|
| 207 |
↓
|
mapi |
* @return string |
|
| 208 |
↓
|
mapi |
*/ |
|
| 209 |
↓
|
mapi |
public function getMethodName() |
|
| 210 |
↓
|
mapi |
{ |
|
| 211 |
196
|
mapi |
return $this->_CodeMethodName; |
|
| 212 |
17
|
mapi |
} |
|
| 213 |
↓
|
mapi |
|
|
| 214 |
↓
|
mapi |
/** |
|
| 215 |
↓
|
mapi |
* Returns the name of a function or <b>null</b> when this violation has no |
|
| 216 |
↓
|
mapi |
* function context. |
|
| 217 |
↓
|
mapi |
* |
|
| 218 |
↓
|
mapi |
* @return string |
|
| 219 |
↓
|
mapi |
*/ |
|
| 220 |
↓
|
mapi |
public function getFunctionName() |
|
| 221 |
↓
|
mapi |
{ |
|
| 222 |
↓
|
mapi |
return $this->_functionName; |
|
| 223 |
↓
|
mapi |
} |
|
| 224 |
75
|
mapi |
} |
|