Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace PHP_CodeSniffer\Tests\Core\Tokenizer; use PHP_CodeSniffer\Tests\Core\Abst..

Decoded Output download

<?php
 namespace PHP_CodeSniffer\Tests\Core\Tokenizer; use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest; class AttributesTest extends AbstractMethodUnitTest { public function testAttribute($testMarker, $length, $tokenCodes) { $tokens = self::$phpcsFile->getTokens(); $attribute = $this->getTargetToken($testMarker, T_ATTRIBUTE); $this->assertArrayHasKey("attribute_closer", $tokens[$attribute]); $closer = $tokens[$attribute]["attribute_closer"]; $this->assertSame($attribute + $length, $closer); $this->assertSame(T_ATTRIBUTE_END, $tokens[$closer]["code"]); $this->assertSame($tokens[$attribute]["attribute_opener"], $tokens[$closer]["attribute_opener"]); $this->assertSame($tokens[$attribute]["attribute_closer"], $tokens[$closer]["attribute_closer"]); $map = array_map(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)); $this->assertSame($tokenCodes, $map); } public function dataAttribute() { return array(array("/* testAttribute */", 2, array(T_STRING)), array("/* testAttributeWithParams */", 7, array(T_STRING, T_OPEN_PARENTHESIS, T_STRING, T_DOUBLE_COLON, T_STRING, T_CLOSE_PARENTHESIS)), array("/* testAttributeWithNamedParam */", 10, array(T_STRING, T_OPEN_PARENTHESIS, T_PARAM_NAME, T_COLON, T_WHITESPACE, T_STRING, T_DOUBLE_COLON, T_STRING, T_CLOSE_PARENTHESIS)), array("/* testAttributeOnFunction */", 2, array(T_STRING)), array("/* testAttributeOnFunctionWithParams */", 17, array(T_STRING, T_OPEN_PARENTHESIS, T_CONSTANT_ENCAPSED_STRING, T_COMMA, T_WHITESPACE, T_PARAM_NAME, T_COLON, T_WHITESPACE, T_OPEN_SHORT_ARRAY, T_CONSTANT_ENCAPSED_STRING, T_WHITESPACE, T_DOUBLE_ARROW, T_WHITESPACE, T_CONSTANT_ENCAPSED_STRING, T_CLOSE_SHORT_ARRAY, T_CLOSE_PARENTHESIS)), array("/* testAttributeWithShortClosureParameter */", 17, array(T_STRING, T_OPEN_PARENTHESIS, T_STATIC, T_WHITESPACE, T_FN, T_WHITESPACE, T_OPEN_PARENTHESIS, T_VARIABLE, T_CLOSE_PARENTHESIS, T_WHITESPACE, T_FN_ARROW, T_WHITESPACE, T_BOOLEAN_NOT, T_WHITESPACE, T_VARIABLE, T_CLOSE_PARENTHESIS)), array("/* testAttributeGrouping */", 26, array(T_STRING, T_COMMA, T_WHITESPACE, T_STRING, T_OPEN_PARENTHESIS, T_CONSTANT_ENCAPSED_STRING, T_CLOSE_PARENTHESIS, T_COMMA, T_WHITESPACE, T_STRING, T_OPEN_PARENTHESIS, T_CONSTANT_ENCAPSED_STRING, T_COMMA, T_WHITESPACE, T_PARAM_NAME, T_COLON, T_WHITESPACE, T_OPEN_SHORT_ARRAY, T_CONSTANT_ENCAPSED_STRING, T_WHITESPACE, T_DOUBLE_ARROW, T_WHITESPACE, T_CONSTANT_ENCAPSED_STRING, T_CLOSE_SHORT_ARRAY, T_CLOSE_PARENTHESIS)), array("/* testAttributeMultiline */", 31, array(T_WHITESPACE, T_WHITESPACE, T_STRING, T_COMMA, T_WHITESPACE, T_WHITESPACE, T_STRING, T_OPEN_PARENTHESIS, T_CONSTANT_ENCAPSED_STRING, T_CLOSE_PARENTHESIS, T_COMMA, T_WHITESPACE, T_WHITESPACE, T_STRING, T_OPEN_PARENTHESIS, T_CONSTANT_ENCAPSED_STRING, T_COMMA, T_WHITESPACE, T_PARAM_NAME, T_COLON, T_WHITESPACE, T_OPEN_SHORT_ARRAY, T_CONSTANT_ENCAPSED_STRING, T_WHITESPACE, T_DOUBLE_ARROW, T_WHITESPACE, T_CONSTANT_ENCAPSED_STRING, T_CLOSE_SHORT_ARRAY, T_CLOSE_PARENTHESIS, T_WHITESPACE)), array("/* testFqcnAttribute */", 13, array(T_STRING, T_NS_SEPARATOR, T_STRING, T_COMMA, T_WHITESPACE, T_NS_SEPARATOR, T_STRING, T_NS_SEPARATOR, T_STRING, T_OPEN_PARENTHESIS, T_CONSTANT_ENCAPSED_STRING, T_CLOSE_PARENTHESIS))); } public function testTwoAttributesOnTheSameLine() { $tokens = self::$phpcsFile->getTokens(); $attribute = $this->getTargetToken("/* testTwoAttributeOnTheSameLine */", T_ATTRIBUTE); $this->assertArrayHasKey("attribute_closer", $tokens[$attribute]); $closer = $tokens[$attribute]["attribute_closer"]; $this->assertSame(T_WHITESPACE, $tokens[$closer + 1]["code"]); $this->assertSame(T_ATTRIBUTE, $tokens[$closer + 2]["code"]); $this->assertArrayHasKey("attribute_closer", $tokens[$closer + 2]); } public function testAttributeAndLineComment() { $tokens = self::$phpcsFile->getTokens(); $attribute = $this->getTargetToken("/* testAttributeAndCommentOnTheSameLine */", T_ATTRIBUTE); $this->assertArrayHasKey("attribute_closer", $tokens[$attribute]); $closer = $tokens[$attribute]["attribute_closer"]; $this->assertSame(T_WHITESPACE, $tokens[$closer + 1]["code"]); $this->assertSame(T_COMMENT, $tokens[$closer + 2]["code"]); } public function testAttributeOnParameters($testMarker, $position, $length, array $tokenCodes) { $tokens = self::$phpcsFile->getTokens(); $function = $this->getTargetToken($testMarker, T_FUNCTION); $attribute = $function + $position; $this->assertSame(T_ATTRIBUTE, $tokens[$attribute]["code"]); $this->assertArrayHasKey("attribute_closer", $tokens[$attribute]); $this->assertSame($attribute + $length, $tokens[$attribute]["attribute_closer"]); $closer = $tokens[$attribute]["attribute_closer"]; $this->assertSame(T_WHITESPACE, $tokens[$closer + 1]["code"]); $this->assertSame(T_STRING, $tokens[$closer + 2]["code"]); $this->assertSame("int", $tokens[$closer + 2]["content"]); $this->assertSame(T_VARIABLE, $tokens[$closer + 4]["code"]); $this->assertSame("$param", $tokens[$closer + 4]["content"]); $map = array_map(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)); $this->assertSame($tokenCodes, $map); } public function dataAttributeOnParameters() { return array(array("/* testSingleAttributeOnParameter */", 4, 2, array(T_STRING)), array("/* testMultipleAttributesOnParameter */", 4, 10, array(T_STRING, T_COMMA, T_WHITESPACE, T_STRING, T_OPEN_PARENTHESIS, T_COMMENT, T_WHITESPACE, T_CONSTANT_ENCAPSED_STRING, T_CLOSE_PARENTHESIS)), array("/* testMultilineAttributesOnParameter */", 4, 13, array(T_WHITESPACE, T_WHITESPACE, T_STRING, T_OPEN_PARENTHESIS, T_WHITESPACE, T_WHITESPACE, T_CONSTANT_ENCAPSED_STRING, T_WHITESPACE, T_WHITESPACE, T_CLOSE_PARENTHESIS, T_WHITESPACE, T_WHITESPACE))); } public function testAttributeContainingTextLookingLikeCloseTag($testMarker, $length, array $expectedTokensAttribute, array $expectedTokensAfter) { $tokens = self::$phpcsFile->getTokens(); $attribute = $this->getTargetToken($testMarker, T_ATTRIBUTE); $this->assertSame("T_ATTRIBUTE", $tokens[$attribute]["type"]); $this->assertArrayHasKey("attribute_closer", $tokens[$attribute]); $closer = $tokens[$attribute]["attribute_closer"]; $this->assertSame($attribute + $length, $closer); $this->assertSame(T_ATTRIBUTE_END, $tokens[$closer]["code"]); $this->assertSame("T_ATTRIBUTE_END", $tokens[$closer]["type"]); $this->assertSame($tokens[$attribute]["attribute_opener"], $tokens[$closer]["attribute_opener"]); $this->assertSame($tokens[$attribute]["attribute_closer"], $tokens[$closer]["attribute_closer"]); $i = $attribute + 1; foreach ($expectedTokensAttribute as $item) { list($expectedType, $expectedContents) = $item; $this->assertSame($expectedType, $tokens[$i]["type"]); $this->assertSame($expectedContents, $tokens[$i]["content"]); $this->assertArrayHasKey("attribute_opener", $tokens[$i]); $this->assertArrayHasKey("attribute_closer", $tokens[$i]); ++$i; } $i = $closer + 1; foreach ($expectedTokensAfter as $expectedCode) { $this->assertSame($expectedCode, $tokens[$i]["code"]); ++$i; } } public function dataAttributeOnTextLookingLikeCloseTag() { return array(array("/* testAttributeContainingTextLookingLikeCloseTag */", 5, array(array("T_STRING", "DeprecationReason"), array("T_OPEN_PARENTHESIS", "("), array("T_CONSTANT_ENCAPSED_STRING", "'reason: <https://some-website/reason?>'"), array("T_CLOSE_PARENTHESIS", ")"), array("T_ATTRIBUTE_END", "]")), array(T_WHITESPACE, T_FUNCTION, T_WHITESPACE, T_STRING, T_OPEN_PARENTHESIS, T_CLOSE_PARENTHESIS, T_WHITESPACE, T_OPEN_CURLY_BRACKET, T_CLOSE_CURLY_BRACKET)), array("/* testAttributeContainingMultilineTextLookingLikeCloseTag */", 8, array(array("T_STRING", "DeprecationReason"), array("T_OPEN_PARENTHESIS", "("), array("T_WHITESPACE", "
"), array("T_WHITESPACE", "    "), array("T_CONSTANT_ENCAPSED_STRING", "'reason: <https://some-website/reason?>'"), array("T_WHITESPACE", "\xa"), array("T_CLOSE_PARENTHESIS", ")"), array("T_ATTRIBUTE_END", "]")), array(T_WHITESPACE, T_FUNCTION, T_WHITESPACE, T_STRING, T_OPEN_PARENTHESIS, T_CLOSE_PARENTHESIS, T_WHITESPACE, T_OPEN_CURLY_BRACKET, T_CLOSE_CURLY_BRACKET))); } public function testInvalidAttribute() { $tokens = self::$phpcsFile->getTokens(); $attribute = $this->getTargetToken("/* testInvalidAttribute */", T_ATTRIBUTE); $this->assertArrayHasKey("attribute_closer", $tokens[$attribute]); $this->assertNull($tokens[$attribute]["attribute_closer"]); } public function testNestedAttributes() { $tokens = self::$phpcsFile->getTokens(); $tokenCodes = array(T_STRING, T_NS_SEPARATOR, T_STRING, T_OPEN_PARENTHESIS, T_FN, T_WHITESPACE, T_OPEN_PARENTHESIS, T_ATTRIBUTE, T_STRING, T_OPEN_PARENTHESIS, T_CONSTANT_ENCAPSED_STRING, T_CLOSE_PARENTHESIS, T_ATTRIBUTE_END, T_WHITESPACE, T_VARIABLE, T_CLOSE_PARENTHESIS, T_WHITESPACE, T_FN_ARROW, T_WHITESPACE, T_STRING_CAST, T_WHITESPACE, T_VARIABLE, T_CLOSE_PARENTHESIS); $attribute = $this->getTargetToken("/* testNestedAttributes */", T_ATTRIBUTE); $this->assertArrayHasKey("attribute_closer", $tokens[$attribute]); $closer = $tokens[$attribute]["attribute_closer"]; $this->assertSame($attribute + 24, $closer); $this->assertSame(T_ATTRIBUTE_END, $tokens[$closer]["code"]); $this->assertSame($tokens[$attribute]["attribute_opener"], $tokens[$closer]["attribute_opener"]); $this->assertSame($tokens[$attribute]["attribute_closer"], $tokens[$closer]["attribute_closer"]); $this->assertArrayNotHasKey("nested_attributes", $tokens[$attribute]); $this->assertArrayHasKey("nested_attributes", $tokens[$attribute + 8]); $this->assertSame(array($attribute => $attribute + 24), $tokens[$attribute + 8]["nested_attributes"]); $test = function (array $tokens, $length, $nestedMap) use($attribute) { foreach ($tokens as $token) { $this->assertArrayHasKey("attribute_closer", $token); $this->assertSame($attribute + $length, $token["attribute_closer"]); $this->assertSame($nestedMap, $token["nested_attributes"]); } }; $test(array_slice($tokens, $attribute + 1, 7), 24, array($attribute => $attribute + 24)); $test(array_slice($tokens, $attribute + 8, 1), 8 + 5, array($attribute => $attribute + 24)); $test(array_slice($tokens, $attribute + 9, 4), 8 + 5, array($attribute => $attribute + 24, $attribute + 8 => $attribute + 13)); $test(array_slice($tokens, $attribute + 13, 1), 8 + 5, array($attribute => $attribute + 24)); $test(array_slice($tokens, $attribute + 14, 10), 24, array($attribute => $attribute + 24)); $map = array_map(static function ($token) { return $token["code"]; }, array_slice($tokens, $attribute + 1, 23)); $this->assertSame($tokenCodes, $map); } } ?>

Did this file decode correctly?

Original Code

<?php
 namespace PHP_CodeSniffer\Tests\Core\Tokenizer; use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest; class AttributesTest extends AbstractMethodUnitTest { public function testAttribute($testMarker, $length, $tokenCodes) { $tokens = self::$phpcsFile->getTokens(); $attribute = $this->getTargetToken($testMarker, T_ATTRIBUTE); $this->assertArrayHasKey("\x61\164\164\162\x69\142\x75\x74\145\137\143\x6c\157\x73\x65\x72", $tokens[$attribute]); $closer = $tokens[$attribute]["\141\x74\164\x72\151\x62\165\x74\x65\x5f\x63\154\x6f\163\145\x72"]; $this->assertSame($attribute + $length, $closer); $this->assertSame(T_ATTRIBUTE_END, $tokens[$closer]["\x63\x6f\144\145"]); $this->assertSame($tokens[$attribute]["\x61\x74\164\x72\151\x62\165\x74\x65\x5f\x6f\160\x65\156\145\162"], $tokens[$closer]["\x61\164\x74\x72\x69\142\165\164\x65\x5f\x6f\x70\x65\156\x65\x72"]); $this->assertSame($tokens[$attribute]["\141\x74\x74\x72\151\142\165\164\145\137\x63\x6c\x6f\163\145\162"], $tokens[$closer]["\141\164\x74\x72\x69\x62\165\x74\145\137\x63\x6c\157\163\x65\162"]); $map = array_map(function ($token) use($attribute, $length) { $this->assertArrayHasKey("\141\x74\x74\162\151\142\165\164\x65\137\143\x6c\x6f\163\145\162", $token); $this->assertSame($attribute + $length, $token["\x61\x74\x74\162\151\142\x75\x74\145\137\x63\x6c\157\x73\x65\162"]); return $token["\143\157\144\145"]; }, array_slice($tokens, $attribute + 1, $length - 1)); $this->assertSame($tokenCodes, $map); } public function dataAttribute() { return array(array("\57\x2a\40\x74\145\163\164\x41\164\164\162\x69\142\x75\164\145\40\x2a\57", 2, array(T_STRING)), array("\57\52\40\x74\x65\163\x74\101\x74\x74\162\x69\x62\x75\164\x65\x57\x69\x74\150\120\x61\162\x61\155\x73\40\x2a\57", 7, array(T_STRING, T_OPEN_PARENTHESIS, T_STRING, T_DOUBLE_COLON, T_STRING, T_CLOSE_PARENTHESIS)), array("\57\x2a\x20\x74\x65\x73\x74\x41\x74\164\x72\151\x62\x75\164\x65\x57\151\x74\150\x4e\141\155\x65\x64\x50\x61\162\141\x6d\x20\52\57", 10, array(T_STRING, T_OPEN_PARENTHESIS, T_PARAM_NAME, T_COLON, T_WHITESPACE, T_STRING, T_DOUBLE_COLON, T_STRING, T_CLOSE_PARENTHESIS)), array("\x2f\52\40\x74\x65\x73\164\x41\x74\x74\x72\151\x62\165\164\x65\x4f\x6e\x46\x75\x6e\x63\x74\151\157\x6e\40\x2a\x2f", 2, array(T_STRING)), array("\57\x2a\x20\164\x65\163\164\x41\x74\164\162\x69\142\165\164\x65\x4f\x6e\106\x75\x6e\143\164\x69\x6f\x6e\x57\x69\x74\x68\x50\141\162\141\155\163\40\x2a\x2f", 17, array(T_STRING, T_OPEN_PARENTHESIS, T_CONSTANT_ENCAPSED_STRING, T_COMMA, T_WHITESPACE, T_PARAM_NAME, T_COLON, T_WHITESPACE, T_OPEN_SHORT_ARRAY, T_CONSTANT_ENCAPSED_STRING, T_WHITESPACE, T_DOUBLE_ARROW, T_WHITESPACE, T_CONSTANT_ENCAPSED_STRING, T_CLOSE_SHORT_ARRAY, T_CLOSE_PARENTHESIS)), array("\x2f\x2a\x20\x74\145\x73\164\x41\x74\x74\162\x69\142\x75\164\x65\x57\x69\x74\150\x53\x68\157\162\x74\x43\154\x6f\x73\165\x72\x65\x50\x61\x72\141\155\145\164\x65\x72\40\x2a\x2f", 17, array(T_STRING, T_OPEN_PARENTHESIS, T_STATIC, T_WHITESPACE, T_FN, T_WHITESPACE, T_OPEN_PARENTHESIS, T_VARIABLE, T_CLOSE_PARENTHESIS, T_WHITESPACE, T_FN_ARROW, T_WHITESPACE, T_BOOLEAN_NOT, T_WHITESPACE, T_VARIABLE, T_CLOSE_PARENTHESIS)), array("\57\x2a\x20\x74\145\163\164\101\164\x74\x72\151\142\x75\x74\145\x47\162\x6f\x75\x70\151\156\147\40\52\57", 26, array(T_STRING, T_COMMA, T_WHITESPACE, T_STRING, T_OPEN_PARENTHESIS, T_CONSTANT_ENCAPSED_STRING, T_CLOSE_PARENTHESIS, T_COMMA, T_WHITESPACE, T_STRING, T_OPEN_PARENTHESIS, T_CONSTANT_ENCAPSED_STRING, T_COMMA, T_WHITESPACE, T_PARAM_NAME, T_COLON, T_WHITESPACE, T_OPEN_SHORT_ARRAY, T_CONSTANT_ENCAPSED_STRING, T_WHITESPACE, T_DOUBLE_ARROW, T_WHITESPACE, T_CONSTANT_ENCAPSED_STRING, T_CLOSE_SHORT_ARRAY, T_CLOSE_PARENTHESIS)), array("\57\x2a\x20\164\145\x73\164\x41\x74\164\x72\151\x62\165\x74\x65\x4d\x75\x6c\x74\151\154\151\156\145\x20\x2a\x2f", 31, array(T_WHITESPACE, T_WHITESPACE, T_STRING, T_COMMA, T_WHITESPACE, T_WHITESPACE, T_STRING, T_OPEN_PARENTHESIS, T_CONSTANT_ENCAPSED_STRING, T_CLOSE_PARENTHESIS, T_COMMA, T_WHITESPACE, T_WHITESPACE, T_STRING, T_OPEN_PARENTHESIS, T_CONSTANT_ENCAPSED_STRING, T_COMMA, T_WHITESPACE, T_PARAM_NAME, T_COLON, T_WHITESPACE, T_OPEN_SHORT_ARRAY, T_CONSTANT_ENCAPSED_STRING, T_WHITESPACE, T_DOUBLE_ARROW, T_WHITESPACE, T_CONSTANT_ENCAPSED_STRING, T_CLOSE_SHORT_ARRAY, T_CLOSE_PARENTHESIS, T_WHITESPACE)), array("\x2f\x2a\40\x74\x65\x73\x74\x46\161\143\x6e\101\164\x74\162\x69\142\x75\164\145\x20\x2a\x2f", 13, array(T_STRING, T_NS_SEPARATOR, T_STRING, T_COMMA, T_WHITESPACE, T_NS_SEPARATOR, T_STRING, T_NS_SEPARATOR, T_STRING, T_OPEN_PARENTHESIS, T_CONSTANT_ENCAPSED_STRING, T_CLOSE_PARENTHESIS))); } public function testTwoAttributesOnTheSameLine() { $tokens = self::$phpcsFile->getTokens(); $attribute = $this->getTargetToken("\57\x2a\x20\164\145\x73\164\x54\167\157\101\164\164\x72\151\142\165\164\x65\117\156\x54\x68\x65\123\141\155\145\114\151\156\145\x20\x2a\x2f", T_ATTRIBUTE); $this->assertArrayHasKey("\x61\x74\x74\x72\x69\142\165\164\x65\137\143\x6c\157\163\145\162", $tokens[$attribute]); $closer = $tokens[$attribute]["\x61\164\164\162\151\x62\165\164\145\x5f\x63\154\157\x73\145\x72"]; $this->assertSame(T_WHITESPACE, $tokens[$closer + 1]["\x63\157\x64\x65"]); $this->assertSame(T_ATTRIBUTE, $tokens[$closer + 2]["\143\157\x64\x65"]); $this->assertArrayHasKey("\x61\164\x74\x72\151\142\x75\164\145\137\143\154\157\163\145\x72", $tokens[$closer + 2]); } public function testAttributeAndLineComment() { $tokens = self::$phpcsFile->getTokens(); $attribute = $this->getTargetToken("\57\52\x20\164\x65\x73\x74\x41\164\164\x72\x69\142\165\164\x65\101\x6e\144\x43\x6f\x6d\155\145\156\x74\x4f\156\124\x68\x65\x53\141\155\x65\x4c\x69\x6e\145\40\x2a\x2f", T_ATTRIBUTE); $this->assertArrayHasKey("\141\x74\164\x72\x69\x62\165\164\x65\137\143\154\x6f\x73\145\162", $tokens[$attribute]); $closer = $tokens[$attribute]["\x61\x74\x74\x72\151\x62\x75\164\145\x5f\x63\x6c\x6f\x73\145\162"]; $this->assertSame(T_WHITESPACE, $tokens[$closer + 1]["\143\x6f\x64\x65"]); $this->assertSame(T_COMMENT, $tokens[$closer + 2]["\x63\157\x64\x65"]); } public function testAttributeOnParameters($testMarker, $position, $length, array $tokenCodes) { $tokens = self::$phpcsFile->getTokens(); $function = $this->getTargetToken($testMarker, T_FUNCTION); $attribute = $function + $position; $this->assertSame(T_ATTRIBUTE, $tokens[$attribute]["\143\x6f\x64\x65"]); $this->assertArrayHasKey("\141\x74\x74\x72\x69\142\165\164\145\x5f\x63\154\157\x73\x65\162", $tokens[$attribute]); $this->assertSame($attribute + $length, $tokens[$attribute]["\x61\x74\x74\x72\151\142\x75\x74\x65\x5f\x63\x6c\x6f\163\145\x72"]); $closer = $tokens[$attribute]["\141\164\164\162\x69\142\165\164\145\137\x63\154\x6f\163\x65\162"]; $this->assertSame(T_WHITESPACE, $tokens[$closer + 1]["\143\x6f\x64\x65"]); $this->assertSame(T_STRING, $tokens[$closer + 2]["\x63\157\x64\x65"]); $this->assertSame("\x69\x6e\164", $tokens[$closer + 2]["\143\x6f\156\x74\x65\x6e\x74"]); $this->assertSame(T_VARIABLE, $tokens[$closer + 4]["\x63\157\144\x65"]); $this->assertSame("\x24\160\x61\x72\141\x6d", $tokens[$closer + 4]["\143\x6f\156\164\145\156\x74"]); $map = array_map(function ($token) use($attribute, $length) { $this->assertArrayHasKey("\x61\x74\x74\162\151\x62\165\x74\x65\x5f\143\x6c\157\163\x65\162", $token); $this->assertSame($attribute + $length, $token["\x61\164\164\x72\x69\x62\x75\164\145\x5f\x63\154\x6f\x73\145\162"]); return $token["\x63\157\x64\145"]; }, array_slice($tokens, $attribute + 1, $length - 1)); $this->assertSame($tokenCodes, $map); } public function dataAttributeOnParameters() { return array(array("\57\52\x20\164\x65\x73\164\123\151\x6e\x67\x6c\145\x41\x74\x74\162\x69\x62\x75\x74\145\117\156\120\141\x72\141\155\x65\x74\145\162\x20\52\x2f", 4, 2, array(T_STRING)), array("\57\x2a\40\164\145\163\164\115\x75\x6c\x74\151\160\154\145\101\164\x74\x72\151\x62\165\x74\x65\163\x4f\x6e\120\141\x72\x61\x6d\145\164\145\x72\40\52\x2f", 4, 10, array(T_STRING, T_COMMA, T_WHITESPACE, T_STRING, T_OPEN_PARENTHESIS, T_COMMENT, T_WHITESPACE, T_CONSTANT_ENCAPSED_STRING, T_CLOSE_PARENTHESIS)), array("\57\52\x20\164\x65\163\164\115\165\x6c\164\x69\x6c\x69\x6e\x65\101\164\x74\162\151\x62\165\x74\145\163\x4f\x6e\x50\x61\162\141\155\145\x74\145\162\40\52\x2f", 4, 13, array(T_WHITESPACE, T_WHITESPACE, T_STRING, T_OPEN_PARENTHESIS, T_WHITESPACE, T_WHITESPACE, T_CONSTANT_ENCAPSED_STRING, T_WHITESPACE, T_WHITESPACE, T_CLOSE_PARENTHESIS, T_WHITESPACE, T_WHITESPACE))); } public function testAttributeContainingTextLookingLikeCloseTag($testMarker, $length, array $expectedTokensAttribute, array $expectedTokensAfter) { $tokens = self::$phpcsFile->getTokens(); $attribute = $this->getTargetToken($testMarker, T_ATTRIBUTE); $this->assertSame("\x54\x5f\101\124\124\122\111\x42\125\x54\105", $tokens[$attribute]["\x74\x79\x70\145"]); $this->assertArrayHasKey("\x61\x74\164\x72\151\x62\x75\164\145\137\143\154\157\x73\x65\x72", $tokens[$attribute]); $closer = $tokens[$attribute]["\141\164\x74\x72\x69\142\165\x74\145\137\143\x6c\157\163\145\x72"]; $this->assertSame($attribute + $length, $closer); $this->assertSame(T_ATTRIBUTE_END, $tokens[$closer]["\x63\x6f\x64\x65"]); $this->assertSame("\x54\x5f\x41\x54\x54\122\111\102\125\x54\x45\137\x45\x4e\104", $tokens[$closer]["\x74\x79\160\x65"]); $this->assertSame($tokens[$attribute]["\x61\x74\x74\x72\151\x62\165\164\x65\137\x6f\x70\x65\x6e\145\x72"], $tokens[$closer]["\141\164\164\x72\151\x62\x75\x74\x65\137\157\160\x65\156\145\162"]); $this->assertSame($tokens[$attribute]["\x61\x74\164\162\x69\142\165\164\x65\137\x63\154\157\x73\145\x72"], $tokens[$closer]["\141\164\x74\162\x69\142\x75\164\145\x5f\143\x6c\x6f\x73\x65\x72"]); $i = $attribute + 1; foreach ($expectedTokensAttribute as $item) { list($expectedType, $expectedContents) = $item; $this->assertSame($expectedType, $tokens[$i]["\x74\171\x70\145"]); $this->assertSame($expectedContents, $tokens[$i]["\143\157\156\x74\x65\156\x74"]); $this->assertArrayHasKey("\x61\164\164\162\x69\x62\165\164\x65\x5f\157\160\x65\156\145\x72", $tokens[$i]); $this->assertArrayHasKey("\141\164\164\162\x69\142\165\x74\x65\137\x63\x6c\x6f\x73\145\162", $tokens[$i]); ++$i; } $i = $closer + 1; foreach ($expectedTokensAfter as $expectedCode) { $this->assertSame($expectedCode, $tokens[$i]["\143\157\144\x65"]); ++$i; } } public function dataAttributeOnTextLookingLikeCloseTag() { return array(array("\57\52\x20\164\x65\163\x74\101\164\x74\x72\x69\142\x75\x74\145\x43\x6f\156\164\x61\x69\x6e\151\156\x67\x54\x65\x78\164\114\157\x6f\x6b\x69\156\x67\114\151\153\x65\103\x6c\x6f\163\x65\124\x61\x67\x20\x2a\57", 5, array(array("\x54\x5f\x53\x54\122\111\x4e\x47", "\x44\x65\x70\162\145\143\x61\164\x69\157\x6e\x52\145\x61\x73\x6f\156"), array("\124\137\117\x50\x45\116\137\120\101\122\105\x4e\124\110\105\x53\x49\x53", "\x28"), array("\124\x5f\x43\x4f\x4e\123\124\101\x4e\x54\x5f\x45\x4e\103\x41\120\123\x45\104\137\123\x54\122\x49\116\x47", "\x27\162\145\x61\163\x6f\156\72\40\x3c\150\x74\x74\x70\x73\72\57\57\163\157\x6d\145\55\x77\x65\142\x73\x69\164\x65\x2f\x72\x65\x61\163\x6f\x6e\x3f\x3e\47"), array("\x54\137\103\x4c\x4f\123\105\137\120\101\x52\x45\x4e\x54\110\x45\123\111\123", "\x29"), array("\x54\x5f\101\x54\124\122\x49\102\x55\124\105\x5f\x45\x4e\104", "\135")), array(T_WHITESPACE, T_FUNCTION, T_WHITESPACE, T_STRING, T_OPEN_PARENTHESIS, T_CLOSE_PARENTHESIS, T_WHITESPACE, T_OPEN_CURLY_BRACKET, T_CLOSE_CURLY_BRACKET)), array("\57\x2a\x20\x74\x65\x73\164\101\164\164\162\151\142\165\x74\145\x43\x6f\156\x74\141\151\156\151\156\x67\x4d\165\154\x74\x69\154\x69\156\x65\x54\x65\x78\x74\114\157\157\x6b\x69\x6e\147\114\151\153\x65\x43\x6c\157\x73\x65\124\x61\x67\40\x2a\x2f", 8, array(array("\124\x5f\x53\124\122\111\116\x47", "\x44\x65\x70\x72\145\143\141\164\x69\157\156\x52\145\x61\x73\x6f\156"), array("\x54\x5f\117\120\105\116\137\x50\101\x52\x45\x4e\124\x48\x45\x53\x49\123", "\x28"), array("\124\137\127\110\111\x54\105\x53\x50\101\103\105", "\12"), array("\124\x5f\x57\110\111\x54\105\x53\x50\101\x43\x45", "\40\40\40\40"), array("\x54\x5f\x43\x4f\x4e\x53\x54\101\116\124\137\x45\116\x43\x41\120\123\105\x44\137\123\124\x52\111\x4e\x47", "\47\162\145\141\163\x6f\x6e\x3a\40\74\150\x74\x74\x70\x73\x3a\57\x2f\163\157\x6d\145\55\167\145\x62\163\x69\x74\145\x2f\x72\145\141\163\x6f\156\77\76\47"), array("\x54\x5f\x57\x48\x49\x54\x45\123\x50\101\x43\x45", "\xa"), array("\x54\137\103\114\x4f\x53\105\x5f\120\101\x52\x45\116\124\x48\105\123\x49\123", "\51"), array("\124\137\101\x54\x54\122\111\x42\125\124\105\x5f\105\116\x44", "\135")), array(T_WHITESPACE, T_FUNCTION, T_WHITESPACE, T_STRING, T_OPEN_PARENTHESIS, T_CLOSE_PARENTHESIS, T_WHITESPACE, T_OPEN_CURLY_BRACKET, T_CLOSE_CURLY_BRACKET))); } public function testInvalidAttribute() { $tokens = self::$phpcsFile->getTokens(); $attribute = $this->getTargetToken("\57\52\40\164\145\163\164\x49\156\166\x61\x6c\x69\144\101\x74\164\x72\151\x62\165\x74\145\x20\52\x2f", T_ATTRIBUTE); $this->assertArrayHasKey("\141\x74\164\162\x69\x62\x75\x74\x65\137\143\154\x6f\163\x65\162", $tokens[$attribute]); $this->assertNull($tokens[$attribute]["\141\164\x74\162\x69\x62\165\x74\x65\x5f\143\x6c\x6f\163\x65\162"]); } public function testNestedAttributes() { $tokens = self::$phpcsFile->getTokens(); $tokenCodes = array(T_STRING, T_NS_SEPARATOR, T_STRING, T_OPEN_PARENTHESIS, T_FN, T_WHITESPACE, T_OPEN_PARENTHESIS, T_ATTRIBUTE, T_STRING, T_OPEN_PARENTHESIS, T_CONSTANT_ENCAPSED_STRING, T_CLOSE_PARENTHESIS, T_ATTRIBUTE_END, T_WHITESPACE, T_VARIABLE, T_CLOSE_PARENTHESIS, T_WHITESPACE, T_FN_ARROW, T_WHITESPACE, T_STRING_CAST, T_WHITESPACE, T_VARIABLE, T_CLOSE_PARENTHESIS); $attribute = $this->getTargetToken("\57\x2a\40\x74\x65\x73\164\x4e\x65\163\164\x65\x64\x41\164\x74\x72\x69\x62\165\164\145\163\x20\x2a\x2f", T_ATTRIBUTE); $this->assertArrayHasKey("\x61\164\x74\x72\151\142\x75\164\x65\137\143\x6c\x6f\163\x65\162", $tokens[$attribute]); $closer = $tokens[$attribute]["\141\x74\x74\162\x69\x62\165\x74\145\x5f\x63\x6c\x6f\163\145\x72"]; $this->assertSame($attribute + 24, $closer); $this->assertSame(T_ATTRIBUTE_END, $tokens[$closer]["\x63\x6f\144\145"]); $this->assertSame($tokens[$attribute]["\141\164\x74\x72\x69\142\165\164\145\137\x6f\160\x65\156\x65\162"], $tokens[$closer]["\x61\x74\164\162\x69\142\165\x74\x65\x5f\157\160\x65\x6e\x65\x72"]); $this->assertSame($tokens[$attribute]["\x61\164\x74\x72\x69\142\165\164\145\x5f\x63\154\x6f\163\145\x72"], $tokens[$closer]["\x61\164\164\x72\151\x62\165\x74\x65\x5f\143\154\x6f\x73\145\162"]); $this->assertArrayNotHasKey("\156\x65\163\164\x65\144\137\x61\164\x74\162\x69\142\x75\x74\145\x73", $tokens[$attribute]); $this->assertArrayHasKey("\x6e\145\x73\x74\x65\x64\x5f\x61\164\164\x72\151\x62\165\x74\x65\163", $tokens[$attribute + 8]); $this->assertSame(array($attribute => $attribute + 24), $tokens[$attribute + 8]["\x6e\145\x73\164\x65\x64\x5f\x61\164\164\x72\151\x62\x75\x74\x65\163"]); $test = function (array $tokens, $length, $nestedMap) use($attribute) { foreach ($tokens as $token) { $this->assertArrayHasKey("\x61\x74\164\162\151\142\x75\164\x65\137\x63\x6c\157\x73\x65\162", $token); $this->assertSame($attribute + $length, $token["\141\x74\164\x72\x69\142\165\x74\145\137\143\x6c\x6f\x73\145\x72"]); $this->assertSame($nestedMap, $token["\156\x65\163\164\x65\144\137\x61\164\164\162\x69\x62\165\164\x65\163"]); } }; $test(array_slice($tokens, $attribute + 1, 7), 24, array($attribute => $attribute + 24)); $test(array_slice($tokens, $attribute + 8, 1), 8 + 5, array($attribute => $attribute + 24)); $test(array_slice($tokens, $attribute + 9, 4), 8 + 5, array($attribute => $attribute + 24, $attribute + 8 => $attribute + 13)); $test(array_slice($tokens, $attribute + 13, 1), 8 + 5, array($attribute => $attribute + 24)); $test(array_slice($tokens, $attribute + 14, 10), 24, array($attribute => $attribute + 24)); $map = array_map(static function ($token) { return $token["\x63\x6f\144\x65"]; }, array_slice($tokens, $attribute + 1, 23)); $this->assertSame($tokenCodes, $map); } }

Function Calls

None

Variables

None

Stats

MD5 3fa5eb57ea3a1972d4ef136fcf9db8d7
Eval Count 0
Decode Time 121 ms