diff --git a/src/Cdn77/Sniffs/Ordering/AlphabeticallyOrderedConstantsSniff.php b/src/Cdn77/Sniffs/Ordering/AlphabeticallyOrderedConstantsSniff.php index ca0edca..8c5de28 100644 --- a/src/Cdn77/Sniffs/Ordering/AlphabeticallyOrderedConstantsSniff.php +++ b/src/Cdn77/Sniffs/Ordering/AlphabeticallyOrderedConstantsSniff.php @@ -15,6 +15,7 @@ use function in_array; use function sort; use function sprintf; +use function strtolower; use function ucfirst; use function usort; @@ -36,6 +37,7 @@ * } * @phpstan-type NameShape array{ * content: string, + * lowercaseContent: string, * ptr: int * } * @phpstan-type ValueShape array{ @@ -63,7 +65,7 @@ public function process(File $phpcsFile, mixed $stackPtr): void foreach ($namesWithValuesByVisibility as $visibility => $namesWithValues) { $constantNames = array_map( - static fn (array $nameWithValue): string => $nameWithValue['name']['content'], + static fn (array $nameWithValue): string => $nameWithValue['name']['lowercaseContent'], $namesWithValues, ); $sortedConstantNames = $constantNames; @@ -95,7 +97,7 @@ private function fix(File $file, array $namesWithValues): void $sortedNameAndValueTokens = $namesWithValues; usort( $sortedNameAndValueTokens, - static fn (array $a, array $b): int => $a['name']['content'] <=> $b['name']['content'], + static fn (array $a, array $b): int => $a['name']['lowercaseContent'] <=> $b['name']['lowercaseContent'], ); $fixer->beginChangeset(); @@ -184,7 +186,11 @@ private function findConstantName(File $phpcsFile, int $constStackPtr): array|nu return null; } - return ['content' => $tokens[$constantNameTokenPointer]['content'], 'ptr' => $constantNameTokenPointer]; + return [ + 'content' => $tokens[$constantNameTokenPointer]['content'], + 'lowercaseContent' => strtolower($tokens[$constantNameTokenPointer]['content']), + 'ptr' => $constantNameTokenPointer, + ]; } private function findEqualsPointer(File $phpcsFile, int $constNameStackPtr): int|null diff --git a/tests/Sniffs/Ordering/AlphabeticallyOrderedConstantsSniffTest.php b/tests/Sniffs/Ordering/AlphabeticallyOrderedConstantsSniffTest.php index dd0857a..ec1d05d 100644 --- a/tests/Sniffs/Ordering/AlphabeticallyOrderedConstantsSniffTest.php +++ b/tests/Sniffs/Ordering/AlphabeticallyOrderedConstantsSniffTest.php @@ -19,7 +19,7 @@ public function testErrors(): void $expectedErrors = [ 9 => AlphabeticallyOrderedConstantsSniff::CodeIncorrectConstantOrder, 19 => AlphabeticallyOrderedConstantsSniff::CodeIncorrectConstantOrder, - 24 => AlphabeticallyOrderedConstantsSniff::CodeIncorrectConstantOrder, + 25 => AlphabeticallyOrderedConstantsSniff::CodeIncorrectConstantOrder, ]; $possibleLines = array_keys($expectedErrors); $errors = $file->getErrors(); diff --git a/tests/Sniffs/Ordering/data/AlphabeticallyOrderedConstantsSniffTest.fixed.inc b/tests/Sniffs/Ordering/data/AlphabeticallyOrderedConstantsSniffTest.fixed.inc index c6f37a8..9026183 100644 --- a/tests/Sniffs/Ordering/data/AlphabeticallyOrderedConstantsSniffTest.fixed.inc +++ b/tests/Sniffs/Ordering/data/AlphabeticallyOrderedConstantsSniffTest.fixed.inc @@ -19,7 +19,8 @@ final class TestClass protected const E = 'e'; protected const F = 'f'; protected const G = 'g'; - protected const H = 'h'; + protected const Ha = 'h'; + protected const HB = 'h'; private const I = 'i'; private const J = 'j'; diff --git a/tests/Sniffs/Ordering/data/AlphabeticallyOrderedConstantsSniffTest.inc b/tests/Sniffs/Ordering/data/AlphabeticallyOrderedConstantsSniffTest.inc index 572a352..fe8aa1e 100644 --- a/tests/Sniffs/Ordering/data/AlphabeticallyOrderedConstantsSniffTest.inc +++ b/tests/Sniffs/Ordering/data/AlphabeticallyOrderedConstantsSniffTest.inc @@ -16,10 +16,11 @@ final class TestClass public const D = [123, 'test']; public const B = 'b'; - protected const H = 'h'; protected const E = 'e'; protected const G = 'g'; protected const F = 'f'; + protected const HB = 'h'; + protected const Ha = 'h'; private const K = 'k'; private const J = 'j';