Arbit - project tracking

PHPMD

History

Diff

199 200 /test/PHP/PMD/ParserTest.php
76 76 public function testAdapterDelegatesClassNodeToRuleSet()
77 77 {
78 78 $adapter = new PHP_PMD_Parser($this->_getPHPDependMock());
79 - $adapter->addRuleSet($this->getRuleSetMock('PHP_PMD_Node_CodeClass'));
79 + $adapter->addRuleSet($this->getRuleSetMock('PHP_PMD_Node_Class'));
80 80 $adapter->setReport($this->getReportMock(0));
81 81 $adapter->visitClass($this->getPHPDependClassMock());
82 82 }
109 109 public function testAdapterDelegatesMethodNodeToRuleSet()
110 110 {
111 111 $adapter = new PHP_PMD_Parser($this->_getPHPDependMock());
112 - $adapter->addRuleSet($this->getRuleSetMock('PHP_PMD_Node_CodeMethod'));
112 + $adapter->addRuleSet($this->getRuleSetMock('PHP_PMD_Node_Method'));
113 113 $adapter->setReport($this->getReportMock(0));
114 114 $adapter->visitMethod($this->getPHPDependMethodMock());
115 115 }
142 142 public function testAdapterDelegatesFunctionNodeToRuleSet()
143 143 {
144 144 $adapter = new PHP_PMD_Parser($this->_getPHPDependMock());
145 - $adapter->addRuleSet($this->getRuleSetMock('PHP_PMD_Node_CodeFunction'));
145 + $adapter->addRuleSet($this->getRuleSetMock('PHP_PMD_Node_Function'));
146 146 $adapter->setReport($this->getReportMock(0));
147 147 $adapter->visitFunction($this->getPHPDependFunctionMock());
148 148 }
199 200 /test/PHP/PMD/Node/CodeMethodTest.php
2 -<?php
3 -/**
4 - * This file is part of PHP_PMD.
5 - *
6 - * PHP Version 5
7 - *
8 - * Copyright (c) 2009-2010, Manuel Pichler <mapi@phpmd.org>.
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 Manuel Pichler 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
41 - * @package PHP_PMD
42 - * @subpackage Node
43 - * @author Manuel Pichler <mapi@phpmd.org>
44 - * @copyright 2009-2010 Manuel Pichler. All rights reserved.
45 - * @license http://www.opensource.org/licenses/bsd-license.php BSD License
46 - * @version SVN: $Id$
47 - * @link http://phpmd.org
48 - */
49 -
50 -require_once dirname(__FILE__) . '/../AbstractTest.php';
51 -
52 -require_once 'PHP/PMD/Node/CodeMethod.php';
53 -require_once 'PHP/Depend/Code/Method.php';
54 -
55 -/**
56 - * Test case for the method node implementation.
57 - *
58 - * @category PHP
59 - * @package PHP_PMD
60 - * @subpackage Node
61 - * @author Manuel Pichler <mapi@phpmd.org>
62 - * @copyright 2009-2010 Manuel Pichler. All rights reserved.
63 - * @license http://www.opensource.org/licenses/bsd-license.php BSD License
64 - * @version Release: @package_version@
65 - * @link http://phpmd.org
66 - */
67 -class PHP_PMD_Node_CodeMethodTest extends PHP_PMD_AbstractTest
68 -{
69 - /**
70 - * testMagicCallDelegatesToWrappedPHPDependMethod
71 - *
72 - * @return void
73 - * @covers PHP_PMD_Node_AbstractCodeCallable::__call
74 - * @group phpmd
75 - * @group phpmd::node
76 - * @group unittest
77 - */
78 - public function testMagicCallDelegatesToWrappedPHPDependMethod()
79 - {
80 - $method = $this->getMock('PHP_Depend_Code_Method', array(), array(null));
81 - $method->expects($this->once())
82 - ->method('getStartLine');
83 -
84 - $node = new PHP_PMD_Node_CodeMethod($method);
85 - $node->getStartLine();
86 - }
87 -
88 - /**
89 - * testMagicCallThrowsExceptionWhenNoMatchingMethodExists
90 - *
91 - * @return void
92 - * @covers PHP_PMD_Node_AbstractCodeCallable::__call
93 - * @group phpmd
94 - * @group phpmd::node
95 - * @group unittest
96 - * @expectedException BadMethodCallException
97 - */
98 - public function testMagicCallThrowsExceptionWhenNoMatchingMethodExists()
99 - {
100 - $node = new PHP_PMD_Node_CodeMethod(new PHP_Depend_Code_Method(null));
101 - $node->getFooBar();
102 -
103 - }
104 -}
199 200 /test/PHP/PMD/Node/CodeClassTest.php
2 -<?php
3 -/**
4 - * This file is part of PHP_PMD.
5 - *
6 - * PHP Version 5
7 - *
8 - * Copyright (c) 2009-2010, Manuel Pichler <mapi@phpmd.org>.
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 Manuel Pichler 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
41 - * @package PHP_PMD
42 - * @subpackage Node
43 - * @author Manuel Pichler <mapi@phpmd.org>
44 - * @copyright 2009-2010 Manuel Pichler. All rights reserved.
45 - * @license http://www.opensource.org/licenses/bsd-license.php BSD License
46 - * @version SVN: $Id$
47 - * @link http://phpmd.org
48 - */
49 -
50 -require_once dirname(__FILE__) . '/../AbstractTest.php';
51 -
52 -require_once 'PHP/PMD/Node/CodeClass.php';
53 -require_once 'PHP/Depend/Code/Class.php';
54 -require_once 'PHP/Depend/Code/Method.php';
55 -
56 -/**
57 - * Test case for the class node implementation.
58 - *
59 - * @category PHP
60 - * @package PHP_PMD
61 - * @subpackage Node
62 - * @author Manuel Pichler <mapi@phpmd.org>
63 - * @copyright 2009-2010 Manuel Pichler. All rights reserved.
64 - * @license http://www.opensource.org/licenses/bsd-license.php BSD License
65 - * @version Release: @package_version@
66 - * @link http://phpmd.org
67 - */
68 -class PHP_PMD_Node_CodeClassTest extends PHP_PMD_AbstractTest
69 -{
70 - /**
71 - * testGetMethodNamesReturnsExpectedResult
72 - *
73 - * @return void
74 - * @covers PHP_PMD_Node_CodeClass
75 - * @covers PHP_PMD_Node_AbstractCodeType
76 - * @group phpmd
77 - * @group phpmd::node
78 - * @group unittest
79 - */
80 - public function testGetMethodNamesReturnsExpectedResult()
81 - {
82 - $class = new PHP_Depend_Code_Class(null);
83 - $class->addMethod(new PHP_Depend_Code_Method(__CLASS__));
84 - $class->addMethod(new PHP_Depend_Code_Method(__FUNCTION__));
85 -
86 - $node = new PHP_PMD_Node_CodeClass($class);
87 - $this->assertEquals(array(__CLASS__, __FUNCTION__), $node->getMethodNames());
88 - }
89 -}
199 200 /test/PHP/PMD/Node/CodeFunctionTest.php
2 -<?php
3 -/**
4 - * This file is part of PHP_PMD.
5 - *
6 - * PHP Version 5
7 - *
8 - * Copyright (c) 2009-2010, Manuel Pichler <mapi@phpmd.org>.
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 Manuel Pichler 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
41 - * @package PHP_PMD
42 - * @subpackage Node
43 - * @author Manuel Pichler <mapi@phpmd.org>
44 - * @copyright 2009-2010 Manuel Pichler. All rights reserved.
45 - * @license http://www.opensource.org/licenses/bsd-license.php BSD License
46 - * @version SVN: $Id$
47 - * @link http://phpmd.org
48 - */
49 -
50 -require_once dirname(__FILE__) . '/../AbstractTest.php';
51 -
52 -require_once 'PHP/PMD/Node/CodeFunction.php';
53 -require_once 'PHP/Depend/Code/Function.php';
54 -
55 -/**
56 - * Test case for the function node implementation.
57 - *
58 - * @category PHP
59 - * @package PHP_PMD
60 - * @subpackage Node
61 - * @author Manuel Pichler <mapi@phpmd.org>
62 - * @copyright 2009-2010 Manuel Pichler. All rights reserved.
63 - * @license http://www.opensource.org/licenses/bsd-license.php BSD License
64 - * @version Release: @package_version@
65 - * @link http://phpmd.org
66 - */
67 -class PHP_PMD_Node_CodeFunctionTest extends PHP_PMD_AbstractTest
68 -{
69 - /**
70 - * testMagicCallDelegatesToWrappedPHPDependFunction
71 - *
72 - * @return void
73 - * @covers PHP_PMD_Node_AbstractCodeCallable::__call
74 - * @group phpmd
75 - * @group phpmd::node
76 - * @group unittest
77 - */
78 - public function testMagicCallDelegatesToWrappedPHPDependFunction()
79 - {
80 - $function = $this->getMock('PHP_Depend_Code_Function', array(), array(null));
81 - $function->expects($this->once())
82 - ->method('getStartLine');
83 -
84 - $node = new PHP_PMD_Node_CodeFunction($function);
85 - $node->getStartLine();
86 - }
87 -
88 - /**
89 - * testMagicCallThrowsExceptionWhenNoMatchingMethodExists
90 - *
91 - * @return void
92 - * @covers PHP_PMD_Node_AbstractCodeCallable::__call
93 - * @group phpmd
94 - * @group phpmd::node
95 - * @group unittest
96 - * @expectedException BadMethodCallException
97 - */
98 - public function testMagicCallThrowsExceptionWhenNoMatchingMethodExists()
99 - {
100 - $node = new PHP_PMD_Node_CodeFunction(new PHP_Depend_Code_Function(null));
101 - $node->getFooBar();
102 -
103 - }
104 -}
199 200 /test/PHP/PMD/Node/AnnotationTest.php
2 +<?php
3 +/**
4 + * This file is part of PHP_PMD.
5 + *
6 + * PHP Version 5
7 + *
8 + * Copyright (c) 2009-2010, Manuel Pichler <mapi@phpmd.org>.
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 Manuel Pichler 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
41 + * @package PHP_PMD
42 + * @subpackage Node
43 + * @author Manuel Pichler <mapi@phpmd.org>
44 + * @copyright 2009-2010 Manuel Pichler. All rights reserved.
45 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
46 + * @version SVN: $Id$
47 + * @link http://phpmd.org
48 + */
49 +
50 +require_once dirname(__FILE__) . '/../AbstractTest.php';
51 +
52 +require_once 'PHP/PMD/Node/Annotation.php';
53 +
54 +/**
55 + * Test case for the {@link PHP_PMD_Node_Annotation} class.
56 + *
57 + * @category PHP
58 + * @package PHP_PMD
59 + * @subpackage Node
60 + * @author Manuel Pichler <mapi@phpmd.org>
61 + * @copyright 2009-2010 Manuel Pichler. All rights reserved.
62 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
63 + * @version Release: @package_version@
64 + * @link http://phpmd.org
65 + */
66 +class PHP_PMD_Node_AnnotationTest extends PHP_PMD_AbstractTest
67 +{
68 + /**
69 + * testAnnotationReturnsFalseWhenNoSuppressWarningAnnotationExists
70 + *
71 + * @return void
72 + * @covers PHP_PMD_Node_Annotation
73 + * @group phpmd
74 + * @group phpmd::node
75 + * @group unittest
76 + */
77 + public function testAnnotationReturnsFalseWhenNoSuppressWarningAnnotationExists()
78 + {
79 + $annotation = new PHP_PMD_Node_Annotation('NoSuppressWarning', 'PMD');
80 + $this->assertFalse($annotation->suppresses($this->getRuleMock()));
81 + }
82 +
83 + /**
84 + * testAnnotationReturnsFalseWhenSuppressWarningContainsInvalidValue
85 + *
86 + * @return void
87 + * @covers PHP_PMD_Node_Annotation
88 + * @group phpmd
89 + * @group phpmd::node
90 + * @group unittest
91 + */
92 + public function testAnnotationReturnsFalseWhenSuppressWarningContainsInvalidValue()
93 + {
94 + $annotation = new PHP_PMD_Node_Annotation('SuppressWarnings', 'PHP');
95 + $this->assertFalse($annotation->suppresses($this->getRuleMock()));
96 + }
97 +
98 + /**
99 + * testAnnotationReturnsTrueWhenSuppressWarningContainsWithPMD
100 + *
101 + * @return void
102 + * @covers PHP_PMD_Node_Annotation
103 + * @group phpmd
104 + * @group phpmd::node
105 + * @group unittest
106 + */
107 + public function testAnnotationReturnsTrueWhenSuppressWarningContainsWithPMD()
108 + {
109 + $annotation = new PHP_PMD_Node_Annotation('SuppressWarnings', 'PMD');
110 + $this->assertTrue($annotation->suppresses($this->getRuleMock()));
111 + }
112 +
113 + /**
114 + * testAnnotationReturnsTrueWhenSuppressWarningContainsWithPHPMD
115 + *
116 + * @return void
117 + * @covers PHP_PMD_Node_Annotation
118 + * @group phpmd
119 + * @group phpmd::node
120 + * @group unittest
121 + */
122 + public function testAnnotationReturnsTrueWhenSuppressWarningContainsWithPHPMD()
123 + {
124 + $annotation = new PHP_PMD_Node_Annotation('SuppressWarnings', 'PHPMD');
125 + $this->assertTrue($annotation->suppresses($this->getRuleMock()));
126 + }
127 +
128 + /**
129 + * testAnnotationReturnsTrueWhenSuppressWarningContainsPMDPlusRuleName
130 + *
131 + * @return void
132 + * @covers PHP_PMD_Node_Annotation
133 + * @group phpmd
134 + * @group phpmd::node
135 + * @group unittest
136 + */
137 + public function testAnnotationReturnsTrueWhenSuppressWarningContainsPMDPlusRuleName()
138 + {
139 + $rule = $this->getRuleMock();
140 + $rule->setName('UnusedCodeRule');
141 +
142 + $annotation = new PHP_PMD_Node_Annotation('SuppressWarnings', 'PMD.UnusedCodeRule');
143 + $this->assertTrue($annotation->suppresses($rule));
144 + }
145 +
146 + /**
147 + * testAnnotationReturnsTrueWhenSuppressWarningContainsPHPMDPlusRuleName
148 + *
149 + * @return void
150 + * @covers PHP_PMD_Node_Annotation
151 + * @group phpmd
152 + * @group phpmd::node
153 + * @group unittest
154 + */
155 + public function testAnnotationReturnsTrueWhenSuppressWarningContainsPHPMDPlusRuleName()
156 + {
157 + $rule = $this->getRuleMock();
158 + $rule->setName('UnusedCodeRule');
159 +
160 + $annotation = new PHP_PMD_Node_Annotation('SuppressWarnings', 'PHPMD.UnusedCodeRule');
161 + $this->assertTrue($annotation->suppresses($rule));
162 + }
163 +
164 + /**
165 + * testAnnotationReturnsTrueWhenSuppressWarningContainsPartialRuleName
166 + *
167 + * @return void
168 + * @covers PHP_PMD_Node_Annotation
169 + * @group phpmd
170 + * @group phpmd::node
171 + * @group unittest
172 + */
173 + public function testAnnotationReturnsTrueWhenSuppressWarningContainsPartialRuleName()
174 + {
175 + $rule = $this->getRuleMock();
176 + $rule->setName('UnusedCodeRule');
177 +
178 + $annotation = new PHP_PMD_Node_Annotation('SuppressWarnings', 'unused');
179 + $this->assertTrue($annotation->suppresses($rule));
180 + }
181 +}
199 200 /test/PHP/PMD/Node/AllTests.php
50 50 require_once 'PHPUnit/Framework.php';
51 51
52 52 require_once dirname(__FILE__) . '/ASTNodeTest.php';
53 -require_once dirname(__FILE__) . '/CodeClassTest.php';
54 -require_once dirname(__FILE__) . '/CodeFunctionTest.php';
55 -require_once dirname(__FILE__) . '/CodeMethodTest.php';
53 +require_once dirname(__FILE__) . '/AnnotationTest.php';
54 +require_once dirname(__FILE__) . '/AnnotationsTest.php';
55 +require_once dirname(__FILE__) . '/ClassTest.php';
56 +require_once dirname(__FILE__) . '/FunctionTest.php';
57 +require_once dirname(__FILE__) . '/MethodTest.php';
56 58
57 59 /**
58 60 * Main test suite for the PHP_PMD_Node package.
78 80 $suite = new PHPUnit_Framework_TestSuite('PHP_PMD_Node - Tests');
79 81
80 82 $suite->addTestSuite('PHP_PMD_Node_ASTNodeTest');
81 - $suite->addTestSuite('PHP_PMD_Node_CodeClassTest');
82 - $suite->addTestSuite('PHP_PMD_Node_CodeFunctionTest');
83 - $suite->addTestSuite('PHP_PMD_Node_CodeMethodTest');
83 + $suite->addTestSuite('PHP_PMD_Node_AnnotationTest');
84 + $suite->addTestSuite('PHP_PMD_Node_AnnotationsTest');
85 + $suite->addTestSuite('PHP_PMD_Node_ClassTest');
86 + $suite->addTestSuite('PHP_PMD_Node_FunctionTest');
87 + $suite->addTestSuite('PHP_PMD_Node_MethodTest');
84 88
85 89 return $suite;
86 90 }
199 200 /test/PHP/PMD/Node/AnnotationsTest.php
2 +<?php
3 +/**
4 + * This file is part of PHP_PMD.
5 + *
6 + * PHP Version 5
7 + *
8 + * Copyright (c) 2009-2010, Manuel Pichler <mapi@phpmd.org>.
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 Manuel Pichler 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
41 + * @package PHP_PMD
42 + * @subpackage Node
43 + * @author Manuel Pichler <mapi@phpmd.org>
44 + * @copyright 2009-2010 Manuel Pichler. All rights reserved.
45 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
46 + * @version SVN: $Id$
47 + * @link http://phpmd.org
48 + */
49 +
50 +require_once dirname(__FILE__) . '/../AbstractTest.php';
51 +
52 +require_once 'PHP/PMD/Node/Annotations.php';
53 +
54 +/**
55 + * Test case for the {@link PHP_PMD_Node_Annotations} class.
56 + *
57 + * @category PHP
58 + * @package PHP_PMD
59 + * @subpackage Node
60 + * @author Manuel Pichler <mapi@phpmd.org>
61 + * @copyright 2009-2010 Manuel Pichler. All rights reserved.
62 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
63 + * @version Release: @package_version@
64 + * @link http://phpmd.org
65 + */
66 +class PHP_PMD_Node_AnnotationsTest extends PHP_PMD_AbstractTest
67 +{
68 + /**
69 + * testCollectionReturnsFalseWhenNoAnnotationExists
70 + *
71 + * @return void
72 + * @covers PHP_PMD_Node_Annotations
73 + * @group phpmd
74 + * @group phpmd::node
75 + * @group unittest
76 + */
77 + public function testCollectionReturnsFalseWhenNoAnnotationExists()
78 + {
79 + $annotations = new PHP_PMD_Node_Annotations($this->getClassMock());
80 + $this->assertFalse($annotations->suppresses($this->getRuleMock()));
81 + }
82 +
83 + /**
84 + * testCollectionReturnsFalseWhenNoMatchingAnnotationExists
85 + *
86 + * @return void
87 + * @covers PHP_PMD_Node_Annotations
88 + * @group phpmd
89 + * @group phpmd::node
90 + * @group unittest
91 + */
92 + public function testCollectionReturnsFalseWhenNoMatchingAnnotationExists()
93 + {
94 + $class = $this->getClassMock();
95 + $class->expects($this->once())
96 + ->method('__call')
97 + ->with($this->equalTo('getDocComment'))
98 + ->will(
99 + $this->returnValue(
100 + '/**
101 + * @SuppressWarnings("Foo")
102 + * @SuppressWarnings("Bar")
103 + * @SuppressWarnings("Baz")
104 + */'
105 + )
106 + );
107 +
108 + $annotations = new PHP_PMD_Node_Annotations($class);
109 + $this->assertFalse($annotations->suppresses($this->getRuleMock()));
110 + }
111 +
112 + /**
113 + * testCollectionReturnsTrueWhenMatchingAnnotationExists
114 + *
115 + * @return void
116 + * @covers PHP_PMD_Node_Annotations
117 + * @group phpmd
118 + * @group phpmd::node
119 + * @group unittest
120 + */
121 + public function testCollectionReturnsTrueWhenMatchingAnnotationExists()
122 + {
123 + $class = $this->getClassMock();
124 + $class->expects($this->once())
125 + ->method('__call')
126 + ->with($this->equalTo('getDocComment'))
127 + ->will($this->returnValue('/** @SuppressWarnings("PMD") */'));
128 +
129 + $annotations = new PHP_PMD_Node_Annotations($class);
130 + $this->assertTrue($annotations->suppresses($this->getRuleMock()));
131 + }
132 +
133 + /**
134 + * testCollectionReturnsTrueWhenOneMatchingAnnotationExists
135 + *
136 + * @return void
137 + * @covers PHP_PMD_Node_Annotations
138 + * @group phpmd
139 + * @group phpmd::node
140 + * @group unittest
141 + */
142 + public function testCollectionReturnsTrueWhenOneMatchingAnnotationExists()
143 + {
144 + $class = $this->getClassMock();
145 + $class->expects($this->once())
146 + ->method('__call')
147 + ->with($this->equalTo('getDocComment'))
148 + ->will(
149 + $this->returnValue(
150 + '/**
151 + * @SuppressWarnings("FooBar")
152 + * @SuppressWarnings("PMD")
153 + */'
154 + )
155 + );
156 +
157 + $annotations = new PHP_PMD_Node_Annotations($class);
158 + $this->assertTrue($annotations->suppresses($this->getRuleMock()));
159 + }
160 +}
199 200 /test/PHP/PMD/Node/MethodTest.php
2 +<?php
3 +/**
4 + * This file is part of PHP_PMD.
5 + *
6 + * PHP Version 5
7 + *
8 + * Copyright (c) 2009-2010, Manuel Pichler <mapi@phpmd.org>.
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 Manuel Pichler 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
41 + * @package PHP_PMD
42 + * @subpackage Node
43 + * @author Manuel Pichler <mapi@phpmd.org>
44 + * @copyright 2009-2010 Manuel Pichler. All rights reserved.
45 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
46 + * @version SVN: $Id$
47 + * @link http://phpmd.org
48 + */
49 +
50 +require_once dirname(__FILE__) . '/../AbstractTest.php';
51 +
52 +require_once 'PHP/PMD/Node/Method.php';
53 +require_once 'PHP/Depend/Code/Method.php';
54 +
55 +/**
56 + * Test case for the method node implementation.
57 + *
58 + * @category PHP
59 + * @package PHP_PMD
60 + * @subpackage Node
61 + * @author Manuel Pichler <mapi@phpmd.org>
62 + * @copyright 2009-2010 Manuel Pichler. All rights reserved.
63 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
64 + * @version Release: @package_version@
65 + * @link http://phpmd.org
66 + */
67 +class PHP_PMD_Node_MethodTest extends PHP_PMD_AbstractTest
68 +{
69 + /**
70 + * testMagicCallDelegatesToWrappedPHPDependMethod
71 + *
72 + * @return void
73 + * @covers PHP_PMD_Node_AbstractCallable::__call
74 + * @group phpmd
75 + * @group phpmd::node
76 + * @group unittest
77 + */
78 + public function testMagicCallDelegatesToWrappedPHPDependMethod()
79 + {
80 + $method = $this->getMock('PHP_Depend_Code_Method', array(), array(null));
81 + $method->expects($this->once())
82 + ->method('getStartLine');
83 +
84 + $node = new PHP_PMD_Node_Method($method);
85 + $node->getStartLine();
86 + }
87 +
88 + /**
89 + * testMagicCallThrowsExceptionWhenNoMatchingMethodExists
90 + *
91 + * @return void
92 + * @covers PHP_PMD_Node_AbstractCallable::__call
93 + * @group phpmd
94 + * @group phpmd::node
95 + * @group unittest
96 + * @expectedException BadMethodCallException
97 + */
98 + public function testMagicCallThrowsExceptionWhenNoMatchingMethodExists()
99 + {
100 + $node = new PHP_PMD_Node_Method(new PHP_Depend_Code_Method(null));
101 + $node->getFooBar();
102 +
103 + }
104 +}
199 200 /test/PHP/PMD/Node/ClassTest.php
2 +<?php
3 +/**
4 + * This file is part of PHP_PMD.
5 + *
6 + * PHP Version 5
7 + *
8 + * Copyright (c) 2009-2010, Manuel Pichler <mapi@phpmd.org>.
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 Manuel Pichler 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
41 + * @package PHP_PMD
42 + * @subpackage Node
43 + * @author Manuel Pichler <mapi@phpmd.org>
44 + * @copyright 2009-2010 Manuel Pichler. All rights reserved.
45 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
46 + * @version SVN: $Id$
47 + * @link http://phpmd.org
48 + */
49 +
50 +require_once dirname(__FILE__) . '/../AbstractTest.php';
51 +
52 +require_once 'PHP/PMD/AbstractRule.php';
53 +require_once 'PHP/PMD/Node/Class.php';
54 +require_once 'PHP/Depend/Code/Class.php';
55 +require_once 'PHP/Depend/Code/Method.php';
56 +
57 +/**
58 + * Test case for the class node implementation.
59 + *
60 + * @category PHP
61 + * @package PHP_PMD
62 + * @subpackage Node
63 + * @author Manuel Pichler <mapi@phpmd.org>
64 + * @copyright 2009-2010 Manuel Pichler. All rights reserved.
65 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
66 + * @version Release: @package_version@
67 + * @link http://phpmd.org
68 + */
69 +class PHP_PMD_Node_ClassTest extends PHP_PMD_AbstractTest
70 +{
71 + /**
72 + * testGetMethodNamesReturnsExpectedResult
73 + *
74 + * @return void
75 + * @covers PHP_PMD_Node_Class
76 + * @covers PHP_PMD_Node_AbstractType
77 + * @group phpmd
78 + * @group phpmd::node
79 + * @group unittest
80 + */
81 + public function testGetMethodNamesReturnsExpectedResult()
82 + {
83 + $class = new PHP_Depend_Code_Class(null);
84 + $class->addMethod(new PHP_Depend_Code_Method(__CLASS__));
85 + $class->addMethod(new PHP_Depend_Code_Method(__FUNCTION__));
86 +
87 + $node = new PHP_PMD_Node_Class($class);
88 + $this->assertEquals(array(__CLASS__, __FUNCTION__), $node->getMethodNames());
89 + }
90 +
91 + /**
92 + * testHasSuppressWarningsAnnotationForReturnsTrue
93 + *
94 + * @return void
95 + * @covers PHP_PMD_Node_AbstractNode
96 + * @group phpmd
97 + * @group phpmd::node
98 + * @group unittest
99 + */
100 + public function testHasSuppressWarningsAnnotationForReturnsTrue()
101 + {
102 + $class = new PHP_Depend_Code_Class(null);
103 + $class->setDocComment('/** @SuppressWarnings("PMD") */');
104 +
105 + $rule = $this->getMock('PHP_PMD_AbstractRule');
106 +
107 + $node = new PHP_PMD_Node_Class($class);
108 +
109 + $this->assertTrue($node->hasSuppressWarningsAnnotationFor($rule));
110 + }
111 +}
199 200 /test/PHP/PMD/Node/FunctionTest.php
2 +<?php
3 +/**
4 + * This file is part of PHP_PMD.
5 + *
6 + * PHP Version 5
7 + *
8 + * Copyright (c) 2009-2010, Manuel Pichler <mapi@phpmd.org>.
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 Manuel Pichler 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
41 + * @package PHP_PMD
42 + * @subpackage Node
43 + * @author Manuel Pichler <mapi@phpmd.org>
44 + * @copyright 2009-2010 Manuel Pichler. All rights reserved.
45 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
46 + * @version SVN: $Id$
47 + * @link http://phpmd.org
48 + */
49 +
50 +require_once dirname(__FILE__) . '/../AbstractTest.php';
51 +
52 +require_once 'PHP/PMD/Node/Function.php';
53 +require_once 'PHP/Depend/Code/Function.php';
54 +
55 +/**
56 + * Test case for the function node implementation.
57 + *
58 + * @category PHP
59 + * @package PHP_PMD
60 + * @subpackage Node
61 + * @author Manuel Pichler <mapi@phpmd.org>
62 + * @copyright 2009-2010 Manuel Pichler. All rights reserved.
63 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
64 + * @version Release: @package_version@
65 + * @link http://phpmd.org
66 + */
67 +class PHP_PMD_Node_FunctionTest extends PHP_PMD_AbstractTest
68 +{
69 + /**
70 + * testMagicCallDelegatesToWrappedPHPDependFunction
71 + *
72 + * @return void
73 + * @covers PHP_PMD_Node_AbstractCallable::__call
74 + * @group phpmd
75 + * @group phpmd::node
76 + * @group unittest
77 + */
78 + public function testMagicCallDelegatesToWrappedPHPDependFunction()
79 + {
80 + $function = $this->getMock('PHP_Depend_Code_Function', array(), array(null));
81 + $function->expects($this->once())
82 + ->method('getStartLine');
83 +
84 + $node = new PHP_PMD_Node_Function($function);
85 + $node->getStartLine();
86 + }
87 +
88 + /**
89 + * testMagicCallThrowsExceptionWhenNoMatchingMethodExists
90 + *
91 + * @return void
92 + * @covers PHP_PMD_Node_AbstractCallable::__call
93 + * @group phpmd
94 + * @group phpmd::node
95 + * @group unittest
96 + * @expectedException BadMethodCallException
97 + */
98 + public function testMagicCallThrowsExceptionWhenNoMatchingMethodExists()
99 + {
100 + $node = new PHP_PMD_Node_Function(new PHP_Depend_Code_Function(null));
101 + $node->getFooBar();
102 +
103 + }
104 +}
199 200 /test/PHP/PMD/Rule/Design/TooManyMethodsTest.php
179 179 * @param integer $numberOfMethods Number of methods metric value.
180 180 * @param array(string) $methodNames Name of all methods.
181 181 *
182 - * @return PHP_PMD_Node_CodeClass
182 + * @return PHP_PMD_Node_Class
183 183 */
184 184 private function _createClassMock($numberOfMethods, array $methodNames = null)
185 185 {
199 200 /test/PHP/PMD/Rule/Design/LongParameterListTest.php
178 178 *
179 179 * @param integer $parameterCount Number of method parameters.
180 180 *
181 - * @return PHP_PMD_Node_CodeMethod
181 + * @return PHP_PMD_Node_Method
182 182 */
183 183 private function _createMethod($parameterCount)
184 184 {
190 190 *
191 191 * @param integer $parameterCount Number of function parameters.
192 192 *
193 - * @return PHP_PMD_Node_CodeFunction
193 + * @return PHP_PMD_Node_Function
194 194 */
195 195 private function _createFunction($parameterCount)
196 196 {
200 200 /**
201 201 * Initializes the getParameterCount() method of the given callable.
202 202 *
203 - * @param PHP_PMD_Node_CodeFunction|PHP_PMD_Node_CodeMethod $mock Mocked callable.
203 + * @param PHP_PMD_Node_Function|PHP_PMD_Node_Method $mock Mocked callable.
204 204 * @param integer $parameterCount Number of parameters.
205 205 *
206 - * @return PHP_PMD_Node_CodeFunction|PHP_PMD_Node_CodeMethod
206 + * @return PHP_PMD_Node_Function|PHP_PMD_Node_Method
207 207 */
208 208 private function _initFunctionOrMethod($mock, $parameterCount)
209 209 {
199 200 /test/PHP/PMD/Rule/Design/LongMethodTest.php
70 70 * threshold.
71 71 *
72 72 * @return void
73 - * @covers PHP_PMD_Rule_UnusedLocalVariable
73 + * @covers PHP_PMD_Rule_Design_LongMethod
74 74 * @group phpmd
75 75 * @group phpmd::rule
76 76 * @group phpmd::rule::design
92 92 * threshold.
93 93 *
94 94 * @return void
95 - * @covers PHP_PMD_Rule_UnusedLocalVariable
95 + * @covers PHP_PMD_Rule_Design_LongMethod
96 96 * @group phpmd
97 97 * @group phpmd::rule
98 98 * @group phpmd::rule::design
114 114 * than the threshold.
115 115 *
116 116 * @return void
117 - * @covers PHP_PMD_Rule_UnusedLocalVariable
117 + * @covers PHP_PMD_Rule_Design_LongMethod
118 118 * @group phpmd
119 119 * @group phpmd::rule
120 120 * @group phpmd::rule::design
199 200 /test/PHP/PMD/Rule/Design/LongClassTest.php
70 70 * threshold.
71 71 *
72 72 * @return void
73 - * @covers PHP_PMD_Rule_UnusedLocalVariable
73 + * @covers PHP_PMD_Rule_Design_LongClass
74 74 * @group phpmd
75 75 * @group phpmd::rule
76 76 * @group phpmd::rule::design
92 92 * threshold.
93 93 *
94 94 * @return void
95 - * @covers PHP_PMD_Rule_UnusedLocalVariable
95 + * @covers PHP_PMD_Rule_Design_LongClass
96 96 * @group phpmd
97 97 * @group phpmd::rule
98 98 * @group phpmd::rule::design
114 114 * than the threshold.
115 115 *
116 116 * @return void
117 - * @covers PHP_PMD_Rule_UnusedLocalVariable
117 + * @covers PHP_PMD_Rule_Design_LongClass
118 118 * @group phpmd
119 119 * @group phpmd::rule
120 120 * @group phpmd::rule::design
199 200 /test/PHP/PMD/AbstractTest.php
95 95 * Returns the first class found in a source file related to the calling
96 96 * test method.
97 97 *
98 - * @return PHP_PMD_Node_CodeClass
98 + * @return PHP_PMD_Node_Class
99 99 */
100 100 protected function getClass()
101 101 {
102 - include_once 'PHP/PMD/Node/CodeClass.php';
102 + include_once 'PHP/PMD/Node/Class.php';
103 103
104 - return new PHP_PMD_Node_CodeClass(
104 + return new PHP_PMD_Node_Class(
105 105 $this->_getNodeForCallingTestCase(
106 106 $this->_parseTestCaseSource()
107 107 ->getClasses()
113 113 * Returns the first method found in a source file related to the calling
114 114 * test method.
115 115 *
116 - * @return PHP_PMD_Node_CodeMethod
116 + * @return PHP_PMD_Node_Method
117 117 */
118 118 protected function getMethod()
119 119 {
120 - include_once 'PHP/PMD/Node/CodeMethod.php';
120 + include_once 'PHP/PMD/Node/Method.php';
121 121
122 - return new PHP_PMD_Node_CodeMethod(
122 + return new PHP_PMD_Node_Method(
123 123 $this->_getNodeForCallingTestCase(
124 124 $this->_parseTestCaseSource()
125 125 ->getTypes()
133 133 * Returns the first function found in a source files related to the calling
134 134 * test method.
135 135 *
136 - * @return PHP_PMD_Node_CodeFunction
136 + * @return PHP_PMD_Node_Function
137 137 */
138 138 protected function getFunction()
139 139 {
140 - include_once 'PHP/PMD/Node/CodeFunction.php';
140 + include_once 'PHP/PMD/Node/Function.php';
141 141
142 - return new PHP_PMD_Node_CodeFunction(
142 + return new PHP_PMD_Node_Function(
143 143 $this->_getNodeForCallingTestCase(
144 144 $this->_parseTestCaseSource()
145 145 ->getFunctions()
236 236 * @param string $metric The metric acronym used by PHP_Depend.
237 237 * @param mixed $value The expected metric return value.
238 238 *
239 - * @return PHP_PMD_Node_CodeClass
239 + * @return PHP_PMD_Node_Class
240 240 */
241 241 protected function getClassMock($metric = null, $value = null)
242 242 {
243 - include_once 'PHP/PMD/Node/CodeClass.php';
243 + include_once 'PHP/PMD/Node/Class.php';
244 244
245 - $class = $this->getMock('PHP_PMD_Node_CodeClass', array(), array(null), '', false);
245 + $class = $this->getMock('PHP_PMD_Node_Class', array(), array(null), '', false);
246 246 if ($metric !== null) {
247 247 $class->expects($this->atLeastOnce())
248 248 ->method('getMetric')
258 258 * @param string $metric The metric acronym used by PHP_Depend.
259 259 * @param mixed $value The expected metric return value.
260 260 *
261 - * @return PHP_PMD_Node_CodeMethod
261 + * @return PHP_PMD_Node_Method
262 262 */
263 263 protected function getMethodMock($metric = null, $value = null)
264 264 {
265 - include_once 'PHP/PMD/Node/CodeMethod.php';
265 + include_once 'PHP/PMD/Node/Method.php';
266 266
267 267 return $this->initFunctionOrMethod(
268 - $this->getMock('PHP_PMD_Node_CodeMethod', array(), array(null), '', false),
268 + $this->getMock('PHP_PMD_Node_Method', array(), array(null), '', false),
269 269 $metric,
270 270 $value
271 271 );
277 277 * @param string $metric The metric acronym used by PHP_Depend.
278 278 * @param mixed $value The expected metric return value.
279 279 *
280 - * @return PHP_PMD_Node_CodeFunction
280 + * @return PHP_PMD_Node_Function
281 281 */
282 282 protected function createFunctionMock($metric = null, $value = null)
283 283 {
284 - include_once 'PHP/PMD/Node/CodeFunction.php';
284 + include_once 'PHP/PMD/Node/Function.php';
285 285
286 286 return $this->initFunctionOrMethod(
287 - $this->getMock('PHP_PMD_Node_CodeFunction', array(), array(null), '', false),
287 + $this->getMock('PHP_PMD_Node_Function', array(), array(null), '', false),
288 288 $metric,
289 289 $value
290 290 );
293 293 /**
294 294 * Initializes the getMetric() method of the given function or methode node.
295 295 *
296 - * @param PHP_PMD_Node_CodeFunction|PHP_PMD_Node_CodeMethod $mock Mock instance.
296 + * @param PHP_PMD_Node_Function|PHP_PMD_Node_Method $mock Mock instance.
297 297 * @param string $metric Metric acronym.
298 298 * @param mixed $value Expected value.
299 299 *
300 - * @return PHP_PMD_Node_CodeFunction|PHP_PMD_Node_CodeMethod
300 + * @return PHP_PMD_Node_Function|PHP_PMD_Node_Method
301 301 */
302 302 protected function initFunctionOrMethod($mock, $metric, $value)
303 303 {
343 343 }
344 344
345 345 /**
346 + * Creates a mocked {@link PHP_PMD_AbstractRule} instance.
347 + *
348 + * @return PHP_PMD_AbstractRule
349 + */
350 + protected function getRuleMock()
351 + {
352 + include_once 'PHP/PMD/AbstractRule.php';
353 +
354 + return $this->getMockForAbstractClass('PHP_PMD_AbstractRule');
355 + }
356 +
357 + /**
346 358 * Creates a mocked rule-set instance.
347 359 *
348 360 * @param string $expectedClass Optional class name for apply() expected at
199 200 /test/PHP/PMD/ParserFactoryTest.php
83 83 ->method('getInput')
84 84 ->will($this->returnValue($uri));
85 85
86 - $ruleSet = $this->getRuleSetMock('PHP_PMD_Node_CodeClass');
86 + $ruleSet = $this->getRuleSetMock('PHP_PMD_Node_Class');
87 87
88 88 $parser = $factory->create($phpmd);
89 89 $parser->addRuleSet($ruleSet);
109 109 ->method('getInput')
110 110 ->will($this->returnValue($uri));
111 111
112 - $ruleSet = $this->getRuleSetMock('PHP_PMD_Node_CodeClass');
112 + $ruleSet = $this->getRuleSetMock('PHP_PMD_Node_Class');
113 113
114 114 $parser = $factory->create($phpmd);
115 115 $parser->addRuleSet($ruleSet);
136 136 ->method('getInput')
137 137 ->will($this->returnValue($uri1 . ',' . $uri2));
138 138
139 - $ruleSet = $this->getRuleSetMock('PHP_PMD_Node_CodeClass', 2);
139 + $ruleSet = $this->getRuleSetMock('PHP_PMD_Node_Class', 2);
140 140
141 141 $parser = $factory->create($phpmd);
142 142 $parser->addRuleSet($ruleSet);
163 163 ->method('getInput')
164 164 ->will($this->returnValue($uri1 . ',' . $uri2));
165 165
166 - $ruleSet = $this->getRuleSetMock('PHP_PMD_Node_CodeClass', 2);
166 + $ruleSet = $this->getRuleSetMock('PHP_PMD_Node_Class', 2);
167 167
168 168 $parser = $factory->create($phpmd);
169 169 $parser->addRuleSet($ruleSet);
199 200 /source/PHP/PMD/RuleViolation.php
120 120 $this->_node = $node;
121 121 $this->_description = $violationMessage;
122 122
123 - if ($node instanceof PHP_PMD_Node_AbstractCodeType) {
123 + if ($node instanceof PHP_PMD_Node_AbstractType) {
124 124 $this->_className = $node->getName();
125 - } else if ($node instanceof PHP_PMD_Node_CodeMethod) {
125 + } else if ($node instanceof PHP_PMD_Node_Method) {
126 126 $this->_className = $node->getParentName();
127 127 $this->_CodeMethodName = $node->getName();
128 - } else if ($node instanceof PHP_PMD_Node_CodeFunction) {
128 + } else if ($node instanceof PHP_PMD_Node_Function) {
129 129 $this->_functionName = $node->getName();
130 130 }
131 131 }
199 200 /source/PHP/PMD/Parser.php
50 50 require_once 'PHP/Depend/Log/CodeAwareI.php';
51 51 require_once 'PHP/Depend/Visitor/AbstractVisitor.php';
52 52
53 -require_once 'PHP/PMD/Node/CodeClass.php';
54 -require_once 'PHP/PMD/Node/CodeFunction.php';
55 -require_once 'PHP/PMD/Node/CodeMethod.php';
53 +require_once 'PHP/PMD/Node/Class.php';
54 +require_once 'PHP/PMD/Node/Function.php';
55 +require_once 'PHP/PMD/Node/Method.php';
56 56
57 57 /**
58 58 * Simple wrapper around the php depend engine.
205 205 return;
206 206 }
207 207
208 - $this->_apply(new PHP_PMD_Node_CodeClass($node));
208 + $this->_apply(new PHP_PMD_Node_Class($node));
209 209 parent::visitClass($node);
210 210 }
211 211
223 223 return;
224 224 }
225 225
226 - $this->_apply(new PHP_PMD_Node_CodeFunction($node));
226 + $this->_apply(new PHP_PMD_Node_Function($node));
227 227 }
228 228
229 229 /**
240 240 return;
241 241 }
242 242
243 - $this->_apply(new PHP_PMD_Node_CodeMethod($node));
243 + $this->_apply(new PHP_PMD_Node_Method($node));
244 244 }
245 245
246 246 /**
199 200 /source/PHP/PMD/Node/CodeMethod.php
2 -<?php
3 -/**
4 - * This file is part of PHP_PMD.
5 - *
6 - * PHP Version 5
7 - *
8 - * Copyright (c) 2009-2010, Manuel Pichler <mapi@phpmd.org>.
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 Manuel Pichler 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
41 - * @package PHP_PMD
42 - * @subpackage Node
43 - * @author Manuel Pichler <mapi@phpmd.org>
44 - * @copyright 2009-2010 Manuel Pichler. All rights reserved.
45 - * @license http://www.opensource.org/licenses/bsd-license.php BSD License
46 - * @version SVN: $Id$
47 - * @link http://phpmd.org
48 - */
49 -
50 -require_once 'PHP/PMD/Node/AbstractCodeCallable.php';
51 -
52 -/**
53 - * Wrapper around a PHP_Depend method node.
54 - *
55 - * @category PHP
56 - * @package PHP_PMD
57 - * @subpackage Node
58 - * @author Manuel Pichler <mapi@phpmd.org>
59 - * @copyright 2009-2010 Manuel Pichler. All rights reserved.
60 - * @license http://www.opensource.org/licenses/bsd-license.php BSD License
61 - * @version Release: @package_version@
62 - * @link http://phpmd.org
63 - */
64 -class PHP_PMD_Node_CodeMethod extends PHP_PMD_Node_AbstractCodeCallable
65 -{
66 - /**
67 - * Constructs a new method wrapper.
68 - *
69 - * @param PHP_Depend_Code_CodeMethod $node The wrapped method object.
70 - */
71 - public function __construct(PHP_Depend_Code_Method $node)
72 - {
73 - parent::__construct($node);
74 - }
75 -
76 - /**
77 - * Returns the name of the parent package.
78 - *
79 - * @return string
80 - */
81 - public function getPackageName()
82 - {
83 - return $this->getNode()->getParent()->getPackage()->getName();
84 - }
85 -
86 - /**
87 - * Returns the name of the parent type or <b>null</b> when this node has no
88 - * parent type.
89 - *
90 - * @return string
91 - */
92 - public function getParentName()
93 - {
94 - return $this->getNode()->getParent()->getName();
95 - }
96 -
97 - /**
98 - * Returns <b>true</b> when the underlying method is declared as abstract or
99 - * is declared as child of an interface.
100 - *
101 - * @return boolean
102 - */
103 - public function isAbstract()
104 - {
105 - return $this->getNode()->isAbstract();
106 - }
107 -}
199 200 /source/PHP/PMD/Node/AbstractCodeCallable.php
2 -<?php
3 -/**
4 - * This file is part of PHP_PMD.
5 - *
6 - * PHP Version 5
7 - *
8 - * Copyright (c) 2009-2010, Manuel Pichler <mapi@phpmd.org>.
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 Manuel Pichler 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
41 - * @package PHP_PMD
42 - * @subpackage Node
43 - * @author Manuel Pichler <mapi@phpmd.org>
44 - * @copyright 2009-2010 Manuel Pichler. All rights reserved.
45 - * @license http://www.opensource.org/licenses/bsd-license.php BSD License
46 - * @version SVN: $Id$
47 - * @link http://phpmd.org
48 - */
49 -
50 -require_once 'PHP/PMD/Node/AbstractCodeNode.php';
51 -
52 -/**
53 - * Abstract base class for PHP_Depend function and method wrappers.
54 - *
55 - * @category PHP
56 - * @package PHP_PMD
57 - * @subpackage Node
58 - * @author Manuel Pichler <mapi@phpmd.org>
59 - * @copyright 2009-2010 Manuel Pichler. All rights reserved.
60 - * @license http://www.opensource.org/licenses/bsd-license.php BSD License
61 - * @version Release: @package_version@
62 - * @link http://phpmd.org
63 - */
64 -abstract class PHP_PMD_Node_AbstractCodeCallable
65 - extends PHP_PMD_Node_AbstractCodeNode
66 -{
67 - /**
68 - * Constructs a new callable wrapper.
69 - *
70 - * @param PHP_Depend_Code_AbstractCallable $node The wrapped callable object.
71 - */
72 - public function __construct(PHP_Depend_Code_AbstractCallable $node)
73 - {
74 - parent::__construct($node);
75 - }
76 -
77 - /**
78 - * Returns the number of parameters in the callable signature.
79 - *
80 - * @return integer
81 - */
82 - public function getParameterCount()
83 - {
84 - return $this->getNode()->getParameters()->count();
85 - }
86 -}
199 200 /source/PHP/PMD/Node/AbstractCodeType.php
2 -<?php
3 -/**
4 - * This file is part of PHP_PMD.
5 - *
6 - * PHP Version 5
7 - *
8 - * Copyright (c) 2009-2010, Manuel Pichler <mapi@phpmd.org>.
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 Manuel Pichler 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
41 - * @package PHP_PMD
42 - * @subpackage Node
43 - * @author Manuel Pichler <mapi@phpmd.org>
44 - * @copyright 2009-2010 Manuel Pichler. All rights reserved.
45 - * @license http://www.opensource.org/licenses/bsd-license.php BSD License
46 - * @version SVN: $Id$
47 - * @link http://phpmd.org
48 - */
49 -
50 -require_once 'PHP/PMD/Node/AbstractCodeNode.php';
51 -
52 -/**
53 - * Abstract base class for classes and interfaces.
54 - *
55 - * @category PHP
56 - * @package PHP_PMD
57 - * @subpackage Node
58 - * @author Manuel Pichler <mapi@phpmd.org>
59 - * @copyright 2009-2010 Manuel Pichler. All rights reserved.
60 - * @license http://www.opensource.org/licenses/bsd-license.php BSD License
61 - * @version Release: @package_version@
62 - * @link http://phpmd.org
63 - */
64 -abstract class PHP_PMD_Node_AbstractCodeType extends PHP_PMD_Node_AbstractCodeNode
65 -{
66 - /**
67 - * Constructs a new generic class or interface node.
68 - *
69 - * @param PHP_Depend_Code_AbstractType $node The wrapped PHP_Depend node.
70 - */
71 - public function __construct(PHP_Depend_Code_AbstractType $node)
72 - {
73 - parent::__construct($node);
74 - }
75 -
76 - /**
77 - * Returns an <b>array</b> with all methods defined in the context class or
78 - * interface.
79 - *
80 - * @return array(PHP_PMD_Node_CodeMethod)
81 - */
82 - public function getMethods()
83 - {
84 - $methods = array();
85 - foreach ($this->getNode()->getMethods() as $method) {
86 - $methods[] = new PHP_PMD_Node_CodeMethod($method);
87 - }
88 - return $methods;
89 - }
90 -
91 - /**
92 - * Returns an array with the names of all methods within this class or
93 - * interface node.
94 - *
95 - * @return array(string)
96 - */
97 - public function getMethodNames()
98 - {
99 - $names = array();
100 - foreach ($this->getNode()->getMethods() as $method) {
101 - $names[] = $method->getName();
102 - }
103 - return $names;
104 - }
105 -
106 - /**
107 - * Returns the number of constants declared in this type.
108 - *
109 - * @return integer
110 - */
111 - public function getConstantCount()
112 - {
113 - return $this->getNode()->getConstants()->count();
114 - }
115 -
116 - /**
117 - * Returns the name of the parent package.
118 - *
119 - * @return string
120 - */
121 - public function getPackageName()
122 - {
123 - return $this->getNode()->getPackage()->getName();
124 - }
125 -
126 - /**
127 - * Returns the name of the parent type or <b>null</b> when this node has no
128 - * parent type.
129 - *
130 - * @return string
131 - */
132 - public function getParentName()
133 - {
134 - return null;
135 - }
136 -}
199 200 /source/PHP/PMD/Node/CodeClass.php
2 -<?php
3 -/**
4 - * This file is part of PHP_PMD.
5 - *
6 - * PHP Version 5
7 - *
8 - * Copyright (c) 2009-2010, Manuel Pichler <mapi@phpmd.org>.
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 Manuel Pichler 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
41 - * @package PHP_PMD
42 - * @subpackage Node
43 - * @author Manuel Pichler <mapi@phpmd.org>
44 - * @copyright 2009-2010 Manuel Pichler. All rights reserved.
45 - * @license http://www.opensource.org/licenses/bsd-license.php BSD License
46 - * @version SVN: $Id$
47 - * @link http://phpmd.org
48 - */
49 -
50 -require_once 'PHP/PMD/Node/AbstractCodeType.php';
51 -
52 -/**
53 - * Wrapper around PHP_Depend's class objects.
54 - *
55 - * @category PHP
56 - * @package PHP_PMD
57 - * @subpackage Node
58 - * @author Manuel Pichler <mapi@phpmd.org>
59 - * @copyright 2009-2010 Manuel Pichler. All rights reserved.
60 - * @license http://www.opensource.org/licenses/bsd-license.php BSD License
61 - * @version Release: @package_version@
62 - * @link http://phpmd.org
63 - */
64 -class PHP_PMD_Node_CodeClass extends PHP_PMD_Node_AbstractCodeType
65 -{
66 - /**
67 - * Constructs a new class wrapper node.
68 - *
69 - * @param PHP_Depend_Code_Class $node The wrapped class object.
70 - */
71 - public function __construct(PHP_Depend_Code_Class $node)
72 - {
73 - parent::__construct($node);
74 - }
75 -
76 - /**
77 - * This method will return the metric value for the given identifier or
78 - * <b>null</b> when no such metric exists.
79 - *
80 - * @param string $name The metric name or abbreviation.
81 - *
82 - * @return mixed
83 - */
84 - public function getMetric($name)
85 - {
86 - if ($name === 'nopm') {
87 - return $this->_numberOfPublicMembers();
88 - }
89 - return parent::getMetric($name);
90 - }
91 -
92 - /**
93 - * Returns the number of public fields and/or methods in the context class.
94 - *
95 - * @return integer
96 - */
97 - private function _numberOfPublicMembers()
98 - {
99 - $numberOfPublicMembers = 0;
100 - foreach ($this->getNode()->getMethods() as $method) {
101 - if ($method->isPublic()) {
102 - ++$numberOfPublicMembers;
103 - }
104 - }
105 - foreach ($this->getNode()->getProperties() as $property) {
106 - if ($property->isPublic()) {
107 - ++$numberOfPublicMembers;
108 - }
109 - }
110 - return $numberOfPublicMembers;
111 - }
112 -}
199 200 /source/PHP/PMD/Node/CodeFunction.php
2 -<?php
3 -/**
4 - * This file is part of PHP_PMD.
5 - *
6 - * PHP Version 5
7 - *
8 - * Copyright (c) 2009-2010, Manuel Pichler <mapi@phpmd.org>.
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 Manuel Pichler 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
41 - * @package PHP_PMD
42 - * @subpackage Node
43 - * @author Manuel Pichler <mapi@phpmd.org>
44 - * @copyright 2009-2010 Manuel Pichler. All rights reserved.
45 - * @license http://www.opensource.org/licenses/bsd-license.php BSD License
46 - * @version SVN: $Id$
47 - * @link http://phpmd.org
48 - */
49 -
50 -require_once 'PHP/PMD/Node/AbstractCodeCallable.php';
51 -
52 -/**
53 - * Wrapper around a PHP_Depend function node.
54 - *
55 - * @category PHP
56 - * @package PHP_PMD
57 - * @subpackage Node
58 - * @author Manuel Pichler <mapi@phpmd.org>
59 - * @copyright 2009-2010 Manuel Pichler. All rights reserved.
60 - * @license http://www.opensource.org/licenses/bsd-license.php BSD License
61 - * @version Release: @package_version@
62 - * @link http://phpmd.org
63 - */
64 -class PHP_PMD_Node_CodeFunction extends PHP_PMD_Node_AbstractCodeCallable
65 -{
66 - /**
67 - * Constructs a new function wrapper.
68 - *
69 - * @param PHP_Depend_Code_Function $node The wrapped function object.
70 - */
71 - public function __construct(PHP_Depend_Code_Function $node)
72 - {
73 - parent::__construct($node);
74 - }
75 -
76 - /**
77 - * Returns the name of the parent package.
78 - *
79 - * @return string
80 - */
81 - public function getPackageName()
82 - {
83 - return $this->getNode()->getPackage()->getName();
84 - }
85 -
86 - /**
87 - * Returns the name of the parent type or <b>null</b> when this node has no
88 - * parent type.
89 - *
90 - * @return string
91 - */
92 - public function getParentName()
93 - {
94 - return null;
95 - }
96 -}
199 200 /source/PHP/PMD/Node/AbstractCodeNode.php
2 -<?php
3 -/**
4 - * This file is part of PHP_PMD.
5 - *
6 - * PHP Version 5
7 - *
8 - * Copyright (c) 2009-2010, Manuel Pichler <mapi@phpmd.org>.
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 Manuel Pichler 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
41 - * @package PHP_PMD
42 - * @subpackage Node
43 - * @author Manuel Pichler <mapi@phpmd.org>
44 - * @copyright 2009-2010 Manuel Pichler. All rights reserved.
45 - * @license http://www.opensource.org/licenses/bsd-license.php BSD License
46 - * @version SVN: $Id$
47 - * @link http://phpmd.org
48 - */
49 -
50 -require_once 'PHP/PMD/AbstractNode.php';
51 -
52 -/**
53 - * Abstract base class for all code nodes.
54 - *
55 - * @category PHP
56 - * @package PHP_PMD
57 - * @subpackage Node
58 - * @author Manuel Pichler <mapi@phpmd.org>
59 - * @copyright 2009-2010 Manuel Pichler. All rights reserved.
60 - * @license http://www.opensource.org/licenses/bsd-license.php BSD License
61 - * @version Release: @package_version@
62 - * @link http://phpmd.org
63 - */
64 -abstract class PHP_PMD_Node_AbstractCodeNode extends PHP_PMD_AbstractNode
65 -{
66 - /**
67 - * Annotations associated with node instance.
68 - *
69 - * @var PHP_PMD_Node_CodeAnnotations
70 - */
71 - private $_annotations = null;
72 -
73 - /**
74 - * Checks if this node has a suppressed annotation for the given rule
75 - * instance.
76 - *
77 - * @param PHP_PMD_AbstractRule $rule The context rule instance.
78 - *
79 - * @return boolean
80 - */
81 - public function hasSuppressWarningsAnnotationFor(PHP_PMD_AbstractRule $rule)
82 - {
83 - if ($this->_annotations === null) {
84 - $this->_annotations = new PHP_PMD_Node_CodeAnnotations($this);
85 - }
86 - return $this->_annotations->suppresses($rule);
87 - }
88 -}
199 200 /source/PHP/PMD/Node/CodeAnnotation.php
2 -<?php
3 -/**
4 - * This file is part of PHP_PMD.
5 - *
6 - * PHP Version 5
7 - *
8 - * Copyright (c) 2009-2010, Manuel Pichler <mapi@phpmd.org>.
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 Manuel Pichler 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
41 - * @package PHP_PMD
42 - * @subpackage Node
43 - * @author Manuel Pichler <mapi@phpmd.org>
44 - * @copyright 2009-2010 Manuel Pichler. All rights reserved.
45 - * @license http://www.opensource.org/licenses/bsd-license.php BSD License
46 - * @version SVN: $Id$
47 - * @link http://phpmd.org
48 - */
49 -
50 -/**
51 - * Simple code annotation class.
52 - *
53 - * @category PHP
54 - * @package PHP_PMD
55 - * @subpackage Node
56 - * @author Manuel Pichler <mapi@phpmd.org>
57 - * @copyright 2009-2010 Manuel Pichler. All rights reserved.
58 - * @license http://www.opensource.org/licenses/bsd-license.php BSD License
59 - * @version Release: @package_version@
60 - * @link http://phpmd.org
61 - */
62 -class PHP_PMD_Node_CodeAnnotation
63 -{
64 - /**
65 - * Name of the suppress warnings annotation.
66 - */
67 - const SUPPRESS_ANNOTATION = 'SuppressWarnings';
68 -
69 - /**
70 - * The annotation name.
71 - *
72 - * @var string
73 - */
74 - private $_name = null;
75 -
76 - /**
77 - * The annotation value.
78 - *
79 - * @var string
80 - */
81 - private $_value = null;
82 -
83 - /**
84 - * Constructs a new annotation instance.
85 - *
86 - * @param string $name The annotation name.
87 - * @param string $value The supplied annotation value.
88 - */
89 - public function __construct($name, $value)
90 - {
91 - $this->_name = $name;
92 - $this->_value = trim($value, '" ');
93 - }
94 -
95 - /**
96 - * Checks if this annotation suppresses the given rule.
97 - *
98 - * @param PHP_PMD_AbstractRule $rule The rule to check.
99 - *
100 - * @return boolean
101 - */
102 - public function suppresses(PHP_PMD_AbstractRule $rule)
103 - {
104 - if ($this->_name === self::SUPPRESS_ANNOTATION) {
105 - return $this->_suppresses($rule);
106 - }
107 - return false;
108 - }
109 -
110 - /**
111 - * Checks if this annotation suppresses the given rule.
112 - *
113 - * @param PHP_PMD_AbstractRule $rule The rule to check.
114 - *
115 - * @return boolean
116 - */
117 - private function _suppresses(PHP_PMD_AbstractRule $rule)
118 - {
119 - if (in_array($this->_value, array('PHPMD', 'PMD'))) {
120 - return true;
121 - } else if (strpos($this->_value, 'PMD.' . $rule->getName()) !== false) {
122 - return true;
123 - }
124 - return (stripos($rule->getName(), $this->_value) !== false);
125 - }
126 -}
199 200 /source/PHP/PMD/Node/CodeAnnotations.php
2 -<?php
3 -/**
4 - * This file is part of PHP_PMD.
5 - *
6 - * PHP Version 5
7 - *
8 - * Copyright (c) 2009-2010, Manuel Pichler <mapi@phpmd.org>.
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 Manuel Pichler 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
41 - * @package PHP_PMD
42 - * @subpackage Node
43 - * @author Manuel Pichler <mapi@phpmd.org>
44 - * @copyright 2009-2010 Manuel Pichler. All rights reserved.
45 - * @license http://www.opensource.org/licenses/bsd-license.php BSD License
46 - * @version SVN: $Id$
47 - * @link http://phpmd.org
48 - */
49 -
50 -require_once 'PHP/PMD/Node/CodeAnnotation.php';
51 -
52 -/**
53 - * Collection of code annotations.
54 - *
55 - * @category PHP
56 - * @package PHP_PMD
57 - * @subpackage Node
58 - * @author Manuel Pichler <mapi@phpmd.org>
59 - * @copyright 2009-2010 Manuel Pichler. All rights reserved.
60 - * @license http://www.opensource.org/licenses/bsd-license.php BSD License
61 - * @version Release: @package_version@
62 - * @link http://phpmd.org
63 - */
64 -class PHP_PMD_Node_CodeAnnotations
65 -{
66 - /**
67 - * Detected annotations.
68 - *
69 - * @var array(PHP_PMD_Node_CodeAnnotation)
70 - */
71 - private $_annotations = array();
72 -
73 - /**
74 - * Regexp used to extract code annotations.
75 - *
76 - * @var string
77 - */
78 - private $_regexp = '(@([a-z_][a-z0-9_]+)\(([^\)]+)\))i';
79 -
80 - /**
81 - * Constructs a new collection instance.
82 - *
83 - * @param PHP_PMD_AbstractNode $node The context/parent node.
84 - */
85 - public function __construct(PHP_PMD_AbstractNode $node)
86 - {
87 - preg_match_all($this->_regexp, $node->getDocComment(), $matches);
88 - foreach (array_keys($matches[0]) as $i) {
89 - $name = $matches[1][$i];
90 - $value = trim($matches[2][$i], '" ');
91 -
92 - $this->_annotations[] = new PHP_PMD_Node_CodeAnnotation($name, $value);
93 - }
94 - }
95 -
96 - /**
97 - * Checks if one of the annotations suppresses the given rule.
98 - *
99 - * @param PHP_PMD_AbstractRule $rule The rule to check.
100 - *
101 - * @return boolean
102 - */
103 - public function suppresses(PHP_PMD_AbstractRule $rule)
104 - {
105 - foreach ($this->_annotations as $annotation) {
106 - if ($annotation->suppresses($rule)) {
107 - return true;
108 - }
109 - }
110 - return false;
111 - }
112 -}
199 200 /source/PHP/PMD/Node/AbstractNode.php
2 +<?php
3 +/**
4 + * This file is part of PHP_PMD.
5 + *
6 + * PHP Version 5
7 + *
8 + * Copyright (c) 2009-2010, Manuel Pichler <mapi@phpmd.org>.
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 Manuel Pichler 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
41 + * @package PHP_PMD
42 + * @subpackage Node
43 + * @author Manuel Pichler <mapi@phpmd.org>
44 + * @copyright 2009-2010 Manuel Pichler. All rights reserved.
45 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
46 + * @version SVN: $Id$
47 + * @link http://phpmd.org
48 + */
49 +
50 +require_once 'PHP/PMD/AbstractNode.php';
51 +
52 +/**
53 + * Abstract base class for all code nodes.
54 + *
55 + * @category PHP
56 + * @package PHP_PMD
57 + * @subpackage Node
58 + * @author Manuel Pichler <mapi@phpmd.org>
59 + * @copyright 2009-2010 Manuel Pichler. All rights reserved.
60 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
61 + * @version Release: @package_version@
62 + * @link http://phpmd.org
63 + */
64 +abstract class PHP_PMD_Node_AbstractNode extends PHP_PMD_AbstractNode
65 +{
66 + /**
67 + * Annotations associated with node instance.
68 + *
69 + * @var PHP_PMD_Node_Annotations
70 + */
71 + private $_annotations = null;
72 +
73 + /**
74 + * Checks if this node has a suppressed annotation for the given rule
75 + * instance.
76 + *
77 + * @param PHP_PMD_AbstractRule $rule The context rule instance.
78 + *
79 + * @return boolean
80 + */
81 + public function hasSuppressWarningsAnnotationFor(PHP_PMD_AbstractRule $rule)
82 + {
83 + if ($this->_annotations === null) {
84 + $this->_annotations = new PHP_PMD_Node_Annotations($this);
85 + }
86 + return $this->_annotations->suppresses($rule);
87 + }
88 +}
199 200 /source/PHP/PMD/Node/Annotation.php
2 +<?php
3 +/**
4 + * This file is part of PHP_PMD.
5 + *
6 + * PHP Version 5
7 + *
8 + * Copyright (c) 2009-2010, Manuel Pichler <mapi@phpmd.org>.
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 Manuel Pichler 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
41 + * @package PHP_PMD
42 + * @subpackage Node
43 + * @author Manuel Pichler <mapi@phpmd.org>
44 + * @copyright 2009-2010 Manuel Pichler. All rights reserved.
45 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
46 + * @version SVN: $Id$
47 + * @link http://phpmd.org
48 + */
49 +
50 +/**
51 + * Simple code annotation class.
52 + *
53 + * @category PHP
54 + * @package PHP_PMD
55 + * @subpackage Node
56 + * @author Manuel Pichler <mapi@phpmd.org>
57 + * @copyright 2009-2010 Manuel Pichler. All rights reserved.
58 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
59 + * @version Release: @package_version@
60 + * @link http://phpmd.org
61 + */
62 +class PHP_PMD_Node_Annotation
63 +{
64 + /**
65 + * Name of the suppress warnings annotation.
66 + */
67 + const SUPPRESS_ANNOTATION = 'SuppressWarnings';
68 +
69 + /**
70 + * The annotation name.
71 + *
72 + * @var string
73 + */
74 + private $_name = null;
75 +
76 + /**
77 + * The annotation value.
78 + *
79 + * @var string
80 + */
81 + private $_value = null;
82 +
83 + /**
84 + * Constructs a new annotation instance.
85 + *
86 + * @param string $name The annotation name.
87 + * @param string $value The supplied annotation value.
88 + */
89 + public function __construct($name, $value)
90 + {
91 + $this->_name = $name;
92 + $this->_value = trim($value, '" ');
93 + }
94 +
95 + /**
96 + * Checks if this annotation suppresses the given rule.
97 + *
98 + * @param PHP_PMD_AbstractRule $rule The rule to check.
99 + *
100 + * @return boolean
101 + */
102 + public function suppresses(PHP_PMD_AbstractRule $rule)
103 + {
104 + if ($this->_name === self::SUPPRESS_ANNOTATION) {
105 + return $this->_suppresses($rule);
106 + }
107 + return false;
108 + }
109 +
110 + /**
111 + * Checks if this annotation suppresses the given rule.
112 + *
113 + * @param PHP_PMD_AbstractRule $rule The rule to check.
114 + *
115 + * @return boolean
116 + */
117 + private function _suppresses(PHP_PMD_AbstractRule $rule)
118 + {
119 + if (in_array($this->_value, array('PHPMD', 'PMD'))) {
120 + return true;
121 + } else if (strpos($this->_value, 'PMD.' . $rule->getName()) !== false) {
122 + return true;
123 + }
124 + return (stripos($rule->getName(), $this->_value) !== false);
125 + }
126 +}
199 200 /source/PHP/PMD/Node/Annotations.php
2 +<?php
3 +/**
4 + * This file is part of PHP_PMD.
5 + *
6 + * PHP Version 5
7 + *
8 + * Copyright (c) 2009-2010, Manuel Pichler <mapi@phpmd.org>.
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 Manuel Pichler 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
41 + * @package PHP_PMD
42 + * @subpackage Node
43 + * @author Manuel Pichler <mapi@phpmd.org>
44 + * @copyright 2009-2010 Manuel Pichler. All rights reserved.
45 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
46 + * @version SVN: $Id$
47 + * @link http://phpmd.org
48 + */
49 +
50 +require_once 'PHP/PMD/Node/Annotation.php';
51 +
52 +/**
53 + * Collection of code annotations.
54 + *
55 + * @category PHP
56 + * @package PHP_PMD
57 + * @subpackage Node
58 + * @author Manuel Pichler <mapi@phpmd.org>
59 + * @copyright 2009-2010 Manuel Pichler. All rights reserved.
60 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
61 + * @version Release: @package_version@
62 + * @link http://phpmd.org
63 + */
64 +class PHP_PMD_Node_Annotations
65 +{
66 + /**
67 + * Detected annotations.
68 + *
69 + * @var array(PHP_PMD_Node_Annotation)
70 + */
71 + private $_annotations = array();
72 +
73 + /**
74 + * Regexp used to extract code annotations.
75 + *
76 + * @var string
77 + */
78 + private $_regexp = '(@([a-z_][a-z0-9_]+)\(([^\)]+)\))i';
79 +
80 + /**
81 + * Constructs a new collection instance.
82 + *
83 + * @param PHP_PMD_AbstractNode $node The context/parent node.
84 + */
85 + public function __construct(PHP_PMD_AbstractNode $node)
86 + {
87 + preg_match_all($this->_regexp, $node->getDocComment(), $matches);
88 + foreach (array_keys($matches[0]) as $i) {
89 + $name = $matches[1][$i];
90 + $value = trim($matches[2][$i], '" ');
91 +
92 + $this->_annotations[] = new PHP_PMD_Node_Annotation($name, $value);
93 + }
94 + }
95 +
96 + /**
97 + * Checks if one of the annotations suppresses the given rule.
98 + *
99 + * @param PHP_PMD_AbstractRule $rule The rule to check.
100 + *
101 + * @return boolean
102 + */
103 + public function suppresses(PHP_PMD_AbstractRule $rule)
104 + {
105 + foreach ($this->_annotations as $annotation) {
106 + if ($annotation->suppresses($rule)) {
107 + return true;
108 + }
109 + }
110 + return false;
111 + }
112 +}
199 200 /source/PHP/PMD/Node/Method.php
2 +<?php
3 +/**
4 + * This file is part of PHP_PMD.
5 + *
6 + * PHP Version 5
7 + *
8 + * Copyright (c) 2009-2010, Manuel Pichler <mapi@phpmd.org>.
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 Manuel Pichler 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
41 + * @package PHP_PMD
42 + * @subpackage Node
43 + * @author Manuel Pichler <mapi@phpmd.org>
44 + * @copyright 2009-2010 Manuel Pichler. All rights reserved.
45 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
46 + * @version SVN: $Id$
47 + * @link http://phpmd.org
48 + */
49 +
50 +require_once 'PHP/PMD/Node/AbstractCallable.php';
51 +
52 +/**
53 + * Wrapper around a PHP_Depend method node.
54 + *
55 + * @category PHP
56 + * @package PHP_PMD
57 + * @subpackage Node
58 + * @author Manuel Pichler <mapi@phpmd.org>
59 + * @copyright 2009-2010 Manuel Pichler. All rights reserved.
60 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
61 + * @version Release: @package_version@
62 + * @link http://phpmd.org
63 + */
64 +class PHP_PMD_Node_Method extends PHP_PMD_Node_AbstractCallable
65 +{
66 + /**
67 + * Constructs a new method wrapper.
68 + *
69 + * @param PHP_Depend_Code_CodeMethod $node The wrapped method object.
70 + */
71 + public function __construct(PHP_Depend_Code_Method $node)
72 + {
73 + parent::__construct($node);
74 + }
75 +
76 + /**
77 + * Returns the name of the parent package.
78 + *
79 + * @return string
80 + */
81 + public function getPackageName()
82 + {
83 + return $this->getNode()->getParent()->getPackage()->getName();
84 + }
85 +
86 + /**
87 + * Returns the name of the parent type or <b>null</b> when this node has no
88 + * parent type.
89 + *
90 + * @return string
91 + */
92 + public function getParentName()
93 + {
94 + return $this->getNode()->getParent()->getName();
95 + }
96 +
97 + /**
98 + * Returns <b>true</b> when the underlying method is declared as abstract or
99 + * is declared as child of an interface.
100 + *
101 + * @return boolean
102 + */
103 + public function isAbstract()
104 + {
105 + return $this->getNode()->isAbstract();
106 + }
107 +}
199 200 /source/PHP/PMD/Node/AbstractCallable.php
2 +<?php
3 +/**
4 + * This file is part of PHP_PMD.
5 + *
6 + * PHP Version 5
7 + *
8 + * Copyright (c) 2009-2010, Manuel Pichler <mapi@phpmd.org>.
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 Manuel Pichler 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
41 + * @package PHP_PMD
42 + * @subpackage Node
43 + * @author Manuel Pichler <mapi@phpmd.org>
44 + * @copyright 2009-2010 Manuel Pichler. All rights reserved.
45 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
46 + * @version SVN: $Id$
47 + * @link http://phpmd.org
48 + */
49 +
50 +require_once 'PHP/PMD/Node/AbstractNode.php';
51 +
52 +/**
53 + * Abstract base class for PHP_Depend function and method wrappers.
54 + *
55 + * @category PHP
56 + * @package PHP_PMD
57 + * @subpackage Node
58 + * @author Manuel Pichler <mapi@phpmd.org>
59 + * @copyright 2009-2010 Manuel Pichler. All rights reserved.
60 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
61 + * @version Release: @package_version@
62 + * @link http://phpmd.org
63 + */
64 +abstract class PHP_PMD_Node_AbstractCallable extends PHP_PMD_Node_AbstractNode
65 +{
66 + /**
67 + * Constructs a new callable wrapper.
68 + *
69 + * @param PHP_Depend_Code_AbstractCallable $node The wrapped callable object.
70 + */
71 + public function __construct(PHP_Depend_Code_AbstractCallable $node)
72 + {
73 + parent::__construct($node);
74 + }
75 +
76 + /**
77 + * Returns the number of parameters in the callable signature.
78 + *
79 + * @return integer
80 + */
81 + public function getParameterCount()
82 + {
83 + return $this->getNode()->getParameters()->count();
84 + }
85 +}
199 200 /source/PHP/PMD/Node/AbstractType.php
2 +<?php
3 +/**
4 + * This file is part of PHP_PMD.
5 + *
6 + * PHP Version 5
7 + *
8 + * Copyright (c) 2009-2010, Manuel Pichler <mapi@phpmd.org>.
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 Manuel Pichler 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
41 + * @package PHP_PMD
42 + * @subpackage Node
43 + * @author Manuel Pichler <mapi@phpmd.org>
44 + * @copyright 2009-2010 Manuel Pichler. All rights reserved.
45 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
46 + * @version SVN: $Id$
47 + * @link http://phpmd.org
48 + */
49 +
50 +require_once 'PHP/PMD/Node/AbstractNode.php';
51 +
52 +/**
53 + * Abstract base class for classes and interfaces.
54 + *
55 + * @category PHP
56 + * @package PHP_PMD
57 + * @subpackage Node
58 + * @author Manuel Pichler <mapi@phpmd.org>
59 + * @copyright 2009-2010 Manuel Pichler. All rights reserved.
60 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
61 + * @version Release: @package_version@
62 + * @link http://phpmd.org
63 + */
64 +abstract class PHP_PMD_Node_AbstractType extends PHP_PMD_Node_AbstractNode
65 +{
66 + /**
67 + * Constructs a new generic class or interface node.
68 + *
69 + * @param PHP_Depend_Code_AbstractType $node The wrapped PHP_Depend node.
70 + */
71 + public function __construct(PHP_Depend_Code_AbstractType $node)
72 + {
73 + parent::__construct($node);
74 + }
75 +
76 + /**
77 + * Returns an <b>array</b> with all methods defined in the context class or
78 + * interface.
79 + *
80 + * @return array(PHP_PMD_Node_Method)
81 + */
82 + public function getMethods()
83 + {
84 + $methods = array();
85 + foreach ($this->getNode()->getMethods() as $method) {
86 + $methods[] = new PHP_PMD_Node_Method($method);
87 + }
88 + return $methods;
89 + }
90 +
91 + /**
92 + * Returns an array with the names of all methods within this class or
93 + * interface node.
94 + *
95 + * @return array(string)
96 + */
97 + public function getMethodNames()
98 + {
99 + $names = array();
100 + foreach ($this->getNode()->getMethods() as $method) {
101 + $names[] = $method->getName();
102 + }
103 + return $names;
104 + }
105 +
106 + /**
107 + * Returns the number of constants declared in this type.
108 + *
109 + * @return integer
110 + */
111 + public function getConstantCount()
112 + {
113 + return $this->getNode()->getConstants()->count();
114 + }
115 +
116 + /**
117 + * Returns the name of the parent package.
118 + *
119 + * @return string
120 + */
121 + public function getPackageName()
122 + {
123 + return $this->getNode()->getPackage()->getName();
124 + }
125 +
126 + /**
127 + * Returns the name of the parent type or <b>null</b> when this node has no
128 + * parent type.
129 + *
130 + * @return string
131 + */
132 + public function getParentName()
133 + {
134 + return null;
135 + }
136 +}
199 200 /source/PHP/PMD/Node/Class.php
2 +<?php
3 +/**
4 + * This file is part of PHP_PMD.
5 + *
6 + * PHP Version 5
7 + *
8 + * Copyright (c) 2009-2010, Manuel Pichler <mapi@phpmd.org>.
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 Manuel Pichler 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
41 + * @package PHP_PMD
42 + * @subpackage Node
43 + * @author Manuel Pichler <mapi@phpmd.org>
44 + * @copyright 2009-2010 Manuel Pichler. All rights reserved.
45 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
46 + * @version SVN: $Id$
47 + * @link http://phpmd.org
48 + */
49 +
50 +require_once 'PHP/PMD/Node/AbstractType.php';
51 +
52 +/**
53 + * Wrapper around PHP_Depend's class objects.
54 + *
55 + * @category PHP
56 + * @package PHP_PMD
57 + * @subpackage Node
58 + * @author Manuel Pichler <mapi@phpmd.org>
59 + * @copyright 2009-2010 Manuel Pichler. All rights reserved.
60 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
61 + * @version Release: @package_version@
62 + * @link http://phpmd.org
63 + */
64 +class PHP_PMD_Node_Class extends PHP_PMD_Node_AbstractType
65 +{
66 + /**
67 + * Constructs a new class wrapper node.
68 + *
69 + * @param PHP_Depend_Code_Class $node The wrapped class object.
70 + */
71 + public function __construct(PHP_Depend_Code_Class $node)
72 + {
73 + parent::__construct($node);
74 + }
75 +
76 + /**
77 + * This method will return the metric value for the given identifier or
78 + * <b>null</b> when no such metric exists.
79 + *
80 + * @param string $name The metric name or abbreviation.
81 + *
82 + * @return mixed
83 + */
84 + public function getMetric($name)
85 + {
86 + if ($name === 'nopm') {
87 + return $this->_numberOfPublicMembers();
88 + }
89 + return parent::getMetric($name);
90 + }
91 +
92 + /**
93 + * Returns the number of public fields and/or methods in the context class.
94 + *
95 + * @return integer
96 + */
97 + private function _numberOfPublicMembers()
98 + {
99 + $numberOfPublicMembers = 0;
100 + foreach ($this->getNode()->getMethods() as $method) {
101 + if ($method->isPublic()) {
102 + ++$numberOfPublicMembers;
103 + }
104 + }
105 + foreach ($this->getNode()->getProperties() as $property) {
106 + if ($property->isPublic()) {
107 + ++$numberOfPublicMembers;
108 + }
109 + }
110 + return $numberOfPublicMembers;
111 + }
112 +}
199 200 /source/PHP/PMD/Node/Function.php
2 +<?php
3 +/**
4 + * This file is part of PHP_PMD.
5 + *
6 + * PHP Version 5
7 + *
8 + * Copyright (c) 2009-2010, Manuel Pichler <mapi@phpmd.org>.
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 Manuel Pichler 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
41 + * @package PHP_PMD
42 + * @subpackage Node
43 + * @author Manuel Pichler <mapi@phpmd.org>
44 + * @copyright 2009-2010 Manuel Pichler. All rights reserved.
45 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
46 + * @version SVN: $Id$
47 + * @link http://phpmd.org
48 + */
49 +
50 +require_once 'PHP/PMD/Node/AbstractCallable.php';
51 +
52 +/**
53 + * Wrapper around a PHP_Depend function node.
54 + *
55 + * @category PHP
56 + * @package PHP_PMD
57 + * @subpackage Node
58 + * @author Manuel Pichler <mapi@phpmd.org>
59 + * @copyright 2009-2010 Manuel Pichler. All rights reserved.
60 + * @license http://www.opensource.org/licenses/bsd-license.php BSD License
61 + * @version Release: @package_version@
62 + * @link http://phpmd.org
63 + */
64 +class PHP_PMD_Node_Function extends PHP_PMD_Node_AbstractCallable
65 +{
66 + /**
67 + * Constructs a new function wrapper.
68 + *
69 + * @param PHP_Depend_Code_Function $node The wrapped function object.
70 + */
71 + public function __construct(PHP_Depend_Code_Function $node)
72 + {
73 + parent::__construct($node);
74 + }
75 +
76 + /**
77 + * Returns the name of the parent package.
78 + *
79 + * @return string
80 + */
81 + public function getPackageName()
82 + {
83 + return $this->getNode()->getPackage()->getName();
84 + }
85 +
86 + /**
87 + * Returns the name of the parent type or <b>null</b> when this node has no
88 + * parent type.
89 + *
90 + * @return string
91 + */
92 + public function getParentName()
93 + {
94 + return null;
95 + }
96 +}
199 200 /source/PHP/PMD/AbstractNode.php
47 47 */
48 48
49 49 require_once 'PHP/PMD/Node/ASTNode.php';
50 -require_once 'PHP/PMD/Node/CodeAnnotations.php';
50 +require_once 'PHP/PMD/Node/Annotations.php';
51 51
52 52 /**
53 53 * This is an abstract base class for PHP_PMD code nodes, it is just a wrapper
199 200 /source/PHP/PMD/Rule/UnusedPrivateMethod.php
86 86 * This method collects all methods in the given class that are declared
87 87 * as private and are not used in the same class' context.
88 88 *
89 - * @param PHP_PMD_Node_CodeClass $class The context class instance.
89 + * @param PHP_PMD_Node_Class $class The context class instance.
90 90 *
91 91 * @return array(PHP_PMD_AbstractNode)
92 92 */
93 - private function _collectUnusedPrivateMethods(PHP_PMD_Node_CodeClass $class)
93 + private function _collectUnusedPrivateMethods(PHP_PMD_Node_Class $class)
94 94 {
95 95 $methods = $this->_collectPrivateMethods($class);
96 96 return $this->_removeUsedMethods($class, $methods);
99 99 /**
100 100 * Collects all private methods declared in the given class node.
101 101 *
102 - * @param PHP_PMD_Node_CodeClass $class The context class instance.
102 + * @param PHP_PMD_Node_Class $class The context class instance.
103 103 *
104 104 * @return array(PHP_PMD_AbstractNode)
105 105 */
106 - private function _collectPrivateMethods(PHP_PMD_Node_CodeClass $class)
106 + private function _collectPrivateMethods(PHP_PMD_Node_Class $class)
107 107 {
108 108 $methods = array();
109 109 foreach ($class->getMethods() as $method) {
117 117 /**
118 118 * This method removes all used methods from the given methods array.
119 119 *
120 - * @param PHP_PMD_Node_CodeClass $class The context class instance.
121 - * @param array(PHP_PMD_Node_CodeMethod) $methods All collected private methods.
120 + * @param PHP_PMD_Node_Class $class The context class instance.
121 + * @param array(PHP_PMD_Node_Method) $methods All collected private methods.
122 122 *
123 123 * @return array(PHP_PMD_AbstractNode)
124 124 */
125 125 private function _removeUsedMethods(
126 - PHP_PMD_Node_CodeClass $class,
126 + PHP_PMD_Node_Class $class,
127 127 array $methods
128 128 ) {
129 129 foreach ($class->findChildrenOfType('MethodPostfix') as $postfix) {
138 138 * Returns <b>true</b> when the given method should be used for this rule's
139 139 * analysis.
140 140 *
141 - * @param PHP_PMD_Node_CodeClass $class The context class instance.
142 - * @param PHP_PMD_Node_CodeMethod $method The context method instance.
141 + * @param PHP_PMD_Node_Class $class The context class instance.
142 + * @param PHP_PMD_Node_Method $method The context method instance.
143 143 *
144 144 * @return boolean
145 145 */
146 146 private function _acceptMethod(
147 - PHP_PMD_Node_CodeClass $class,
148 - PHP_PMD_Node_CodeMethod $method
147 + PHP_PMD_Node_Class $class,
148 + PHP_PMD_Node_Method $method
149 149 ) {
150 150 return (
151 151 $method->isPrivate() &&
160 160 * This method checks that the given method postfix is accessed on an
161 161 * instance or static reference to the given class.
162 162 *
163 - * @param PHP_PMD_Node_CodeClass $class The context class node instance.
164 - * @param PHP_PMD_Node_ASTNode $postfix The context method postfix node.
163 + * @param PHP_PMD_Node_Class $class The context class node instance.
164 + * @param PHP_PMD_Node_ASTNode $postfix The context method postfix node.
165 165 *
166 166 * @return boolean
167 167 */
168 168 private function _isClassScope(
169 - PHP_PMD_Node_CodeClass $class,
169 + PHP_PMD_Node_Class $class,
170 170 PHP_PMD_Node_ASTNode $postfix
171 171 ) {
172 172 $prefix = $postfix->getParent()->getChild(0);
199 200 /source/PHP/PMD/Rule/UnusedPrivateField.php
94 94 * This method collects all private fields that aren't used by any class
95 95 * method.
96 96 *
97 - * @param PHP_PMD_Node_CodeClass $class The context class node.
97 + * @param PHP_PMD_Node_Class $class The context class node.
98 98 *
99 99 * @return array(PHP_PMD_AbstractNode)
100 100 */
101 - private function _collectUnusedPrivateFields(PHP_PMD_Node_CodeClass $class)
101 + private function _collectUnusedPrivateFields(PHP_PMD_Node_Class $class)
102 102 {
103 103 $this->_fields = array();
104 104
112 112 * This method collects all private fields in the given class and stores
113 113 * them in the <b>$_fields</b> property.
114 114 *
115 - * @param PHP_PMD_Node_CodeClass $class The context class instance.
115 + * @param PHP_PMD_Node_Class $class The context class instance.
116 116 *
117 117 * @return void
118 118 */
119 - private function _collectPrivateFields(PHP_PMD_Node_CodeClass $class)
119 + private function _collectPrivateFields(PHP_PMD_Node_Class $class)
120 120 {
121 121 foreach ($class->findChildrenOfType('FieldDeclaration') as $declaration) {
122 122 if ($declaration->isPrivate()) {
146 146 * removes all fields from the <b>$_fields</b> property that are accessed by
147 147 * one of the postfix nodes.
148 148 *
149 - * @param PHP_PMD_Node_CodeClass $class The context class instance.
149 + * @param PHP_PMD_Node_Class $class The context class instance.
150 150 *
151 151 * @return void
152 152 */
153 - private function _removeUsedFields(PHP_PMD_Node_CodeClass $class)
153 + private function _removeUsedFields(PHP_PMD_Node_Class $class)
154 154 {
155 155 foreach ($class->findChildrenOfType('PropertyPostfix') as $postfix) {
156 156 if ($this->_isClassScope($class, $postfix)) {
183 183 * This method checks that the given property postfix is accessed on an
184 184 * instance or static reference to the given class.
185 185 *
186 - * @param PHP_PMD_Node_CodeClass $class The context class node instance.
187 - * @param PHP_PMD_Node_ASTNode $postfix The context property postfix node.
186 + * @param PHP_PMD_Node_Class $class The context class node instance.
187 + * @param PHP_PMD_Node_ASTNode $postfix The context property postfix node.
188 188 *
189 189 * @return boolean
190 190 */
191 191 private function _isClassScope(
192 - PHP_PMD_Node_CodeClass $class,
192 + PHP_PMD_Node_Class $class,
193 193 PHP_PMD_Node_ASTNode $postfix
194 194 ) {
195 195 $prefix = $postfix->getParent()->getChild(0);
199 200 /source/PHP/PMD/Rule/Design/TooManyMethods.php
95 95 /**
96 96 * Counts all methods within the given class/interface node.
97 97 *
98 - * @param PHP_PMD_Node_AbstractCodeType $node The context class node.
98 + * @param PHP_PMD_Node_AbstractType $node The context class node.
99 99 *
100 100 * @return integer
101 101 */
102 - private function _countMethods(PHP_PMD_Node_AbstractCodeType $node)
102 + private function _countMethods(PHP_PMD_Node_AbstractType $node)
103 103 {
104 104 $count = 0;
105 105 foreach ($node->getMethodNames() as $name) {
199 200 /source/PHP/PMD/Rule/UnusedLocalVariable.php
103 103 * are also found in the formal parameters of the given method or/and
104 104 * function node.
105 105 *
106 - * @param PHP_PMD_Node_AbstractCodeCallable $node The currently
106 + * @param PHP_PMD_Node_AbstractCallable $node The currently
107 107 * analyzed method/function node.
108 108 *
109 109 * @return void
110 110 */
111 - private function _removeParameters(PHP_PMD_Node_AbstractCodeCallable $node)
111 + private function _removeParameters(PHP_PMD_Node_AbstractCallable $node)
112 112 {
113 113 // Get formal parameter container
114 114 $parameters = $node->getFirstChildOfType('FormalParameters');
126 126 * method/function node and stores their image in the <b>$_images</b>
127 127 * property.
128 128 *
129 - * @param PHP_PMD_Node_AbstractCodeCallable $node The currently
129 + * @param PHP_PMD_Node_AbstractCallable $node The currently
130 130 * analyzed method/function node.
131 131 *
132 132 * @return void
133 133 */
134 - private function _collectVariables(PHP_PMD_Node_AbstractCodeCallable $node)
134 + private function _collectVariables(PHP_PMD_Node_AbstractCallable $node)
135 135 {
136 136 foreach ($node->findChildrenOfType('Variable') as $variable) {
137 137 if ($this->_accept($variable)) {
199 200 /source/PHP/PMD/Rule/UnusedFormalParameter.php
109 109 */
110 110 private function _isAbstractMethod(PHP_PMD_AbstractNode $node)
111 111 {
112 - if ($node instanceof PHP_PMD_Node_CodeMethod) {
112 + if ($node instanceof PHP_PMD_Node_Method) {
113 113 return $node->isAbstract();
114 114 }
115 115 return false;
199 200 /source/PHP/PMD/RuleSet.php
93 93 * @var array(string=>string) $_applyTo
94 94 */
95 95 private $_applyTo = array(
96 - 'PHP_PMD_Rule_IClassAware' => 'PHP_PMD_Node_CodeClass',
97 - 'PHP_PMD_Rule_IFunctionAware' => 'PHP_PMD_Node_CodeFunction',
98 - 'PHP_PMD_Rule_IMethodAware' => 'PHP_PMD_Node_CodeMethod',
96 + 'PHP_PMD_Rule_IClassAware' => 'PHP_PMD_Node_Class',
97 + 'PHP_PMD_Rule_IFunctionAware' => 'PHP_PMD_Node_Function',
98 + 'PHP_PMD_Rule_IMethodAware' => 'PHP_PMD_Node_Method',
99 99 );
100 100
101 101 /**
104 104 * @var array(string=>array) $_rules
105 105 */
106 106 private $_rules = array(
107 - 'PHP_PMD_Node_CodeClass' => array(),
108 - 'PHP_PMD_Node_CodeFunction' => array(),
109 - 'PHP_PMD_Node_CodeMethod' => array(),
107 + 'PHP_PMD_Node_Class' => array(),
108 + 'PHP_PMD_Node_Function' => array(),
109 + 'PHP_PMD_Node_Method' => array(),
110 110 );
111 111
112 112 /**
199 200 /package.xml
50 50 <tasks:replace from="@package_version@" to="version" type="package-info"/>
51 51 <tasks:replace from="@data_dir@" to="data_dir" type="pear-config"/>
52 52 </file>
53 - <file name="AbstractCodeType.php" role="php">
53 + <file name="AbstractType.php" role="php">
54 54 <tasks:replace from="@package_version@" to="version" type="package-info"/>
55 55 <tasks:replace from="@data_dir@" to="data_dir" type="pear-config"/>
56 56 </file>