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 c0122e9 commit 3540a5d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Files/File.php
Expand Up @@ -2230,8 +2230,9 @@ public function findNext(
public function findStartOfStatement($start, $ignore=null)
{
$startTokens = 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 3540a5d

Please sign in to comment.