Arbit - project tracking

PHPMD

Browse source code

File: / source/ PHP/ PMD/ Node/ Annotation.php

Type
text/plain text/plain
Last Author
mapi
Version
200
Line Rev. Author Source
1 128 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 128 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 mapi * @subpackage Node
42 174 mapi * @author Manuel Pichler <mapi@phpmd.org>
43 150 mapi * @copyright 2009-2010 Manuel Pichler. All rights reserved.
44 128 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 128 mapi */
48 mapi
49 mapi /**
50 194 mapi * Simple code annotation class.
51 128 mapi *
52 mapi * @category PHP
53 mapi * @package PHP_PMD
54 mapi * @subpackage Node
55 174 mapi * @author Manuel Pichler <mapi@phpmd.org>
56 150 mapi * @copyright 2009-2010 Manuel Pichler. All rights reserved.
57 128 mapi * @license http://www.opensource.org/licenses/bsd-license.php BSD License
58 mapi * @version Release: @package_version@
59 174 mapi * @link http://phpmd.org
60 128 mapi */
61 200 mapi class PHP_PMD_Node_Annotation
62 128 mapi {
63 mapi /**
64 194 mapi * Name of the suppress warnings annotation.
65 128 mapi */
66 194 mapi const SUPPRESS_ANNOTATION = 'SuppressWarnings';
67 128 mapi
68 mapi /**
69 194 mapi * The annotation name.
70 128 mapi *
71 194 mapi * @var string
72 128 mapi */
73 194 mapi private $_name = null;
74 128 mapi
75 mapi /**
76 194 mapi * The annotation value.
77 128 mapi *
78 194 mapi * @var string
79 128 mapi */
80 194 mapi private $_value = null;
81 128 mapi
82 mapi /**
83 194 mapi * Constructs a new annotation instance.
84 129 mapi *
85 194 mapi * @param string $name The annotation name.
86 mapi * @param string $value The supplied annotation value.
87 129 mapi */
88 194 mapi public function __construct($name, $value)
89 129 mapi {
90 194 mapi $this->_name = $name;
91 mapi $this->_value = trim($value, '" ');
92 129 mapi }
93 mapi
94 mapi /**
95 194 mapi * Checks if this annotation suppresses the given rule.
96 128 mapi *
97 194 mapi * @param PHP_PMD_AbstractRule $rule The rule to check.
98 128 mapi *
99 194 mapi * @return boolean
100 128 mapi */
101 194 mapi public function suppresses(PHP_PMD_AbstractRule $rule)
102 128 mapi {
103 194 mapi if ($this->_name === self::SUPPRESS_ANNOTATION) {
104 mapi return $this->_suppresses($rule);
105 mapi }
106 mapi return false;
107 128 mapi }
108 mapi
109 mapi /**
110 194 mapi * Checks if this annotation suppresses the given rule.
111 128 mapi *
112 194 mapi * @param PHP_PMD_AbstractRule $rule The rule to check.
113 mapi *
114 mapi * @return boolean
115 128 mapi */
116 194 mapi private function _suppresses(PHP_PMD_AbstractRule $rule)
117 128 mapi {
118 194 mapi if (in_array($this->_value, array('PHPMD', 'PMD'))) {
119 mapi return true;
120 198 mapi } else if (strpos($this->_value, 'PMD.' . $rule->getName()) !== false) {
121 194 mapi return true;
122 mapi }
123 198 mapi return (stripos($rule->getName(), $this->_value) !== false);
124 128 mapi }
125 198 mapi }