From b7b0a86c589469820a0e0c21db00a13cf36ccca5 Mon Sep 17 00:00:00 2001 From: mscherer Date: Thu, 27 Nov 2025 18:39:33 +0100 Subject: [PATCH] Remove AttributesSniff to fix conflict with Slevomat ReferenceUsedNamesOnly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The AttributesSniff required FQCN (fully qualified class names) for PHP 8 attributes, e.g. `#[\PHPUnit\Framework\Attributes\DataProvider('foo')]`. However, this conflicts with SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly which requires using short names via use statements. When both rules are active, the auto-fixer enters an infinite loop: 1. AttributesSniff converts to FQCN 2. ReferenceUsedNamesOnly converts back to short name with use statement 3. Go to step 1 Removing the AttributesSniff resolves this conflict and aligns with the modern PHP convention of using short names with use statements for better readability and IDE support. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../Sniffs/Commenting/AttributesSniff.php | 100 ------------------ .../Sniffs/Commenting/AttributesSniffTest.php | 22 ---- tests/_data/Attributes/after.php | 50 --------- tests/_data/Attributes/before.php | 50 --------- 4 files changed, 222 deletions(-) delete mode 100644 PhpCollective/Sniffs/Commenting/AttributesSniff.php delete mode 100644 tests/PhpCollective/Sniffs/Commenting/AttributesSniffTest.php delete mode 100644 tests/_data/Attributes/after.php delete mode 100644 tests/_data/Attributes/before.php diff --git a/PhpCollective/Sniffs/Commenting/AttributesSniff.php b/PhpCollective/Sniffs/Commenting/AttributesSniff.php deleted file mode 100644 index 06ecf96..0000000 --- a/PhpCollective/Sniffs/Commenting/AttributesSniff.php +++ /dev/null @@ -1,100 +0,0 @@ -findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true); - if (!$nextIndex) { - return; - } - - $tokens = $phpcsFile->getTokens(); - - if ($tokens[$nextIndex]['code'] === T_NS_SEPARATOR || $tokens[$nextIndex]['code'] === T_NAME_FULLY_QUALIFIED) { - return; - } - - // Get the attribute name (might be multi-token like Foo\Bar or just Foo) - $attributeName = (string)$tokens[$nextIndex]['content']; - $endIndex = $nextIndex; - - // Check if there are more parts to the attribute name (e.g., Foo\Bar) - $checkIndex = $nextIndex + 1; - while ( - isset($tokens[$checkIndex]) && - ($tokens[$checkIndex]['code'] === T_NS_SEPARATOR || $tokens[$checkIndex]['code'] === T_STRING) - ) { - $attributeName .= (string)$tokens[$checkIndex]['content']; - $endIndex = $checkIndex; - $checkIndex++; - } - - // Extract just the first part for use statement lookup - $firstPart = explode('\\', $attributeName)[0]; - - // Look up the use statement - $useStatements = $this->getUseStatements($phpcsFile); - $fullyQualifiedName = null; - - if (isset($useStatements[$firstPart])) { - // Found a use statement, construct the full name - $useStatement = $useStatements[$firstPart]; - $fullName = (string)$useStatement['fullName']; - if (str_contains($attributeName, '\\')) { - // Replace first part with full name (e.g., Foo\Bar\Baz -> \Full\Namespace\Foo\Bar\Baz) - $parts = explode('\\', $attributeName); - array_shift($parts); // Remove first part - $fullyQualifiedName = '\\' . $fullName . (count($parts) > 0 ? '\\' . implode('\\', $parts) : ''); - } else { - $fullyQualifiedName = '\\' . $fullName; - } - } - - $fix = $phpcsFile->addFixableError('FQCN expected for attribute', $nextIndex, 'ExpectedFQCN'); - if ($fix) { - $phpcsFile->fixer->beginChangeset(); - if ($fullyQualifiedName) { - // Replace entire attribute name with fully qualified version - for ($i = $nextIndex; $i <= $endIndex; $i++) { - $phpcsFile->fixer->replaceToken($i, ''); - } - $phpcsFile->fixer->replaceToken($nextIndex, $fullyQualifiedName); - } else { - // No use statement found, just add leading backslash - $phpcsFile->fixer->addContentBefore($nextIndex, '\\'); - } - $phpcsFile->fixer->endChangeset(); - } - } -} diff --git a/tests/PhpCollective/Sniffs/Commenting/AttributesSniffTest.php b/tests/PhpCollective/Sniffs/Commenting/AttributesSniffTest.php deleted file mode 100644 index 2ac16e8..0000000 --- a/tests/PhpCollective/Sniffs/Commenting/AttributesSniffTest.php +++ /dev/null @@ -1,22 +0,0 @@ -assertSnifferFindsErrors(new AttributesSniff(), 4); - } -} diff --git a/tests/_data/Attributes/after.php b/tests/_data/Attributes/after.php deleted file mode 100644 index e34cdbc..0000000 --- a/tests/_data/Attributes/after.php +++ /dev/null @@ -1,50 +0,0 @@ -