@@ -813,4 +813,53 @@ public static function dataFindStartInsideParenthesesNestedWithinNestedMatch()
813813 ],
814814 ];
815815 }
816+
817+ /**
818+ * Test finding the start of a statement for a token within a short array within a match expressions.
819+ *
820+ * @param string $testMarker The comment which prefaces the target token in the test file.
821+ * @param int|string $target The token to search for after the test marker.
822+ * @param int|string $expectedTarget Token code of the expected start of statement stack pointer.
823+ *
824+ * @link https://github.com/PHPCSStandards/PHP_CodeSniffer/issues/437
825+ *
826+ * @dataProvider dataFindStartInsideShortArrayNestedWithinMatch
827+ *
828+ * @return void
829+ */
830+ public function testFindStartInsideShortArrayNestedWithinMatch ($ testMarker , $ target , $ expectedTarget )
831+ {
832+ $ testToken = $ this ->getTargetToken ($ testMarker , $ target );
833+ $ expected = $ this ->getTargetToken ($ testMarker , $ expectedTarget );
834+
835+ $ found = BCFile::findStartOfStatement (self ::$ phpcsFile , $ testToken );
836+
837+ $ this ->assertSame ($ expected , $ found );
838+ }
839+
840+ /**
841+ * Data provider.
842+ *
843+ * @return array<string, array<string, int|string>>
844+ */
845+ public static function dataFindStartInsideShortArrayNestedWithinMatch ()
846+ {
847+ return [
848+ 'Array item itself should be start for first array item ' => [
849+ 'testMarker ' => '/* test437NestedShortArrayWithinMatch */ ' ,
850+ 'target ' => T_LNUMBER ,
851+ 'expectedTarget ' => T_LNUMBER ,
852+ ],
853+ 'Array item itself should be start for second array item ' => [
854+ 'testMarker ' => '/* test437NestedShortArrayWithinMatch */ ' ,
855+ 'target ' => T_DNUMBER ,
856+ 'expectedTarget ' => T_DNUMBER ,
857+ ],
858+ 'Array item itself should be start for third array item ' => [
859+ 'testMarker ' => '/* test437NestedShortArrayWithinMatch */ ' ,
860+ 'target ' => T_VARIABLE ,
861+ 'expectedTarget ' => T_VARIABLE ,
862+ ],
863+ ];
864+ }
816865}
0 commit comments