mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-23 00:55:57 +00:00
* Utils: fix parsing of single-line doc comments, closes #3388 * correctly handle the empty doc-comment case, add another test case * ignore an extra phpstan bug
This commit is contained in:
parent
84932ce908
commit
ef97c8f99e
@ -662,7 +662,11 @@ class Utils{
|
||||
* @return string[] an array of tagName => tag value. If the tag has no value, an empty string is used as the value.
|
||||
*/
|
||||
public static function parseDocComment(string $docComment) : array{
|
||||
preg_match_all('/(*ANYCRLF)^[\t ]*\* @([a-zA-Z]+)(?:[\t ]+(.+))?[\t ]*$/m', $docComment, $matches);
|
||||
$rawDocComment = substr($docComment, 3, -2); //remove the opening and closing markers
|
||||
if($rawDocComment === false){ //usually empty doc comment, but this is safer and statically analysable
|
||||
return [];
|
||||
}
|
||||
preg_match_all('/(*ANYCRLF)^[\t ]*(?:\* )?@([a-zA-Z]+)(?:[\t ]+(.+?))?[\t ]*$/m', $rawDocComment, $matches);
|
||||
|
||||
return array_combine($matches[1], $matches[2]);
|
||||
}
|
||||
|
@ -130,6 +130,11 @@ parameters:
|
||||
count: 1
|
||||
path: ../../../src/pocketmine/network/mcpe/protocol/DataPacket.php
|
||||
|
||||
-
|
||||
message: "#^Strict comparison using \\=\\=\\= between string and false will always evaluate to false\\.$#"
|
||||
count: 1
|
||||
path: ../../../src/pocketmine/utils/Utils.php
|
||||
|
||||
-
|
||||
message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNotNull\\(\\) with int and string will always evaluate to true\\.$#"
|
||||
count: 1
|
||||
|
@ -63,6 +63,32 @@ class UtilsTest extends TestCase{
|
||||
self::assertEquals("HIGHEST", $tags["priority"]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[][]
|
||||
* @phpstan-return list<array{string}>
|
||||
*/
|
||||
public function parseDocCommentOneLineProvider() : array{
|
||||
return [
|
||||
["/** @ignoreCancelled true dummy */"],
|
||||
["/**@ignoreCancelled true dummy*/"],
|
||||
["/** @ignoreCancelled true dummy */"]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider parseDocCommentOneLineProvider
|
||||
*/
|
||||
public function testParseOneLineDocComment(string $comment) : void{
|
||||
$tags = Utils::parseDocComment($comment);
|
||||
self::assertArrayHasKey("ignoreCancelled", $tags);
|
||||
self::assertEquals("true dummy", $tags["ignoreCancelled"]);
|
||||
}
|
||||
|
||||
public function testParseEmptyDocComment() : void{
|
||||
$tags = Utils::parseDocComment("");
|
||||
self::assertCount(0, $tags);
|
||||
}
|
||||
|
||||
public function testNamespacedNiceClosureName() : void{
|
||||
//be careful with this test. The closure has to be declared on the same line as the assertion.
|
||||
self::assertSame('closure@' . Utils::cleanPath(__FILE__) . '#L' . __LINE__, Utils::getNiceClosureName(function() : void{}));
|
||||
|
Loading…
x
Reference in New Issue
Block a user