Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…rties
  • Loading branch information...
commit f063bc9ea2533e1563a54f08863863e3bec895a2 1 parent 7424046
@manuelpichler manuelpichler authored
View
2  CHANGELOG
@@ -3,6 +3,8 @@ phpmd-1.1.0 (2011/03/ )
- Implemented #10474873: Add rule for PHP's goto statement. Implemented
with commit #2745a20.
+- Fixed #10096717: LongVariable rule should not apply on private
+ properties. Fixed with commit #.
phpmd-1.0.1 (2011/02/12)
========================
View
4 src/main/php/PHP/PMD/Rule/Naming/LongVariable.php
@@ -94,6 +94,10 @@ public function apply(PHP_PMD_AbstractNode $node)
if ($node->getType() === 'class') {
$fields = $node->findChildrenOfType('FieldDeclaration');
foreach ($fields as $field) {
+ if ($field->isPrivate()) {
+ continue;
+ }
+
$declarators = $field->findChildrenOfType('VariableDeclarator');
foreach ($declarators as $declarator) {
$this->checkNodeImage($declarator);
View
2  src/test/php/PHP/PMD/Regression/AllTests.php
@@ -54,6 +54,7 @@
require_once dirname(__FILE__) . '/SuperGlobalsFlaggedAsUnusedTicket019Test.php';
require_once dirname(__FILE__) . '/StaticVariablesFlaggedAsUnusedTicket020Test.php';
require_once dirname(__FILE__) . '/SuppressWarningsNotAppliesToUnusedPrivateMethod036Test.php';
+require_once dirname(__FILE__) . '/LongVariablePrivatePropertiesTicket010096717Test.php';
/**
* Main test suite for the PHP_PMD_Regression package.
@@ -84,6 +85,7 @@ public static function suite()
$suite->addTestSuite('PHP_PMD_Regression_SuperGlobalsFlaggedAsUnusedTicket019Test');
$suite->addTestSuite('PHP_PMD_Regression_StaticVariablesFlaggedAsUnusedTicket020Test');
$suite->addTestSuite('PHP_PMD_Regression_SuppressWarningsNotAppliesToUnusedPrivateMethod036Test');
+ $suite->addTestSuite('PHP_PMD_Regression_LongVariablePrivatePropertiesTicket010096717Test');
return $suite;
}
View
100 src/test/php/PHP/PMD/Regression/LongVariablePrivatePropertiesTicket010096717Test.php
@@ -0,0 +1,100 @@
+<?php
+/**
+ * This file is part of PHP_PMD.
+ *
+ * PHP Version 5
+ *
+ * Copyright (c) 2009-2011, Manuel Pichler <mapi@phpmd.org>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * Neither the name of Manuel Pichler nor the names of his
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @category PHP
+ * @package PHP_PMD
+ * @subpackage Regression
+ * @author Manuel Pichler <mapi@phpmd.org>
+ * @copyright 2009-2011 Manuel Pichler. All rights reserved.
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version SVN: $Id$
+ * @link https://www.pivotaltracker.com/story/show/10096717
+ */
+
+require_once dirname(__FILE__) . '/AbstractTest.php';
+
+require_once 'PHP/PMD/Rule/Naming/LongVariable.php';
+
+/**
+ * Regression test for issue 10096717.
+ *
+ * @category PHP
+ * @package PHP_PMD
+ * @subpackage Regression
+ * @author Manuel Pichler <mapi@phpmd.org>
+ * @copyright 2009-2011 Manuel Pichler. All rights reserved.
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version Release: @package_version@
+ * @link https://www.pivotaltracker.com/story/show/10096717
+ * @since 1.1.0
+ *
+ * @ticket 10096717
+ * @covers stdClass
+ * @group phpmd
+ * @group phpmd::integration
+ * @group integrationtest
+ */
+class PHP_PMD_Regression_LongVariablePrivatePropertiesTicket010096717Test
+ extends PHP_PMD_Regression_AbstractTest
+{
+ /**
+ * testRuleNotAppliesForLongPrivateProperty
+ *
+ * @return void
+ */
+ public function testRuleNotAppliesForLongPrivateProperty()
+ {
+ $rule = new PHP_PMD_Rule_Naming_LongVariable();
+ $rule->setReport($this->getReportMock(0));
+ $rule->addProperty('maximum', 17);
+ $rule->apply($this->getClass());
+ }
+
+ /**
+ * testRuleNotAppliesForLongPrivateStaticProperty
+ *
+ * @return void
+ */
+ public function testRuleNotAppliesForLongPrivateStaticProperty()
+ {
+ $rule = new PHP_PMD_Rule_Naming_LongVariable();
+ $rule->setReport($this->getReportMock(0));
+ $rule->addProperty('maximum', 17);
+ $rule->apply($this->getClass());
+ }
+}
View
118 src/test/php/PHP/PMD/Rule/Naming/LongVariableTest.php
@@ -61,6 +61,12 @@
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: @package_version@
* @link http://phpmd.org
+ *
+ * @covers PHP_PMD_Rule_Naming_LongVariable
+ * @group phpmd
+ * @group phpmd::rule
+ * @group phpmd::rule::naming
+ * @group unittest
*/
class PHP_PMD_Rule_Naming_LongVariableTest extends PHP_PMD_AbstractTest
{
@@ -68,11 +74,6 @@ class PHP_PMD_Rule_Naming_LongVariableTest extends PHP_PMD_AbstractTest
* testRuleAppliesToLocalVariableInFunctionWithNameLongerThanThreshold
*
* @return void
- * @covers PHP_PMD_Rule_Naming_LongVariable
- * @group phpmd
- * @group phpmd::rule
- * @group phpmd::rule::naming
- * @group unittest
*/
public function testRuleAppliesToLocalVariableInFunctionWithNameLongerThanThreshold()
{
@@ -86,11 +87,6 @@ public function testRuleAppliesToLocalVariableInFunctionWithNameLongerThanThresh
* testRuleNotAppliesToLocalVariableInFunctionWithNameSmallerThanThreshold
*
* @return void
- * @covers PHP_PMD_Rule_Naming_LongVariable
- * @group phpmd
- * @group phpmd::rule
- * @group phpmd::rule::naming
- * @group unittest
*/
public function testRuleNotAppliesToLocalVariableInFunctionWithNameSmallerThanThreshold()
{
@@ -104,11 +100,6 @@ public function testRuleNotAppliesToLocalVariableInFunctionWithNameSmallerThanTh
* testRuleNotAppliesToLocalVariableInFunctionWithNameEqualToThreshold
*
* @return void
- * @covers PHP_PMD_Rule_Naming_LongVariable
- * @group phpmd
- * @group phpmd::rule
- * @group phpmd::rule::naming
- * @group unittest
*/
public function testRuleNotAppliesToLocalVariableInFunctionWithNameEqualToThreshold()
{
@@ -122,11 +113,6 @@ public function testRuleNotAppliesToLocalVariableInFunctionWithNameEqualToThresh
* testRuleAppliesToFunctionParameterWithNameLongerThanThreshold
*
* @return void
- * @covers PHP_PMD_Rule_Naming_LongVariable
- * @group phpmd
- * @group phpmd::rule
- * @group phpmd::rule::naming
- * @group unittest
*/
public function testRuleAppliesToFunctionParameterWithNameLongerThanThreshold()
{
@@ -140,11 +126,6 @@ public function testRuleAppliesToFunctionParameterWithNameLongerThanThreshold()
* testRuleNotAppliesToFunctionParameterWithNameSmallerThanThreshold
*
* @return void
- * @covers PHP_PMD_Rule_Naming_LongVariable
- * @group phpmd
- * @group phpmd::rule
- * @group phpmd::rule::naming
- * @group unittest
*/
public function testRuleNotAppliesToFunctionParameterWithNameSmallerThanThreshold()
{
@@ -158,11 +139,6 @@ public function testRuleNotAppliesToFunctionParameterWithNameSmallerThanThreshol
* testRuleAppliesToLocalVariableInMethodWithNameLongerThanThreshold
*
* @return void
- * @covers PHP_PMD_Rule_Naming_LongVariable
- * @group phpmd
- * @group phpmd::rule
- * @group phpmd::rule::naming
- * @group unittest
*/
public function testRuleAppliesToLocalVariableInMethodWithNameLongerThanThreshold()
{
@@ -182,11 +158,6 @@ public function testRuleAppliesToLocalVariableInMethodWithNameLongerThanThreshol
* testRuleNotAppliesToLocalVariableInMethodWithNameEqualToThreshold
*
* @return void
- * @covers PHP_PMD_Rule_Naming_LongVariable
- * @group phpmd
- * @group phpmd::rule
- * @group phpmd::rule::naming
- * @group unittest
*/
public function testRuleNotAppliesToLocalVariableInMethodWithNameEqualToThreshold()
{
@@ -200,11 +171,6 @@ public function testRuleNotAppliesToLocalVariableInMethodWithNameEqualToThreshol
* testRuleNotAppliesToLocalVariableInMethodWithNameShorterThanThreshold
*
* @return void
- * @covers PHP_PMD_Rule_Naming_LongVariable
- * @group phpmd
- * @group phpmd::rule
- * @group phpmd::rule::naming
- * @group unittest
*/
public function testRuleNotAppliesToLocalVariableInMethodWithNameShorterThanThreshold()
{
@@ -218,11 +184,6 @@ public function testRuleNotAppliesToLocalVariableInMethodWithNameShorterThanThre
* testRuleAppliesToMethodParameterWithNameLongerThanThreshold
*
* @return void
- * @covers PHP_PMD_Rule_Naming_LongVariable
- * @group phpmd
- * @group phpmd::rule
- * @group phpmd::rule::naming
- * @group unittest
*/
public function testRuleAppliesToMethodParameterWithNameLongerThanThreshold()
{
@@ -242,11 +203,6 @@ public function testRuleAppliesToMethodParameterWithNameLongerThanThreshold()
* testRuleNotAppliesToMethodParameterWithNameShorterThanThreshold
*
* @return void
- * @covers PHP_PMD_Rule_Naming_LongVariable
- * @group phpmd
- * @group phpmd::rule
- * @group phpmd::rule::naming
- * @group unittest
*/
public function testRuleNotAppliesToMethodParameterWithNameShorterThanThreshold()
{
@@ -260,11 +216,6 @@ public function testRuleNotAppliesToMethodParameterWithNameShorterThanThreshold(
* testRuleAppliesToFieldWithNameLongerThanThreshold
*
* @return void
- * @covers PHP_PMD_Rule_Naming_LongVariable
- * @group phpmd
- * @group phpmd::rule
- * @group phpmd::rule::naming
- * @group unittest
*/
public function testRuleAppliesToFieldWithNameLongerThanThreshold()
{
@@ -278,11 +229,6 @@ public function testRuleAppliesToFieldWithNameLongerThanThreshold()
* testRuleNotAppliesToFieldWithNameEqualToThreshold
*
* @return void
- * @covers PHP_PMD_Rule_Naming_LongVariable
- * @group phpmd
- * @group phpmd::rule
- * @group phpmd::rule::naming
- * @group unittest
*/
public function testRuleNotAppliesToFieldWithNameEqualToThreshold()
{
@@ -296,11 +242,6 @@ public function testRuleNotAppliesToFieldWithNameEqualToThreshold()
* testRuleNotAppliesToFieldWithNameShorterThanThreshold
*
* @return void
- * @covers PHP_PMD_Rule_Naming_LongVariable
- * @group phpmd
- * @group phpmd::rule
- * @group phpmd::rule::naming
- * @group unittest
*/
public function testRuleNotAppliesToFieldWithNameShorterThanThreshold()
{
@@ -314,11 +255,6 @@ public function testRuleNotAppliesToFieldWithNameShorterThanThreshold()
* testRuleAppliesToFieldAndParameterWithNameLongerThanThreshold
*
* @return void
- * @covers PHP_PMD_Rule_Naming_LongVariable
- * @group phpmd
- * @group phpmd::rule
- * @group phpmd::rule::naming
- * @group unittest
*/
public function testRuleAppliesToFieldAndParameterWithNameLongerThanThreshold()
{
@@ -338,11 +274,6 @@ public function testRuleAppliesToFieldAndParameterWithNameLongerThanThreshold()
* testRuleNotAppliesToStaticMembersAccessedInMethod
*
* @return void
- * @covers PHP_PMD_Rule_Naming_LongVariable
- * @group phpmd
- * @group phpmd::rule
- * @group phpmd::rule::naming
- * @group unittest
*/
public function testRuleNotAppliesToStaticMembersAccessedInMethod()
{
@@ -356,11 +287,6 @@ public function testRuleNotAppliesToStaticMembersAccessedInMethod()
* testRuleAppliesToIdenticalVariableOnlyOneTime
*
* @return void
- * @covers PHP_PMD_Rule_Naming_LongVariable
- * @group phpmd
- * @group phpmd::rule
- * @group phpmd::rule::naming
- * @group unittest
*/
public function testRuleAppliesToIdenticalVariableOnlyOneTime()
{
@@ -374,11 +300,6 @@ public function testRuleAppliesToIdenticalVariableOnlyOneTime()
* testRuleAppliesToIdenticalVariablesInDifferentContextsSeveralTimes
*
* @return void
- * @covers PHP_PMD_Rule_Naming_LongVariable
- * @group phpmd
- * @group phpmd::rule
- * @group phpmd::rule::naming
- * @group unittest
*/
public function testRuleAppliesToIdenticalVariablesInDifferentContextsSeveralTimes()
{
@@ -393,4 +314,31 @@ public function testRuleAppliesToIdenticalVariablesInDifferentContextsSeveralTim
$rule->apply($method);
}
}
+ /**
+ * testRuleNotAppliesForLongPrivateProperty
+ *
+ * @return void
+ * @since 1.1.0
+ */
+ public function testRuleNotAppliesForLongPrivateProperty()
+ {
+ $rule = new PHP_PMD_Rule_Naming_LongVariable();
+ $rule->addProperty('maximum', 17);
+ $rule->setReport($this->getReportMock(0));
+ $rule->apply($this->getClass());
+ }
+
+ /**
+ * testRuleNotAppliesForLongPrivateStaticProperty
+ *
+ * @return void
+ * @since 1.1.0
+ */
+ public function testRuleNotAppliesForLongPrivateStaticProperty()
+ {
+ $rule = new PHP_PMD_Rule_Naming_LongVariable();
+ $rule->addProperty('maximum', 17);
+ $rule->setReport($this->getReportMock(0));
+ $rule->apply($this->getClass());
+ }
}
View
5 src/test/resources/files/Regression/010096717/testRuleNotAppliesForLongPrivateProperty.php
@@ -0,0 +1,5 @@
+<?php
+class testRuleNotAppliesForLongPrivateProperty
+{
+ private $testRuleNotAppliesForLongPrivateProperty = 42;
+}
View
5 src/test/resources/files/Regression/010096717/testRuleNotAppliesForLongPrivateStaticProperty.php
@@ -0,0 +1,5 @@
+<?php
+class testRuleNotAppliesForLongPrivateStaticProperty
+{
+ private static $testRuleNotAppliesForLongPrivateStaticProperty = 23;
+}
View
2  ...sources/files/Rule/Naming/LongVariable/testRuleAppliesToFieldAndParameterWithNameLongerThanThreshold.php
@@ -1,7 +1,7 @@
<?php
class testRuleAppliesToFieldAndParameterWithNameLongerThanThreshold
{
- private $_foo;
+ protected $_foo;
protected function testRuleAppliesToFieldAndParameterWithNameLongerThanThreshold($fooB)
{
View
2  src/test/resources/files/Rule/Naming/LongVariable/testRuleAppliesToFieldWithNameLongerThanThreshold.php
@@ -1,5 +1,5 @@
<?php
class testRuleAppliesToFieldWithNameLongerThanThreshold
{
- private $_thisReallyLongClassFieldName = 42;
+ protected $thisReallyLongClassFieldName = 42;
}
View
5 src/test/resources/files/Rule/Naming/LongVariable/testRuleNotAppliesForLongPrivateProperty.php
@@ -0,0 +1,5 @@
+<?php
+class testRuleNotAppliesForLongPrivateProperty
+{
+ private $testRuleNotAppliesForLongPrivateProperty = 42;
+}
View
5 src/test/resources/files/Rule/Naming/LongVariable/testRuleNotAppliesForLongPrivateStaticProperty.php
@@ -0,0 +1,5 @@
+<?php
+class testRuleNotAppliesForLongPrivateStaticProperty
+{
+ private static $testRuleNotAppliesForLongPrivateStaticProperty = 23;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.