Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UndefinedVariable does not contain externalInfoUrl in output #724

Closed
6 tasks done
yykamei opened this issue Jan 8, 2020 · 0 comments · Fixed by #832
Closed
6 tasks done

UndefinedVariable does not contain externalInfoUrl in output #724

yykamei opened this issue Jan 8, 2020 · 0 comments · Fixed by #832
Labels
Bug Good first issue If you want to help, this may be a good start

Comments

@yykamei
Copy link

yykamei commented Jan 8, 2020

  • PHPMD version: 2.8.1
  • PHP Version: 7.4.1
  • Installation type: composer
  • Operating System / Distribution & Version: Debian Buster

Current Behavior

The violation UndefinedVariable does not contain externalInfoUrl in its element like this:

<pmd version="@project.version@" timestamp="2020-01-08T10:31:06+00:00">
  <file name="/tmp/test.php">
    <violation beginline="3" endline="3" rule="UndefinedVariable" ruleset="Clean Code Rules" priority="3">
      Avoid using undefined variables such as '$x' which will lead to PHP notices.
    </violation>
  </file>
</pmd>

Expected Behavior

I expect the output below:

<?xml version="1.0" encoding="UTF-8" ?>
<pmd version="@project.version@" timestamp="2020-01-08T10:31:15+00:00">
  <file name="/tmp/test.php">
    <violation beginline="3" endline="3" rule="UndefinedVariable" ruleset="Clean Code Rules" externalInfoUrl="https://phpmd.org/rules/cleancode.html#undefinedvariable" priority="3">
      Avoid using undefined variables such as '$x' which will lead to PHP notices.
    </violation>
  </file>
</pmd>

Steps To Reproduce:

Prepare the file test.php:

<?php
function printX() {
    echo $x;
}

And, then run the following command:

$ phpmd test.php xml cleancode

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".

I think the following patch resolves the issue, but I'm not sure this exactly works.

diff --git a/src/main/resources/rulesets/cleancode.xml b/src/main/resources/rulesets/cleancode.xml
index 3f01727..4a81006 100644
--- a/src/main/resources/rulesets/cleancode.xml
+++ b/src/main/resources/rulesets/cleancode.xml
@@ -182,7 +182,7 @@ function make() {
           since="2.8.0"
           message="Avoid using undefined variables such as '{0}' which will lead to PHP notices."
           class="PHPMD\Rule\CleanCode\UndefinedVariable"
-          externalInfoUrl="">
+          externalInfoUrl="https://phpmd.org/rules/cleancode.html#undefinedvariable">
         <description>
             Detects when a variable is used that has not been defined before.
         </description>
@kylekatarnls kylekatarnls added Bug Good first issue If you want to help, this may be a good start labels Jan 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Good first issue If you want to help, this may be a good start
Development

Successfully merging a pull request may close this issue.

2 participants