squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.66k stars 1.48k forks source link

Gitblame: fix fatal error on `chdir()` when `basepath` is set and phpcs is run from subdir #3855

Closed jrfnl closed 9 months ago

jrfnl commented 1 year ago

Description

The Reporter::prepareFileReport() method strips the basepath off the file name for the $report['filename'].

https://github.com/squizlabs/PHP_CodeSniffer/blob/276f68cc74a3e4e1855bab6d01f0089337d00ae0/src/Reporter.php#L337

While this is fine in most cases, for "blame" reports, the full path is needed.

This changes the path passed to the getBlameContent() method in subclasses of the VersionControl class to the full path, which fixes the fatal error for the Gitblame report (and probably similar/related errors in the Hgblame and the Svnblame reports, but I don't have any repos to test this on).

Suggested changelog entry

Fixed bug #3854 : Fatal error when using Gitblame report in combination with basepath and running from project subdirectory

Related issues/external references

Fixes #3854

Loosely related to #3809

Types of changes

jrfnl commented 9 months ago

Closing as replaced by https://github.com/PHPCSStandards/PHP_CodeSniffer/pull/67

jrfnl commented 8 months ago

FYI: this fix is included in today's PHP_CodeSniffer 3.8.0 release.

As per #3932, development on PHP_CodeSniffer will continue in the PHPCSStandards/PHP_CodeSniffer repository. If you want to stay informed, you may want to start "watching" that repo (or watching releases from that repo).