Skip to content

Commit

Permalink
Merge pull request #489 from eeree/issue-401
Browse files Browse the repository at this point in the history
Added new predefined variables to AbstractLocalVariable rule
  • Loading branch information
ravage84 committed Jun 15, 2017
2 parents b1c15f8 + c2e378d commit 63047d9
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/main/php/PHPMD/Rule/AbstractLocalVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,23 @@ abstract class AbstractLocalVariable extends AbstractRule
* can never be unused local variables.
*
* @var array(string=>boolean)
* @link http://php.net/manual/en/reserved.variables.php
*/
private static $superGlobals = array(
'$argc' => true,
'$argv' => true,
'$_COOKIE' => true,
'$_ENV' => true,
'$_FILES' => true,
'$_GET' => true,
'$_POST' => true,
'$_REQUEST' => true,
'$_SERVER' => true,
'$_SESSION' => true,
'$GLOBALS' => true,
'$HTTP_RAW_POST_DATA' => true,
'$argc' => true,
'$argv' => true,
'$_COOKIE' => true,
'$_ENV' => true,
'$_FILES' => true,
'$_GET' => true,
'$_POST' => true,
'$_REQUEST' => true,
'$_SERVER' => true,
'$_SESSION' => true,
'$GLOBALS' => true,
'$HTTP_RAW_POST_DATA' => true,
'$php_errormsg' => true,
'$http_response_header' => true,
);

/**
Expand Down
13 changes: 13 additions & 0 deletions src/test/php/PHPMD/Rule/UnusedLocalVariableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -639,4 +639,17 @@ public function testNamespacedCompactFunctionRuleWorksCaseInsensitive()
$rule->setReport($this->getReportMock(0));
$rule->apply($this->getMethod());
}

/**
* testRuleNotAppliesToPredefinedVariables.php
*
* @return void
*/
public function testRuleNotAppliesToPredefinedVariables()
{
$rule = new UnusedLocalVariable();
$rule->addProperty('allow-unused-foreach-variables', 'false');
$rule->setReport($this->getReportMock(1));
$rule->apply($this->getMethod());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* This file is part of PHP Mess Detector.
*
* Copyright (c) Manuel Pichler <mapi@phpmd.org>.
* All rights reserved.
*
* Licensed under BSD License
* For full copyright and license information, please see the LICENSE file.
* Redistributions of files must retain the above copyright notice.
*
* @author Manuel Pichler <mapi@phpmd.org>
* @copyright Manuel Pichler. All rights reserved.
* @license https://opensource.org/licenses/bsd-license.php BSD License
* @link http://phpmd.org/
*/

namespace PHPMDTest;

class testRuleNotAppliesToPredefinedVariables
{
public function testRuleNotAppliesToPredefinedVariables()
{
$foo = 'bar';
$headers = array();
foreach ($http_response_header as $header) {
$headers[] = $header;
if (null !== $php_errormsg) {
continue;
}
}

return $headers;
}
}

0 comments on commit 63047d9

Please sign in to comment.