From ae4f33bc1ba3c779681275a506c44f8dff378c28 Mon Sep 17 00:00:00 2001 From: Greg Sherwood Date: Thu, 22 Apr 2021 09:33:45 +1000 Subject: [PATCH] Fixed bug #3303 : findStartOfStatement() doesn't work with T_OPEN_TAG_WITH_ECHO --- package.xml | 1 + src/Files/File.php | 5 +-- tests/Core/File/FindStartOfStatementTest.inc | 10 ++++++ tests/Core/File/FindStartOfStatementTest.php | 32 ++++++++++++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/package.xml b/package.xml index 84121d4f7c..c408f94353 100644 --- a/package.xml +++ b/package.xml @@ -30,6 +30,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> -- Thanks to Alessandro Chitolina for the patch -- Thanks to Juliette Reinders Folmer for the tests - Fixed bug #3296 : PSR2.ControlStructures.SwitchDeclaration takes phpcs:ignore as content of case body + - Fixed bug #3303 : findStartOfStatement() doesn't work with T_OPEN_TAG_WITH_ECHO diff --git a/src/Files/File.php b/src/Files/File.php index aef4fbf27b..ca01f37e95 100644 --- a/src/Files/File.php +++ b/src/Files/File.php @@ -2285,8 +2285,9 @@ public function findNext( public function findStartOfStatement($start, $ignore=null) { $startTokens = Util\Tokens::$blockOpeners; - $startTokens[T_OPEN_SHORT_ARRAY] = true; - $startTokens[T_OPEN_TAG] = true; + $startTokens[T_OPEN_SHORT_ARRAY] = true; + $startTokens[T_OPEN_TAG] = true; + $startTokens[T_OPEN_TAG_WITH_ECHO] = true; $endTokens = [ T_CLOSE_TAG => true, diff --git a/tests/Core/File/FindStartOfStatementTest.inc b/tests/Core/File/FindStartOfStatementTest.inc index a759a1aa6d..ce9dfad3f9 100644 --- a/tests/Core/File/FindStartOfStatementTest.inc +++ b/tests/Core/File/FindStartOfStatementTest.inc @@ -111,3 +111,13 @@ $result = match ($key) { }; return 0; + +/* testOpenTag */ +?> +

Test

+', foo(), ''; + +/* testOpenTagWithEcho */ +?> +

Test

+', foo(), ''; diff --git a/tests/Core/File/FindStartOfStatementTest.php b/tests/Core/File/FindStartOfStatementTest.php index 33c0686ea4..464021f6fc 100644 --- a/tests/Core/File/FindStartOfStatementTest.php +++ b/tests/Core/File/FindStartOfStatementTest.php @@ -468,4 +468,36 @@ public function testNestedMatch() }//end testNestedMatch() + /** + * Test nested match expressions. + * + * @return void + */ + public function testOpenTag() + { + $start = $this->getTargetToken('/* testOpenTag */', T_OPEN_TAG); + $start += 2; + $found = self::$phpcsFile->findStartOfStatement($start); + + $this->assertSame(($start - 1), $found); + + }//end testOpenTag() + + + /** + * Test nested match expressions. + * + * @return void + */ + public function testOpenTagWithEcho() + { + $start = $this->getTargetToken('/* testOpenTagWithEcho */', T_OPEN_TAG_WITH_ECHO); + $start += 3; + $found = self::$phpcsFile->findStartOfStatement($start); + + $this->assertSame(($start - 1), $found); + + }//end testOpenTagWithEcho() + + }//end class