| 1 |
9
|
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 |
9
|
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 |
↓
|
mapi |
* @category PHP |
|
| 40 |
↓
|
mapi |
* @package PHP_PMD |
|
| 41 |
14
|
mapi |
* @subpackage Node |
|
| 42 |
174
|
mapi |
* @author Manuel Pichler <mapi@phpmd.org> |
|
| 43 |
150
|
mapi |
* @copyright 2009-2010 Manuel Pichler. All rights reserved. |
|
| 44 |
9
|
mapi |
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
| 45 |
↓
|
mapi |
* @version SVN: $Id$ |
|
| 46 |
174
|
mapi |
* @link http://phpmd.org |
|
| 47 |
9
|
mapi |
*/ |
|
| 48 |
↓
|
mapi |
|
|
| 49 |
200
|
mapi |
require_once 'PHP/PMD/Node/Annotation.php'; |
|
| 50 |
9
|
mapi |
|
|
| 51 |
↓
|
mapi |
/** |
|
| 52 |
194
|
mapi |
* Collection of code annotations. |
|
| 53 |
9
|
mapi |
* |
|
| 54 |
↓
|
mapi |
* @category PHP |
|
| 55 |
↓
|
mapi |
* @package PHP_PMD |
|
| 56 |
14
|
mapi |
* @subpackage Node |
|
| 57 |
174
|
mapi |
* @author Manuel Pichler <mapi@phpmd.org> |
|
| 58 |
150
|
mapi |
* @copyright 2009-2010 Manuel Pichler. All rights reserved. |
|
| 59 |
9
|
mapi |
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
| 60 |
↓
|
mapi |
* @version Release: @package_version@ |
|
| 61 |
174
|
mapi |
* @link http://phpmd.org |
|
| 62 |
9
|
mapi |
*/ |
|
| 63 |
200
|
mapi |
class PHP_PMD_Node_Annotations |
|
| 64 |
9
|
mapi |
{ |
|
| 65 |
14
|
mapi |
/** |
|
| 66 |
194
|
mapi |
* Detected annotations. |
|
| 67 |
14
|
mapi |
* |
|
| 68 |
200
|
mapi |
* @var array(PHP_PMD_Node_Annotation) |
|
| 69 |
14
|
mapi |
*/ |
|
| 70 |
194
|
mapi |
private $_annotations = array(); |
|
| 71 |
14
|
mapi |
|
|
| 72 |
↓
|
mapi |
/** |
|
| 73 |
194
|
mapi |
* Regexp used to extract code annotations. |
|
| 74 |
14
|
mapi |
* |
|
| 75 |
194
|
mapi |
* @var string |
|
| 76 |
↓
|
mapi |
*/ |
|
| 77 |
↓
|
mapi |
private $_regexp = '(@([a-z_][a-z0-9_]+)\(([^\)]+)\))i'; |
|
| 78 |
↓
|
mapi |
|
|
| 79 |
↓
|
mapi |
/** |
|
| 80 |
↓
|
mapi |
* Constructs a new collection instance. |
|
| 81 |
102
|
mapi |
* |
|
| 82 |
194
|
mapi |
* @param PHP_PMD_AbstractNode $node The context/parent node. |
|
| 83 |
102
|
mapi |
*/ |
|
| 84 |
194
|
mapi |
public function __construct(PHP_PMD_AbstractNode $node) |
|
| 85 |
102
|
mapi |
{ |
|
| 86 |
194
|
mapi |
preg_match_all($this->_regexp, $node->getDocComment(), $matches); |
|
| 87 |
↓
|
mapi |
foreach (array_keys($matches[0]) as $i) { |
|
| 88 |
↓
|
mapi |
$name = $matches[1][$i]; |
|
| 89 |
↓
|
mapi |
$value = trim($matches[2][$i], '" '); |
|
| 90 |
↓
|
mapi |
|
|
| 91 |
200
|
mapi |
$this->_annotations[] = new PHP_PMD_Node_Annotation($name, $value); |
|
| 92 |
102
|
mapi |
} |
|
| 93 |
↓
|
mapi |
} |
|
| 94 |
194
|
mapi |
|
|
| 95 |
102
|
mapi |
/** |
|
| 96 |
194
|
mapi |
* Checks if one of the annotations suppresses the given rule. |
|
| 97 |
102
|
mapi |
* |
|
| 98 |
194
|
mapi |
* @param PHP_PMD_AbstractRule $rule The rule to check. |
|
| 99 |
↓
|
mapi |
* |
|
| 100 |
↓
|
mapi |
* @return boolean |
|
| 101 |
14
|
mapi |
*/ |
|
| 102 |
194
|
mapi |
public function suppresses(PHP_PMD_AbstractRule $rule) |
|
| 103 |
14
|
mapi |
{ |
|
| 104 |
194
|
mapi |
foreach ($this->_annotations as $annotation) { |
|
| 105 |
↓
|
mapi |
if ($annotation->suppresses($rule)) { |
|
| 106 |
↓
|
mapi |
return true; |
|
| 107 |
102
|
mapi |
} |
|
| 108 |
↓
|
mapi |
} |
|
| 109 |
194
|
mapi |
return false; |
|
| 110 |
14
|
mapi |
} |
|
| 111 |
194
|
mapi |
} |
|