Skip to content

Commit 71bed8b

Browse files
committed
add attribute_opener and attribute_closer properties to all tokens inside an attribute
1 parent 9baa998 commit 71bed8b

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/Tokenizers/Tokenizer.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,8 +754,10 @@ private function createTokenMap()
754754
$this->tokens[$i]['attribute_closer'] = $found;
755755

756756
if ($found !== null) {
757-
$this->tokens[$found]['attribute_opener'] = $i;
758-
$this->tokens[$found]['attribute_closer'] = $found;
757+
for ($x = ($i + 1); $x <= $found; ++$x) {
758+
$this->tokens[$x]['attribute_opener'] = $i;
759+
$this->tokens[$x]['attribute_closer'] = $found;
760+
}
759761
}
760762
}//end if
761763

tests/Core/Tokenizer/AttributesTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
namespace PHP_CodeSniffer\Tests\Core\Tokenizer;
1111

1212
use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest;
13-
use PHP_CodeSniffer\Util\Tokens;
1413

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

4847
$map = array_map(
49-
static function ($token) {
48+
function ($token) use ($attribute, $length) {
49+
$this->assertArrayHasKey('attribute_closer', $token);
50+
$this->assertSame(($attribute + $length), $token['attribute_closer']);
51+
5052
return $token['code'];
5153
},
5254
array_slice($tokens, ($attribute + 1), ($length - 1))

0 commit comments

Comments
 (0)