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

Baseline violations from baseline file saved in a subfolder are NOT ignored in the PHPMD report #901

Closed
6 tasks done
githoober opened this issue Jun 17, 2021 · 1 comment · Fixed by #903
Closed
6 tasks done

Comments

@githoober
Copy link

githoober commented Jun 17, 2021

  • PHPMD version: 2.10.1
  • PHP Version: 7.3
  • Installation type:composer
  • Operating System / Distribution & Version: CentOS 7.6

Current Behavior

The baseline violations are not ignored in the final report

Expected Behavior

The baseline violations are ignored in the final report

Steps To Reproduce:

  • Save the ruleset.xml file within a subfolder of the project root to not pollute it:
    /home/username/src/project/build/phpmd
  • Generate the baseline file and save it in the same subfolder
    /home/username/src/project/build/phpmd
<?xml version="1.0"?>
<phpmd-baseline>
  <violation rule="PHPMD\Rule\Design\CouplingBetweenObjects" file="/home/username/src/project/src/ClassName.php"/>
</phpmd-baseline>
  • Check the generated file, note that its violations contain the absolute file name paths
    /home/username/src/project/src/ClassName.php
  • Run the check with the baseline
  • The check report will contain all the violations that are set to be ignored in the baseline file
  • The reason is the bug in the logic that reads the baseline file - \PHPMD\Baseline\BaselineSetFactory::fromFile
  • The absolute file name paths are prepended with a basepath calculated as $basePath = dirname($fileName); resulting in (the part in bold is the basepath)
    /home/username/src/project/build/phpmd/home/username/src/project/src.ClassName.php

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".
@githoober githoober changed the title The baseline violations are NOT ignored in the PHPMD report Baseline violations from baseline file saved in a subfolder are NOT ignored in the PHPMD report Jun 17, 2021
@frankdekker
Copy link
Contributor

Thanks for the report, was struggling a bit with the basepath implementation. It shouldve been possible to move the phpmd.baseline.xml file. Added PR :)

@ravage84 ravage84 added this to the 2.x (unspecific) milestone May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants