From aa0cfc97697752aaef0fb0e32b26a378cdc3cbaa Mon Sep 17 00:00:00 2001 From: "v.fateev" Date: Wed, 1 Jan 2025 10:53:37 +0300 Subject: [PATCH] EnumCaseSpacingSniff: Fixed internal error --- .../Sniffs/Classes/EnumCaseSpacingSniff.php | 2 +- tests/Sniffs/Classes/data/enumCaseSpacingNoErrors.php | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/SlevomatCodingStandard/Sniffs/Classes/EnumCaseSpacingSniff.php b/SlevomatCodingStandard/Sniffs/Classes/EnumCaseSpacingSniff.php index 286d6ec27..0ad71c520 100644 --- a/SlevomatCodingStandard/Sniffs/Classes/EnumCaseSpacingSniff.php +++ b/SlevomatCodingStandard/Sniffs/Classes/EnumCaseSpacingSniff.php @@ -34,7 +34,7 @@ protected function isNextMemberValid(File $phpcsFile, int $pointer): bool $nextPointer = TokenHelper::findNext($phpcsFile, [T_FUNCTION, T_CONST, T_VARIABLE, T_USE, T_ENUM_CASE], $pointer + 1); - return $tokens[$nextPointer]['code'] === T_ENUM_CASE; + return $nextPointer !== null && $tokens[$nextPointer]['code'] === T_ENUM_CASE; } protected function addError(File $phpcsFile, int $pointer, int $minExpectedLines, int $maxExpectedLines, int $found): bool diff --git a/tests/Sniffs/Classes/data/enumCaseSpacingNoErrors.php b/tests/Sniffs/Classes/data/enumCaseSpacingNoErrors.php index 64c5692e6..93e8792c7 100644 --- a/tests/Sniffs/Classes/data/enumCaseSpacingNoErrors.php +++ b/tests/Sniffs/Classes/data/enumCaseSpacingNoErrors.php @@ -44,3 +44,10 @@ enum TestClass case BAR; } + +enum TestClass1 +{ + case FOO; + + use TestTrait; +}