Skip to content
This repository
Browse code

[fixes #10096717] LongVariable rule should not apply on private prope…

…rties
  • Loading branch information...
commit f063bc9ea2533e1563a54f08863863e3bec895a2 1 parent 7424046
Manuel Pichler authored March 13, 2011
2  CHANGELOG
@@ -3,6 +3,8 @@ phpmd-1.1.0 (2011/03/  )
3 3
 
4 4
 - Implemented #10474873: Add rule for PHP's goto statement. Implemented
5 5
   with commit #2745a20.
  6
+- Fixed #10096717: LongVariable rule should not apply on private
  7
+  properties. Fixed with commit #.
6 8
 
7 9
 phpmd-1.0.1 (2011/02/12)
8 10
 ========================
4  src/main/php/PHP/PMD/Rule/Naming/LongVariable.php
@@ -94,6 +94,10 @@ public function apply(PHP_PMD_AbstractNode $node)
94 94
         if ($node->getType() === 'class') {
95 95
             $fields = $node->findChildrenOfType('FieldDeclaration');
96 96
             foreach ($fields as $field) {
  97
+                if ($field->isPrivate()) {
  98
+                    continue;
  99
+                }
  100
+                
97 101
                 $declarators = $field->findChildrenOfType('VariableDeclarator');
98 102
                 foreach ($declarators as $declarator) {
99 103
                     $this->checkNodeImage($declarator);
2  src/test/php/PHP/PMD/Regression/AllTests.php
@@ -54,6 +54,7 @@
54 54
 require_once dirname(__FILE__) . '/SuperGlobalsFlaggedAsUnusedTicket019Test.php';
55 55
 require_once dirname(__FILE__) . '/StaticVariablesFlaggedAsUnusedTicket020Test.php';
56 56
 require_once dirname(__FILE__) . '/SuppressWarningsNotAppliesToUnusedPrivateMethod036Test.php';
  57
+require_once dirname(__FILE__) . '/LongVariablePrivatePropertiesTicket010096717Test.php';
57 58
 
58 59
 /**
59 60
  * Main test suite for the PHP_PMD_Regression package.
@@ -84,6 +85,7 @@ public static function suite()
84 85
         $suite->addTestSuite('PHP_PMD_Regression_SuperGlobalsFlaggedAsUnusedTicket019Test');
85 86
         $suite->addTestSuite('PHP_PMD_Regression_StaticVariablesFlaggedAsUnusedTicket020Test');
86 87
         $suite->addTestSuite('PHP_PMD_Regression_SuppressWarningsNotAppliesToUnusedPrivateMethod036Test');
  88
+        $suite->addTestSuite('PHP_PMD_Regression_LongVariablePrivatePropertiesTicket010096717Test');
87 89
 
88 90
         return $suite;
89 91
     }
100  src/test/php/PHP/PMD/Regression/LongVariablePrivatePropertiesTicket010096717Test.php
... ...
@@ -0,0 +1,100 @@
  1
+<?php
  2
+/**
  3
+ * This file is part of PHP_PMD.
  4
+ *
  5
+ * PHP Version 5
  6
+ *
  7
+ * Copyright (c) 2009-2011, Manuel Pichler <mapi@phpmd.org>.
  8
+ * All rights reserved.
  9
+ *
  10
+ * Redistribution and use in source and binary forms, with or without
  11
+ * modification, are permitted provided that the following conditions
  12
+ * are met:
  13
+ *
  14
+ *   * Redistributions of source code must retain the above copyright
  15
+ *     notice, this list of conditions and the following disclaimer.
  16
+ *
  17
+ *   * Redistributions in binary form must reproduce the above copyright
  18
+ *     notice, this list of conditions and the following disclaimer in
  19
+ *     the documentation and/or other materials provided with the
  20
+ *     distribution.
  21
+ *
  22
+ *   * Neither the name of Manuel Pichler nor the names of his
  23
+ *     contributors may be used to endorse or promote products derived
  24
+ *     from this software without specific prior written permission.
  25
+ *
  26
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  27
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  28
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  29
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  30
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  31
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  32
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  33
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  34
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  35
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  36
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37
+ * POSSIBILITY OF SUCH DAMAGE.
  38
+ *
  39
+ * @category   PHP
  40
+ * @package    PHP_PMD
  41
+ * @subpackage Regression
  42
+ * @author     Manuel Pichler <mapi@phpmd.org>
  43
+ * @copyright  2009-2011 Manuel Pichler. All rights reserved.
  44
+ * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
  45
+ * @version    SVN: $Id$
  46
+ * @link       https://www.pivotaltracker.com/story/show/10096717
  47
+ */
  48
+
  49
+require_once dirname(__FILE__) . '/AbstractTest.php';
  50
+
  51
+require_once 'PHP/PMD/Rule/Naming/LongVariable.php';
  52
+
  53
+/**
  54
+ * Regression test for issue 10096717.
  55
+ *
  56
+ * @category   PHP
  57
+ * @package    PHP_PMD
  58
+ * @subpackage Regression
  59
+ * @author     Manuel Pichler <mapi@phpmd.org>
  60
+ * @copyright  2009-2011 Manuel Pichler. All rights reserved.
  61
+ * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
  62
+ * @version    Release: @package_version@
  63
+ * @link       https://www.pivotaltracker.com/story/show/10096717
  64
+ * @since      1.1.0
  65
+ *
  66
+ * @ticket 10096717
  67
+ * @covers stdClass
  68
+ * @group phpmd
  69
+ * @group phpmd::integration
  70
+ * @group integrationtest
  71
+ */
  72
+class PHP_PMD_Regression_LongVariablePrivatePropertiesTicket010096717Test
  73
+    extends PHP_PMD_Regression_AbstractTest
  74
+{
  75
+    /**
  76
+     * testRuleNotAppliesForLongPrivateProperty
  77
+     * 
  78
+     * @return void
  79
+     */
  80
+    public function testRuleNotAppliesForLongPrivateProperty()
  81
+    {
  82
+        $rule = new PHP_PMD_Rule_Naming_LongVariable();
  83
+        $rule->setReport($this->getReportMock(0));
  84
+        $rule->addProperty('maximum', 17);
  85
+        $rule->apply($this->getClass());
  86
+    }
  87
+
  88
+    /**
  89
+     * testRuleNotAppliesForLongPrivateStaticProperty
  90
+     *
  91
+     * @return void
  92
+     */
  93
+    public function testRuleNotAppliesForLongPrivateStaticProperty()
  94
+    {
  95
+        $rule = new PHP_PMD_Rule_Naming_LongVariable();
  96
+        $rule->setReport($this->getReportMock(0));
  97
+        $rule->addProperty('maximum', 17);
  98
+        $rule->apply($this->getClass());
  99
+    }
  100
+}
118  src/test/php/PHP/PMD/Rule/Naming/LongVariableTest.php
@@ -61,6 +61,12 @@
61 61
  * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
62 62
  * @version    Release: @package_version@
63 63
  * @link       http://phpmd.org
  64
+ *
  65
+ * @covers PHP_PMD_Rule_Naming_LongVariable
  66
+ * @group phpmd
  67
+ * @group phpmd::rule
  68
+ * @group phpmd::rule::naming
  69
+ * @group unittest
64 70
  */
65 71
 class PHP_PMD_Rule_Naming_LongVariableTest extends PHP_PMD_AbstractTest
66 72
 {
@@ -68,11 +74,6 @@ class PHP_PMD_Rule_Naming_LongVariableTest extends PHP_PMD_AbstractTest
68 74
      * testRuleAppliesToLocalVariableInFunctionWithNameLongerThanThreshold
69 75
      *
70 76
      * @return void
71  
-     * @covers PHP_PMD_Rule_Naming_LongVariable
72  
-     * @group phpmd
73  
-     * @group phpmd::rule
74  
-     * @group phpmd::rule::naming
75  
-     * @group unittest
76 77
      */
77 78
     public function testRuleAppliesToLocalVariableInFunctionWithNameLongerThanThreshold()
78 79
     {
@@ -86,11 +87,6 @@ public function testRuleAppliesToLocalVariableInFunctionWithNameLongerThanThresh
86 87
      * testRuleNotAppliesToLocalVariableInFunctionWithNameSmallerThanThreshold
87 88
      *
88 89
      * @return void
89  
-     * @covers PHP_PMD_Rule_Naming_LongVariable
90  
-     * @group phpmd
91  
-     * @group phpmd::rule
92  
-     * @group phpmd::rule::naming
93  
-     * @group unittest
94 90
      */
95 91
     public function testRuleNotAppliesToLocalVariableInFunctionWithNameSmallerThanThreshold()
96 92
     {
@@ -104,11 +100,6 @@ public function testRuleNotAppliesToLocalVariableInFunctionWithNameSmallerThanTh
104 100
      * testRuleNotAppliesToLocalVariableInFunctionWithNameEqualToThreshold
105 101
      *
106 102
      * @return void
107  
-     * @covers PHP_PMD_Rule_Naming_LongVariable
108  
-     * @group phpmd
109  
-     * @group phpmd::rule
110  
-     * @group phpmd::rule::naming
111  
-     * @group unittest
112 103
      */
113 104
     public function testRuleNotAppliesToLocalVariableInFunctionWithNameEqualToThreshold()
114 105
     {
@@ -122,11 +113,6 @@ public function testRuleNotAppliesToLocalVariableInFunctionWithNameEqualToThresh
122 113
      * testRuleAppliesToFunctionParameterWithNameLongerThanThreshold
123 114
      *
124 115
      * @return void
125  
-     * @covers PHP_PMD_Rule_Naming_LongVariable
126  
-     * @group phpmd
127  
-     * @group phpmd::rule
128  
-     * @group phpmd::rule::naming
129  
-     * @group unittest
130 116
      */
131 117
     public function testRuleAppliesToFunctionParameterWithNameLongerThanThreshold()
132 118
     {
@@ -140,11 +126,6 @@ public function testRuleAppliesToFunctionParameterWithNameLongerThanThreshold()
140 126
      * testRuleNotAppliesToFunctionParameterWithNameSmallerThanThreshold
141 127
      *
142 128
      * @return void
143  
-     * @covers PHP_PMD_Rule_Naming_LongVariable
144  
-     * @group phpmd
145  
-     * @group phpmd::rule
146  
-     * @group phpmd::rule::naming
147  
-     * @group unittest
148 129
      */
149 130
     public function testRuleNotAppliesToFunctionParameterWithNameSmallerThanThreshold()
150 131
     {
@@ -158,11 +139,6 @@ public function testRuleNotAppliesToFunctionParameterWithNameSmallerThanThreshol
158 139
      * testRuleAppliesToLocalVariableInMethodWithNameLongerThanThreshold
159 140
      *
160 141
      * @return void
161  
-     * @covers PHP_PMD_Rule_Naming_LongVariable
162  
-     * @group phpmd
163  
-     * @group phpmd::rule
164  
-     * @group phpmd::rule::naming
165  
-     * @group unittest
166 142
      */
167 143
     public function testRuleAppliesToLocalVariableInMethodWithNameLongerThanThreshold()
168 144
     {
@@ -182,11 +158,6 @@ public function testRuleAppliesToLocalVariableInMethodWithNameLongerThanThreshol
182 158
      * testRuleNotAppliesToLocalVariableInMethodWithNameEqualToThreshold
183 159
      *
184 160
      * @return void
185  
-     * @covers PHP_PMD_Rule_Naming_LongVariable
186  
-     * @group phpmd
187  
-     * @group phpmd::rule
188  
-     * @group phpmd::rule::naming
189  
-     * @group unittest
190 161
      */
191 162
     public function testRuleNotAppliesToLocalVariableInMethodWithNameEqualToThreshold()
192 163
     {
@@ -200,11 +171,6 @@ public function testRuleNotAppliesToLocalVariableInMethodWithNameEqualToThreshol
200 171
      * testRuleNotAppliesToLocalVariableInMethodWithNameShorterThanThreshold
201 172
      *
202 173
      * @return void
203  
-     * @covers PHP_PMD_Rule_Naming_LongVariable
204  
-     * @group phpmd
205  
-     * @group phpmd::rule
206  
-     * @group phpmd::rule::naming
207  
-     * @group unittest
208 174
      */
209 175
     public function testRuleNotAppliesToLocalVariableInMethodWithNameShorterThanThreshold()
210 176
     {
@@ -218,11 +184,6 @@ public function testRuleNotAppliesToLocalVariableInMethodWithNameShorterThanThre
218 184
      * testRuleAppliesToMethodParameterWithNameLongerThanThreshold
219 185
      *
220 186
      * @return void
221  
-     * @covers PHP_PMD_Rule_Naming_LongVariable
222  
-     * @group phpmd
223  
-     * @group phpmd::rule
224  
-     * @group phpmd::rule::naming
225  
-     * @group unittest
226 187
      */
227 188
     public function testRuleAppliesToMethodParameterWithNameLongerThanThreshold()
228 189
     {
@@ -242,11 +203,6 @@ public function testRuleAppliesToMethodParameterWithNameLongerThanThreshold()
242 203
      * testRuleNotAppliesToMethodParameterWithNameShorterThanThreshold
243 204
      *
244 205
      * @return void
245  
-     * @covers PHP_PMD_Rule_Naming_LongVariable
246  
-     * @group phpmd
247  
-     * @group phpmd::rule
248  
-     * @group phpmd::rule::naming
249  
-     * @group unittest
250 206
      */
251 207
     public function testRuleNotAppliesToMethodParameterWithNameShorterThanThreshold()
252 208
     {
@@ -260,11 +216,6 @@ public function testRuleNotAppliesToMethodParameterWithNameShorterThanThreshold(
260 216
      * testRuleAppliesToFieldWithNameLongerThanThreshold
261 217
      *
262 218
      * @return void
263  
-     * @covers PHP_PMD_Rule_Naming_LongVariable
264  
-     * @group phpmd
265  
-     * @group phpmd::rule
266  
-     * @group phpmd::rule::naming
267  
-     * @group unittest
268 219
      */
269 220
     public function testRuleAppliesToFieldWithNameLongerThanThreshold()
270 221
     {
@@ -278,11 +229,6 @@ public function testRuleAppliesToFieldWithNameLongerThanThreshold()
278 229
      * testRuleNotAppliesToFieldWithNameEqualToThreshold
279 230
      *
280 231
      * @return void
281  
-     * @covers PHP_PMD_Rule_Naming_LongVariable
282  
-     * @group phpmd
283  
-     * @group phpmd::rule
284  
-     * @group phpmd::rule::naming
285  
-     * @group unittest
286 232
      */
287 233
     public function testRuleNotAppliesToFieldWithNameEqualToThreshold()
288 234
     {
@@ -296,11 +242,6 @@ public function testRuleNotAppliesToFieldWithNameEqualToThreshold()
296 242
      * testRuleNotAppliesToFieldWithNameShorterThanThreshold
297 243
      *
298 244
      * @return void
299  
-     * @covers PHP_PMD_Rule_Naming_LongVariable
300  
-     * @group phpmd
301  
-     * @group phpmd::rule
302  
-     * @group phpmd::rule::naming
303  
-     * @group unittest
304 245
      */
305 246
     public function testRuleNotAppliesToFieldWithNameShorterThanThreshold()
306 247
     {
@@ -314,11 +255,6 @@ public function testRuleNotAppliesToFieldWithNameShorterThanThreshold()
314 255
      * testRuleAppliesToFieldAndParameterWithNameLongerThanThreshold
315 256
      *
316 257
      * @return void
317  
-     * @covers PHP_PMD_Rule_Naming_LongVariable
318  
-     * @group phpmd
319  
-     * @group phpmd::rule
320  
-     * @group phpmd::rule::naming
321  
-     * @group unittest
322 258
      */
323 259
     public function testRuleAppliesToFieldAndParameterWithNameLongerThanThreshold()
324 260
     {
@@ -338,11 +274,6 @@ public function testRuleAppliesToFieldAndParameterWithNameLongerThanThreshold()
338 274
      * testRuleNotAppliesToStaticMembersAccessedInMethod
339 275
      *
340 276
      * @return void
341  
-     * @covers PHP_PMD_Rule_Naming_LongVariable
342  
-     * @group phpmd
343  
-     * @group phpmd::rule
344  
-     * @group phpmd::rule::naming
345  
-     * @group unittest
346 277
      */
347 278
     public function testRuleNotAppliesToStaticMembersAccessedInMethod()
348 279
     {
@@ -356,11 +287,6 @@ public function testRuleNotAppliesToStaticMembersAccessedInMethod()
356 287
      * testRuleAppliesToIdenticalVariableOnlyOneTime
357 288
      *
358 289
      * @return void
359  
-     * @covers PHP_PMD_Rule_Naming_LongVariable
360  
-     * @group phpmd
361  
-     * @group phpmd::rule
362  
-     * @group phpmd::rule::naming
363  
-     * @group unittest
364 290
      */
365 291
     public function testRuleAppliesToIdenticalVariableOnlyOneTime()
366 292
     {
@@ -374,11 +300,6 @@ public function testRuleAppliesToIdenticalVariableOnlyOneTime()
374 300
      * testRuleAppliesToIdenticalVariablesInDifferentContextsSeveralTimes
375 301
      *
376 302
      * @return void
377  
-     * @covers PHP_PMD_Rule_Naming_LongVariable
378  
-     * @group phpmd
379  
-     * @group phpmd::rule
380  
-     * @group phpmd::rule::naming
381  
-     * @group unittest
382 303
      */
383 304
     public function testRuleAppliesToIdenticalVariablesInDifferentContextsSeveralTimes()
384 305
     {
@@ -393,4 +314,31 @@ public function testRuleAppliesToIdenticalVariablesInDifferentContextsSeveralTim
393 314
             $rule->apply($method);
394 315
         }
395 316
     }
  317
+    /**
  318
+     * testRuleNotAppliesForLongPrivateProperty
  319
+     *
  320
+     * @return void
  321
+     * @since 1.1.0
  322
+     */
  323
+    public function testRuleNotAppliesForLongPrivateProperty()
  324
+    {
  325
+        $rule = new PHP_PMD_Rule_Naming_LongVariable();
  326
+        $rule->addProperty('maximum', 17);
  327
+        $rule->setReport($this->getReportMock(0));
  328
+        $rule->apply($this->getClass());
  329
+    }
  330
+
  331
+    /**
  332
+     * testRuleNotAppliesForLongPrivateStaticProperty
  333
+     *
  334
+     * @return void
  335
+     * @since 1.1.0
  336
+     */
  337
+    public function testRuleNotAppliesForLongPrivateStaticProperty()
  338
+    {
  339
+        $rule = new PHP_PMD_Rule_Naming_LongVariable();
  340
+        $rule->addProperty('maximum', 17);
  341
+        $rule->setReport($this->getReportMock(0));
  342
+        $rule->apply($this->getClass());
  343
+    }
396 344
 }
5  src/test/resources/files/Regression/010096717/testRuleNotAppliesForLongPrivateProperty.php
... ...
@@ -0,0 +1,5 @@
  1
+<?php
  2
+class testRuleNotAppliesForLongPrivateProperty
  3
+{
  4
+    private $testRuleNotAppliesForLongPrivateProperty = 42;
  5
+}
5  src/test/resources/files/Regression/010096717/testRuleNotAppliesForLongPrivateStaticProperty.php
... ...
@@ -0,0 +1,5 @@
  1
+<?php
  2
+class testRuleNotAppliesForLongPrivateStaticProperty
  3
+{
  4
+    private static $testRuleNotAppliesForLongPrivateStaticProperty = 23;
  5
+}
2  ...sources/files/Rule/Naming/LongVariable/testRuleAppliesToFieldAndParameterWithNameLongerThanThreshold.php
... ...
@@ -1,7 +1,7 @@
1 1
 <?php
2 2
 class testRuleAppliesToFieldAndParameterWithNameLongerThanThreshold
3 3
 {
4  
-    private $_foo;
  4
+    protected $_foo;
5 5
 
6 6
     protected function testRuleAppliesToFieldAndParameterWithNameLongerThanThreshold($fooB)
7 7
     {
2  src/test/resources/files/Rule/Naming/LongVariable/testRuleAppliesToFieldWithNameLongerThanThreshold.php
... ...
@@ -1,5 +1,5 @@
1 1
 <?php
2 2
 class testRuleAppliesToFieldWithNameLongerThanThreshold
3 3
 {
4  
-    private $_thisReallyLongClassFieldName = 42;
  4
+    protected $thisReallyLongClassFieldName = 42;
5 5
 }
5  src/test/resources/files/Rule/Naming/LongVariable/testRuleNotAppliesForLongPrivateProperty.php
... ...
@@ -0,0 +1,5 @@
  1
+<?php
  2
+class testRuleNotAppliesForLongPrivateProperty
  3
+{
  4
+    private $testRuleNotAppliesForLongPrivateProperty = 42;
  5
+}
5  src/test/resources/files/Rule/Naming/LongVariable/testRuleNotAppliesForLongPrivateStaticProperty.php
... ...
@@ -0,0 +1,5 @@
  1
+<?php
  2
+class testRuleNotAppliesForLongPrivateStaticProperty
  3
+{
  4
+    private static $testRuleNotAppliesForLongPrivateStaticProperty = 23;
  5
+}

0 notes on commit f063bc9

Please sign in to comment.
Something went wrong with that request. Please try again.