Skip to content

Commit

Permalink
Move UndefinedVariable into CleanCode namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Jul 28, 2019
1 parent 343b374 commit dc78421
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/bin/phpmd
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ class_alias('PHPMD\\Rule\\UnusedFormalParameter', 'PHP_PMD_Rule_UnusedFormalPara
class_alias('PHPMD\\Rule\\UnusedLocalVariable', 'PHP_PMD_Rule_UnusedLocalVariable');
class_alias('PHPMD\\Rule\\UnusedPrivateField', 'PHP_PMD_Rule_UnusedPrivateField');
class_alias('PHPMD\\Rule\\UnusedPrivateMethod', 'PHP_PMD_Rule_UnusedPrivateMethod');
class_alias('PHPMD\\Rule\\UndefinedVariable', 'PHP_PMD_Rule_UndefinedVariable');
class_alias('PHPMD\\Rule\\CleanCode\\BooleanArgumentFlag', 'PHP_PMD_Rule_CleanCode_BooleanArgumentFlag');
class_alias('PHPMD\\Rule\\CleanCode\\ElseExpression', 'PHP_PMD_Rule_CleanCode_ElseExpression');
class_alias('PHPMD\\Rule\\CleanCode\\StaticAccess', 'PHP_PMD_Rule_CleanCode_StaticAccess');
class_alias('PHPMD\\Rule\\CleanCode\\UndefinedVariable', 'PHP_PMD_Rule_CleanCode_UndefinedVariable');
class_alias('PHPMD\\Rule\\Controversial\\CamelCaseClassName', 'PHP_PMD_Rule_Controversial_CamelCaseClassName');
class_alias('PHPMD\\Rule\\Controversial\\CamelCaseMethodName', 'PHP_PMD_Rule_Controversial_CamelCaseMethodName');
class_alias('PHPMD\\Rule\\Controversial\\CamelCaseParameterName', 'PHP_PMD_Rule_Controversial_CamelCaseParameterName');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@
* @link http://phpmd.org/
*/

namespace PHPMD\Rule;
namespace PHPMD\Rule\CleanCode;

use PDepend\Source\AST\ASTVariable;
use PDepend\Source\AST\State;
use PHPMD\AbstractNode;
use PHPMD\Node\AbstractCallableNode;
use PHPMD\Node\ASTNode;
use PHPMD\Node\MethodNode;
use PHPMD\Rule\AbstractLocalVariable;
use PHPMD\Rule\FunctionAware;
use PHPMD\Rule\MethodAware;

/**
* This rule collects all undefined variables within a given function or method
Expand Down
24 changes: 24 additions & 0 deletions src/main/resources/rulesets/cleancode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,28 @@ function createArray() {
]]>
</example>
</rule>

<rule name="UndefinedVariable"
since="2.7"
message="Avoid using undefined variables such as '{0}' which will lead to PHP notices."
class="PHPMD\Rule\CleanCode\UndefinedVariable"
externalInfoUrl="">
<description>
Detects when a variable is used that has not been defined before.
</description>
<priority>3</priority>
<example>
<![CDATA[
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
]]>
</example>
</rule>

</ruleset>
23 changes: 0 additions & 23 deletions src/main/resources/rulesets/unusedcode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,29 +99,6 @@ class Foo
// $howdy is not used
}
}
]]>
</example>
</rule>

<rule name="UndefinedVariable"
since="2.7"
message="Avoid using undefined variables such as '{0}' which will lead to PHP notices."
class="PHPMD\Rule\UndefinedVariable"
externalInfoUrl="">
<description>
Detects when a variable is used that has not been defined before.
</description>
<priority>3</priority>
<example>
<![CDATA[
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
]]>
</example>
</rule>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @link http://phpmd.org/
*/

namespace PHPMD\Rule;
namespace PHPMD\Rule\CleanCode;

use PHPMD\AbstractTest;

Expand Down Expand Up @@ -86,4 +86,16 @@ public function testRuleDoesNotApplyToSuperGlobals()
$rule->setReport($this->getReportMock(0));
$rule->apply($this->getMethod());
}

/**
* testRuleDoesNotApplyToUsedProperties
*
* @return void
*/
public function testRuleDoesNotApplyToUsedProperties()
{
$rule = new UndefinedVariable();
$rule->setReport($this->getReportMock(0));
$rule->apply($this->getMethod());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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/
*/

class testRuleDoesNotApplyToUsedProperties extends AbstractTest
{
protected $x = 'abc';

function testRuleDoesNotApplyToUsedProperties()
{
echo $this->x;
}
}

0 comments on commit dc78421

Please sign in to comment.