Skip to content

Commit

Permalink
add attribute_opener and attribute_closer properties to all tokens in…
Browse files Browse the repository at this point in the history
…side an attribute
  • Loading branch information
alekitto committed Mar 19, 2021
1 parent 9baa998 commit 71bed8b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/Tokenizers/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,10 @@ private function createTokenMap()
$this->tokens[$i]['attribute_closer'] = $found;

if ($found !== null) {
$this->tokens[$found]['attribute_opener'] = $i;
$this->tokens[$found]['attribute_closer'] = $found;
for ($x = ($i + 1); $x <= $found; ++$x) {
$this->tokens[$x]['attribute_opener'] = $i;
$this->tokens[$x]['attribute_closer'] = $found;
}
}
}//end if

Expand Down
6 changes: 4 additions & 2 deletions tests/Core/Tokenizer/AttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace PHP_CodeSniffer\Tests\Core\Tokenizer;

use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest;
use PHP_CodeSniffer\Util\Tokens;

class AttributesTest extends AbstractMethodUnitTest
{
Expand Down Expand Up @@ -46,7 +45,10 @@ public function testAttribute($testMarker, $length, $tokenCodes)
$this->assertSame($tokens[$attribute]['attribute_closer'], $tokens[$closer]['attribute_closer']);

$map = array_map(
static function ($token) {
function ($token) use ($attribute, $length) {
$this->assertArrayHasKey('attribute_closer', $token);
$this->assertSame(($attribute + $length), $token['attribute_closer']);

return $token['code'];
},
array_slice($tokens, ($attribute + 1), ($length - 1))
Expand Down

0 comments on commit 71bed8b

Please sign in to comment.