phpmd / phpmd

PHPMD is a spin-off project of PHP Depend and aims to be a PHP equivalent of the well known Java tool PMD. PHPMD can be seen as an user friendly frontend application for the raw metrics stream measured by PHP Depend.

Home Page:https://phpmd.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Confusing/wrong error message when generating the baseline if the ruleset-file is missing

jakobbuis opened this issue · comments

  • PHPMD version: 2.12.0
  • PHP Version: 8.1.6
  • Installation type: composer
  • Operating System / Distribution & Version: Ubuntu 21.10

Current Behavior

An error message in the console:

Unable to find the baseline file. Use --baseline-file to specify the filepath

Expected Behavior

An error message stating the rule-set file is missing.

Steps To Reproduce:

This error got triggered in a roundabout way because I switched away from the git branch I was working on, thus removing the committed ruleset file from disk. When trying to establish the baseline, the error message is incorrect and leads users down the wrong path. It can be intentionally reproduced like thus:

  1. Install PHPMD using composer
  2. Create a valid ruleset file phpmd.xml.
  3. Run vendor/bin/phpmd . ansi phpmd.xml --generate-baseline. This should work, assuming you have at least one violation.
  4. Remove the ruleset file phpmd.xml and the generated baseline file.
  5. Run vendor/bin/phpmd . ansi phpmd.xml --generate-baseline. This fails with the mentioned error message that does not reflect the problem.

Important caveat: actually giving the command a baseline file location by running:

vendor/bin/phpmd . ansi phpmd.xml --generate-baseline --baseline-file=foo.xml

does not resolve the problem, making this one particularly confusing to users.

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