@@ -660,4 +660,157 @@ public static function dataFindStartInsideClosedScopeNestedWithinMatch()
660660 ],
661661 ];
662662 }
663+
664+ /**
665+ * Test finding the start of a statement for a token within a set of parentheses within a match expressions.
666+ *
667+ * @param string $testMarker The comment which prefaces the target token in the test file.
668+ * @param int|string $target The token to search for after the test marker.
669+ * @param int|string $expectedTarget Token code of the expected start of statement stack pointer.
670+ *
671+ * @link https://github.com/PHPCSStandards/PHP_CodeSniffer/issues/437
672+ *
673+ * @dataProvider dataFindStartInsideParenthesesNestedWithinMatch
674+ *
675+ * @return void
676+ */
677+ public function testFindStartInsideParenthesesNestedWithinMatch ($ testMarker , $ target , $ expectedTarget )
678+ {
679+ $ testToken = $ this ->getTargetToken ($ testMarker , $ target );
680+ $ expected = $ this ->getTargetToken ($ testMarker , $ expectedTarget );
681+
682+ $ found = BCFile::findStartOfStatement (self ::$ phpcsFile , $ testToken );
683+
684+ $ this ->assertSame ($ expected , $ found );
685+ }
686+
687+ /**
688+ * Data provider.
689+ *
690+ * @return array<string, array<string, int|string>>
691+ */
692+ public static function dataFindStartInsideParenthesesNestedWithinMatch ()
693+ {
694+ return [
695+ 'Array item itself should be start for first array item ' => [
696+ 'testMarker ' => '/* test437NestedLongArrayWithinMatch */ ' ,
697+ 'target ' => T_LNUMBER ,
698+ 'expectedTarget ' => T_LNUMBER ,
699+ ],
700+ 'Array item itself should be start for second array item ' => [
701+ 'testMarker ' => '/* test437NestedLongArrayWithinMatch */ ' ,
702+ 'target ' => T_DNUMBER ,
703+ 'expectedTarget ' => T_DNUMBER ,
704+ ],
705+ 'Array item itself should be start for third array item ' => [
706+ 'testMarker ' => '/* test437NestedLongArrayWithinMatch */ ' ,
707+ 'target ' => T_VARIABLE ,
708+ 'expectedTarget ' => T_VARIABLE ,
709+ ],
710+
711+ 'Parameter itself should be start for first param passed to function call ' => [
712+ 'testMarker ' => '/* test437NestedFunctionCallWithinMatch */ ' ,
713+ 'target ' => T_LNUMBER ,
714+ 'expectedTarget ' => T_LNUMBER ,
715+ ],
716+ 'Parameter itself should be start for second param passed to function call ' => [
717+ 'testMarker ' => '/* test437NestedFunctionCallWithinMatch */ ' ,
718+ 'target ' => T_VARIABLE ,
719+ 'expectedTarget ' => T_VARIABLE ,
720+ ],
721+ 'Parameter itself should be start for third param passed to function call ' => [
722+ 'testMarker ' => '/* test437NestedFunctionCallWithinMatch */ ' ,
723+ 'target ' => T_DNUMBER ,
724+ 'expectedTarget ' => T_DNUMBER ,
725+ ],
726+
727+ 'Parameter itself should be start for first param declared in arrow function ' => [
728+ 'testMarker ' => '/* test437NestedArrowFunctionWithinMatch */ ' ,
729+ 'target ' => T_VARIABLE ,
730+ 'expectedTarget ' => T_VARIABLE ,
731+ ],
732+ 'Parameter itself should be start for second param declared in arrow function ' => [
733+ 'testMarker ' => '/* test437FnSecondParamWithinMatch */ ' ,
734+ 'target ' => T_VARIABLE ,
735+ 'expectedTarget ' => T_VARIABLE ,
736+ ],
737+ ];
738+ }
739+
740+ /**
741+ * Test finding the start of a statement for a token within a set of parentheses within a match expressions,
742+ * which itself is nested within parentheses.
743+ *
744+ * @param string $testMarker The comment which prefaces the target token in the test file.
745+ * @param int|string $target The token to search for after the test marker.
746+ * @param int|string $expectedTarget Token code of the expected start of statement stack pointer.
747+ *
748+ * @link https://github.com/PHPCSStandards/PHP_CodeSniffer/issues/437
749+ *
750+ * @dataProvider dataFindStartInsideParenthesesNestedWithinNestedMatch
751+ *
752+ * @return void
753+ */
754+ public function testFindStartInsideParenthesesNestedWithinNestedMatch ($ testMarker , $ target , $ expectedTarget )
755+ {
756+ $ testToken = $ this ->getTargetToken ($ testMarker , $ target );
757+ $ expected = $ this ->getTargetToken ($ testMarker , $ expectedTarget );
758+
759+ $ found = BCFile::findStartOfStatement (self ::$ phpcsFile , $ testToken );
760+
761+ $ this ->assertSame ($ expected , $ found );
762+ }
763+
764+ /**
765+ * Data provider.
766+ *
767+ * @return array<string, array<string, int|string>>
768+ */
769+ public static function dataFindStartInsideParenthesesNestedWithinNestedMatch ()
770+ {
771+ return [
772+ 'Array item itself should be start for first array item ' => [
773+ 'testMarker ' => '/* test437NestedLongArrayWithinNestedMatch */ ' ,
774+ 'target ' => T_LNUMBER ,
775+ 'expectedTarget ' => T_LNUMBER ,
776+ ],
777+ 'Array item itself should be start for second array item ' => [
778+ 'testMarker ' => '/* test437NestedLongArrayWithinNestedMatch */ ' ,
779+ 'target ' => T_DNUMBER ,
780+ 'expectedTarget ' => T_DNUMBER ,
781+ ],
782+ 'Array item itself should be start for third array item ' => [
783+ 'testMarker ' => '/* test437NestedLongArrayWithinNestedMatch */ ' ,
784+ 'target ' => T_VARIABLE ,
785+ 'expectedTarget ' => T_VARIABLE ,
786+ ],
787+
788+ 'Parameter itself should be start for first param passed to function call ' => [
789+ 'testMarker ' => '/* test437NestedFunctionCallWithinNestedMatch */ ' ,
790+ 'target ' => T_LNUMBER ,
791+ 'expectedTarget ' => T_LNUMBER ,
792+ ],
793+ 'Parameter itself should be start for second param passed to function call ' => [
794+ 'testMarker ' => '/* test437NestedFunctionCallWithinNestedMatch */ ' ,
795+ 'target ' => T_VARIABLE ,
796+ 'expectedTarget ' => T_VARIABLE ,
797+ ],
798+ 'Parameter itself should be start for third param passed to function call ' => [
799+ 'testMarker ' => '/* test437NestedFunctionCallWithinNestedMatch */ ' ,
800+ 'target ' => T_DNUMBER ,
801+ 'expectedTarget ' => T_DNUMBER ,
802+ ],
803+
804+ 'Parameter itself should be start for first param declared in arrow function ' => [
805+ 'testMarker ' => '/* test437NestedArrowFunctionWithinNestedMatch */ ' ,
806+ 'target ' => T_VARIABLE ,
807+ 'expectedTarget ' => T_VARIABLE ,
808+ ],
809+ 'Parameter itself should be start for second param declared in arrow function ' => [
810+ 'testMarker ' => '/* test437FnSecondParamWithinNestedMatch */ ' ,
811+ 'target ' => T_VARIABLE ,
812+ 'expectedTarget ' => T_VARIABLE ,
813+ ],
814+ ];
815+ }
663816}
0 commit comments