From a2667bcb4b38c5d0c2a7fd66c450337f4fd971dd Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 13 Jul 2023 10:30:06 +0200 Subject: [PATCH] Gitblame: fix fatal error on `chdir()` when `basepath` is set and phpcs is run from subdir 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). Fixes 3854 --- CHANGELOG.md | 2 ++ src/Reports/VersionControl.php | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8912e592ea..e14018ba8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -139,6 +139,8 @@ The file documents changes to the PHP_CodeSniffer project. - Thanks to Dan Wallis (@fredden) for the patch - Fixed bug #3816 : PSR12/FileHeader: bug fix - false positives on PHP 8.2+ readonly classes - Thanks to Juliette Reinders Folmer (@jrfnl) for the patch +- Fixed bug #3854 : Fatal error when using Gitblame report in combination with `--basepath` and running from project subdirectory + - Thanks to Juliette Reinders Folmer (@jrfnl) for the patch - Fixed bug #3867 : Tokenizer/PHP: union type and intersection type operators were not correctly tokenized for static properties without explicit visibility - Thanks to Juliette Reinders Folmer (@jrfnl) for the patch - Fixed bug #3877 : Filter names can be case-sensitive. The -h help text will now display the correct case for the available filters diff --git a/src/Reports/VersionControl.php b/src/Reports/VersionControl.php index df1cd642db..e3ad74b845 100644 --- a/src/Reports/VersionControl.php +++ b/src/Reports/VersionControl.php @@ -40,7 +40,7 @@ abstract class VersionControl implements Report */ public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80) { - $blames = $this->getBlameContent($report['filename']); + $blames = $this->getBlameContent($phpcsFile->getFilename()); $authorCache = []; $praiseCache = [];