Skip to content

Commit

Permalink
Fixed #14990109: False detection of unused variable
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelpichler committed Jan 24, 2012
1 parent 1eb2316 commit 183fbd5
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/php/PHP/PMD/Rule/UnusedFormalParameter.php
Expand Up @@ -148,7 +148,7 @@ private function _removeUsedParameters(PHP_PMD_AbstractNode $node)
{
$variables = $node->findChildrenOfType('Variable');
foreach ($variables as $variable) {
if ($this->isLocal($variable)) {
if ($this->isRegularVariable($variable)) {
unset($this->_nodes[$variable->getImage()]);
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/site/docx/changes.xml
Expand Up @@ -9,6 +9,15 @@
</properties>

<body>
<release version="1.2.1"
date="2012/01/24"
description="">

<action date="" dev="mapi" issue="14990109" system="pivotaltracker" due-to="tdxtik" type="fix">
False detection of unused variable
</action>
</release>

<release version="1.2.0"
date="2011/09/27"
description="Version 1.2.0 is a small feature release of PHPMD
Expand All @@ -20,7 +29,7 @@
Controverial PHPMD rule that checks if the project under
test does not utilize PHP's super globals.
</action>
<action type="add" issue="18462127" dev="mapi" date="">
<action type="add" issue="18462127" dev="mapi" date="b066b44">
PHPMD needs a *strict* mode.
</action>
</release>
Expand Down
@@ -0,0 +1,102 @@
<?php
/**
* This file is part of PHP_PMD.
*
* PHP Version 5
*
* Copyright (c) 2008-2012, 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 2008-2012 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/14990109
*/

require_once dirname(__FILE__) . '/AbstractTest.php';

require_once 'PHP/PMD/Rule/UnusedFormalParameter.php';

/**
* Regression test for issue 14990109.
*
* @category PHP
* @package PHP_PMD
* @subpackage Regression
* @author Manuel Pichler <mapi@phpmd.org>
* @copyright 2008-2012 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/14990109
* @since 1.1.0
*
* @ticket 14990109
* @covers stdClass
* @group phpmd
* @group phpmd::regression
* @group regressiontest
*/
class PHP_PMD_Regression_UnusedParameterArgvTicket14990109Test
extends PHP_PMD_Regression_AbstractTest
{
/**
* testRuleDoesNotApplyToFunctionParameterNamedArgv
*
* @return void
*/
public function testRuleDoesNotApplyToFunctionParameterNamedArgv()
{
$ruleSet = new PHP_PMD_RuleSet();
$ruleSet->addRule(new PHP_PMD_Rule_UnusedFormalParameter());
$ruleSet->setReport($this->getReportMock(0));

$ruleSet->apply($this->getFunction());
}

/**
* testRuleDoesNotApplyToMethodParameterNamedArgv
*
* @return void
*/
public function testRuleDoesNotApplyToMethodParameterNamedArgv()
{
$ruleSet = new PHP_PMD_RuleSet();
$ruleSet->addRule(new PHP_PMD_Rule_UnusedFormalParameter());
$ruleSet->setReport($this->getReportMock(0));

$ruleSet->apply($this->getMethod());
}
}
@@ -0,0 +1,8 @@
<?php
function testRuleDoesNotApplyToFunctionParameterNamedArgv($argv)
{
foreach ($argv as $arg)
{
echo $arg;
}
}
@@ -0,0 +1,11 @@
<?php
class testRuleDoesNotApplyToMethodParameterNamedArgvClass
{
public function testRuleDoesNotApplyToMethodParameterNamedArgv($argv)
{
foreach ($argv as $arg)
{
echo $arg;
}
}
}

0 comments on commit 183fbd5

Please sign in to comment.