From eed69d3325671818bfad1d4966aa1fa8e601bf38 Mon Sep 17 00:00:00 2001 From: webimpress Date: Sun, 5 May 2019 12:50:46 +0100 Subject: [PATCH 1/2] DisallowFqn - resolve conflict with UnusedImport sniff when imported class was removed --- .../Sniffs/PHP/DisallowFqnSniff.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/WebimpressCodingStandard/Sniffs/PHP/DisallowFqnSniff.php b/src/WebimpressCodingStandard/Sniffs/PHP/DisallowFqnSniff.php index 55415cd7..87f4feba 100644 --- a/src/WebimpressCodingStandard/Sniffs/PHP/DisallowFqnSniff.php +++ b/src/WebimpressCodingStandard/Sniffs/PHP/DisallowFqnSniff.php @@ -410,7 +410,7 @@ private function processString(File $phpcsFile, int $stackPtr, string $namespace $error = '%s must be imported as %s'; $data = [$name, $alias]; - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Import', $data); + $fix = $this->error($phpcsFile, $error, $stackPtr, 'Import', $data, $alias); if ($fix) { return $this->import($type, $name, $alias); @@ -460,7 +460,7 @@ private function error( string $code, array $data, string $expected - ) : void { + ) : bool { $fix = $phpcsFile->addFixableError($error, $stackPtr, $code, $data); if ($fix) { $tokens = $phpcsFile->getTokens(); @@ -481,6 +481,8 @@ private function error( } $phpcsFile->fixer->endChangeset(); } + + return $fix; } private function import(string $type, string $fqn, string $alias) : array From 7974d3c5edaa84554e44ac376822a2ee982a8bc5 Mon Sep 17 00:00:00 2001 From: webimpress Date: Fri, 10 May 2019 20:08:38 +0100 Subject: [PATCH 2/2] Adds CHANGELOG entry for #9 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7594564e..ddb36daf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,8 @@ All notable changes to this project will be documented in this file, in reverse - [#8](https://github.com/webimpress/coding-standard/pull/8) `Formatting\StringClassReference` - fixes checking if string is a valid class name before check if class/interface/trait exists +- [#9](https://github.com/webimpress/coding-standard/pull/9) `PHP\DisallowFqn` - fixes conflict with `Namespaces\UnusedUseStatement` when newly added import was deleted straight away + ## 1.0.0 - 2019-03-07 Initial release.