| 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 |
|
-} |
| 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 |
|
-} |
| 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 |
|
-} |
|
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 |
+} |
|
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 |
+} |
|
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 |
+} |
|
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 |
+} |
|
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 |
+} |
| 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 |
|
-} |
| 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 |
|
-} |
| 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 |
|
-} |
| 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 |
|
-} |
| 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 |
|
-} |
| 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 |
|
-} |
| 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 |
|
-} |
| 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 |
|
-} |
|
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 |
+} |
|
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 |
+} |
|
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 |
+} |
|
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 |
+} |
|
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 |
+} |
|
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 |
+} |
|
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 |
+} |
|
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 |
+} |