Skip to content

Commit

Permalink
Fixed bug #3303 : findStartOfStatement() doesn't work with T_OPEN_TAG…
Browse files Browse the repository at this point in the history
…_WITH_ECHO
  • Loading branch information
gsherwood committed Apr 21, 2021
1 parent 342dbf2 commit ae4f33b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.xml
Expand Up @@ -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
</notes>
<contents>
<dir name="/">
Expand Down
5 changes: 3 additions & 2 deletions src/Files/File.php
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions tests/Core/File/FindStartOfStatementTest.inc
Expand Up @@ -111,3 +111,13 @@ $result = match ($key) {
};

return 0;

/* testOpenTag */
?>
<h1>Test</h1>
<?php echo '<h2>', foo(), '</h2>';

/* testOpenTagWithEcho */
?>
<h1>Test</h1>
<?= '<h2>', foo(), '</h2>';
32 changes: 32 additions & 0 deletions tests/Core/File/FindStartOfStatementTest.php
Expand Up @@ -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

0 comments on commit ae4f33b

Please sign in to comment.