You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Operating System / Distribution & Version: Windows/11
Current Behavior
An anonymous class defined in a static class function is not recognized. Resulting in "UndefinedVariable Avoid using undefined variables such as '$this' which will lead to PHP notices." for each $this access.
Run php phpmd.phar phpmd-anonymous.php text phpmd_config.xml
phpmd_config.xml contains:
<?xml version="1.0"?>
<rulesetname="Clean Code Rules"xmlns="http://pmd.sf.net/ruleset/1.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>
IfStatementAssignment, MissingImport, UndefinedVariable
</description>
<rulename="IfStatementAssignment"since="2.7.0"message="Avoid assigning values to variables in if clauses and the like (line '{0}', column '{1}')."class="PHPMD\Rule\CleanCode\IfStatementAssignment"externalInfoUrl="http://phpmd.org/rules/cleancode.html#ifstatementassignment">
<description>
<![CDATA[Assignments in if clauses and the like are considered a code smell.Assignments in PHP return the right operand as their result.In many cases, this is an expected behavior, but can leadto many difficult to spot bugs, especially when the rightoperand could result in zero, null or an empty string and the like.]]>
</description>
<priority>1</priority>
<properties></properties>
<example>
<![CDATA[class Foo{ public function bar($flag) { if ($foo = 'bar') { // possible typo // ... } if ($baz = 0) { // always false // ... } }}]]>
</example>
</rule>
<rulename="MissingImport"since="2.7.0"message="Missing class import via use statement (line '{0}', column '{1}')."class="PHPMD\Rule\CleanCode\MissingImport"externalInfoUrl="http://phpmd.org/rules/cleancode.html#MissingImport">
<description>
<![CDATA[Importing all external classes in a file through use statements makes them clearly visible.]]>
</description>
<priority>1</priority>
<properties>
<propertyname="ignore-global"value="false"description="Ignore classes in the global namespace" />
</properties>
<example>
<![CDATA[function make() { return new \stdClass();}]]>
</example>
</rule>
<rulename="UndefinedVariable"since="2.8.0"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>
Observe the following output
phpmd-anonymous.php:17 UndefinedVariable Avoid using undefined variables such as '$this' which will lead to PHP notices.
phpmd-anonymous.php:18 UndefinedVariable Avoid using undefined variables such as '$this' which will lead to PHP notices.
phpmd-anonymous.php:19 UndefinedVariable Avoid using undefined variables such as '$this' which will lead to PHP notices.
phpmd-anonymous.php:20 UndefinedVariable Avoid using undefined variables such as '$this' which will lead to PHP notices.
phpmd-anonymous.php:21 UndefinedVariable Avoid using undefined variables such as '$this' which will lead to PHP notices.
phpmd-anonymous.php:22 UndefinedVariable Avoid using undefined variables such as '$this' which will lead to PHP notices.
phpmd-anonymous.php:23 UndefinedVariable Avoid using undefined variables such as '$this' which will lead to PHP notices.
Checks before submitting
Be sure that there isn't already an issue about this. See: Issues list
Be sure that there isn't already a pull request about this. See: Pull requests
I have added every step to reproduce the bug.
If possible I added relevant code examples.
This issue is about 1 bug and nothing more.
The issue has a descriptive title. For example: "JSON rendering failed on Windows for filenames with space".
The text was updated successfully, but these errors were encountered:
Current Behavior
An anonymous class defined in a static class function is not recognized. Resulting in "UndefinedVariable Avoid using undefined variables such as '$this' which will lead to PHP notices." for each $this access.
Expected Behavior
No output/errors/warnings.
Steps To Reproduce:
php phpmd.phar phpmd-anonymous.php text phpmd_config.xml
phpmd_config.xml contains:
Checks before submitting
The text was updated successfully, but these errors were encountered: