diff --git a/src/Standards/Squiz/Sniffs/WhiteSpace/ScopeKeywordSpacingSniff.php b/src/Standards/Squiz/Sniffs/WhiteSpace/ScopeKeywordSpacingSniff.php index 1424819f51..6a72c07e19 100644 --- a/src/Standards/Squiz/Sniffs/WhiteSpace/ScopeKeywordSpacingSniff.php +++ b/src/Standards/Squiz/Sniffs/WhiteSpace/ScopeKeywordSpacingSniff.php @@ -127,6 +127,9 @@ public function process(File $phpcsFile, $stackPtr) if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) { $spacing = 0; + } else if (isset($tokens[($stackPtr + 2)]) === false) { + // Parse error/live coding. Bow out. + return; } else { if ($tokens[($stackPtr + 2)]['line'] !== $tokens[$stackPtr]['line']) { $spacing = 'newline'; diff --git a/src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.inc b/src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.1.inc similarity index 94% rename from src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.inc rename to src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.1.inc index 12685dc97d..a76f42fef4 100644 --- a/src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.inc +++ b/src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.1.inc @@ -95,9 +95,9 @@ public static function fCreate($attributes = []): ?static } // Also account for static used within union types. -public function fCreate($attributes = []): object|static -{ -} +public function staticLast($attributes = []): object|static {} +public function staticMiddle(): string|static|object {} +public function staticFirst(): static|object {} // Ensure that static as a scope keyword when preceeded by a colon which is not for a type declaration is still handled. $callback = $cond ? get_fn_name() : static function ($a) { return $a * 10; }; diff --git a/src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.inc.fixed b/src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.1.inc.fixed similarity index 94% rename from src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.inc.fixed rename to src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.1.inc.fixed index d3b682ed75..7fd80626d5 100644 --- a/src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.inc.fixed +++ b/src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.1.inc.fixed @@ -90,9 +90,9 @@ public static function fCreate($attributes = []): ?static } // Also account for static used within union types. -public function fCreate($attributes = []): object|static -{ -} +public function staticLast($attributes = []): object|static {} +public function staticMiddle(): string|static|object {} +public function staticFirst(): static|object {} // Ensure that static as a scope keyword when preceeded by a colon which is not for a type declaration is still handled. $callback = $cond ? get_fn_name() : static function ($a) { return $a * 10; }; diff --git a/src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.2.inc b/src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.2.inc new file mode 100644 index 0000000000..45cfb53431 --- /dev/null +++ b/src/Standards/Squiz/Tests/WhiteSpace/ScopeKeywordSpacingUnitTest.2.inc @@ -0,0 +1,6 @@ + */ - public function getErrorList() + public function getErrorList($testFile='') { - return [ - 7 => 2, - 8 => 1, - 13 => 1, - 14 => 1, - 15 => 1, - 17 => 2, - 26 => 1, - 28 => 1, - 29 => 1, - 64 => 1, - 67 => 1, - 71 => 1, - 103 => 1, - 106 => 1, - 111 => 1, - 119 => 1, - 121 => 1, - 127 => 2, - 134 => 2, - 138 => 2, - 140 => 3, - ]; + switch ($testFile) { + case 'ScopeKeywordSpacingUnitTest.1.inc': + return [ + 7 => 2, + 8 => 1, + 13 => 1, + 14 => 1, + 15 => 1, + 17 => 2, + 26 => 1, + 28 => 1, + 29 => 1, + 64 => 1, + 67 => 1, + 71 => 1, + 103 => 1, + 106 => 1, + 111 => 1, + 119 => 1, + 121 => 1, + 127 => 2, + 134 => 2, + 138 => 2, + 140 => 3, + ]; + + case 'ScopeKeywordSpacingUnitTest.3.inc': + return [6 => 1]; + + default: + return []; + }//end switch }//end getErrorList()