diff --git a/CHANGELOG.md b/CHANGELOG.md index 323b9e8..d9b0088 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed -- Nothing. +- [#153](https://github.com/webimpress/coding-standard/pull/153) fixes calculating spaces before double arrow in arrays - `Arrays\DoubleArrow` sniff. ## 1.2.2 - 2021-04-12 diff --git a/src/WebimpressCodingStandard/Sniffs/Arrays/DoubleArrowSniff.php b/src/WebimpressCodingStandard/Sniffs/Arrays/DoubleArrowSniff.php index 583f754..f7e6820 100644 --- a/src/WebimpressCodingStandard/Sniffs/Arrays/DoubleArrowSniff.php +++ b/src/WebimpressCodingStandard/Sniffs/Arrays/DoubleArrowSniff.php @@ -170,7 +170,10 @@ private function calculateExpectedSpaces(File $phpcsFile, array $indices) : arra true ); - if ($valueEnd && $tokens[$valueEnd]['line'] !== $tokens[$indices[$k]['index_start']]['line'] - 1) { + if (! isset($res[$i]) + && $valueEnd + && $tokens[$valueEnd]['line'] !== $tokens[$indices[$k]['index_start']]['line'] - 1 + ) { $res[$i] = $current; $min = $length; $current = $length; diff --git a/test/Sniffs/Arrays/DoubleArrowUnitTest.1.inc b/test/Sniffs/Arrays/DoubleArrowUnitTest.1.inc index 55b7be9..8f3994e 100644 --- a/test/Sniffs/Arrays/DoubleArrowUnitTest.1.inc +++ b/test/Sniffs/Arrays/DoubleArrowUnitTest.1.inc @@ -68,3 +68,12 @@ $charMap = [ // Comment 'c' => 'C', 'd' => 'D', ]; + +$array = [ + MyClass::class => AliasClass::class, + + Foo::class + => Bar::class, + + A::class => Baz::class, +]; diff --git a/test/Sniffs/Arrays/DoubleArrowUnitTest.1.inc.fixed b/test/Sniffs/Arrays/DoubleArrowUnitTest.1.inc.fixed index 602e7f4..1330008 100644 --- a/test/Sniffs/Arrays/DoubleArrowUnitTest.1.inc.fixed +++ b/test/Sniffs/Arrays/DoubleArrowUnitTest.1.inc.fixed @@ -68,3 +68,12 @@ $charMap = [ // Comment 'c' => 'C', 'd' => 'D', ]; + +$array = [ + MyClass::class => AliasClass::class, + + Foo::class + => Bar::class, + + A::class => Baz::class, +];