diff --git a/src/pocketmine/plugin/ScriptPluginLoader.php b/src/pocketmine/plugin/ScriptPluginLoader.php index 5f8b083bf..f446be72c 100644 --- a/src/pocketmine/plugin/ScriptPluginLoader.php +++ b/src/pocketmine/plugin/ScriptPluginLoader.php @@ -23,13 +23,14 @@ declare(strict_types=1); namespace pocketmine\plugin; +use pocketmine\utils\Utils; +use function count; use function file; +use function implode; use function is_file; -use function preg_match; use function strlen; use function strpos; use function substr; -use function trim; use const FILE_IGNORE_NEW_LINES; use const FILE_SKIP_EMPTY_LINES; @@ -60,9 +61,9 @@ class ScriptPluginLoader implements PluginLoader{ return null; } - $data = []; - $insideHeader = false; + + $docCommentLines = []; foreach($content as $line){ if(!$insideHeader){ if(strpos($line, "/**") !== false){ @@ -72,22 +73,15 @@ class ScriptPluginLoader implements PluginLoader{ } } - if(preg_match("/^[ \t]+\\*[ \t]+@([a-zA-Z]+)([ \t]+(.*))?$/", $line, $matches) > 0){ - $key = $matches[1]; - $content = trim($matches[3] ?? ""); - - if($key === "notscript"){ - return null; - } - - $data[$key] = $content; - } + $docCommentLines[] = $line; if(strpos($line, "*/") !== false){ break; } } - if($insideHeader){ + + $data = Utils::parseDocComment(implode("\n", $docCommentLines)); + if(count($data) !== 0){ return new PluginDescription($data); } diff --git a/tests/phpstan/configs/phpstan-bugs.neon b/tests/phpstan/configs/phpstan-bugs.neon index fdc5a57df..cc4842e75 100644 --- a/tests/phpstan/configs/phpstan-bugs.neon +++ b/tests/phpstan/configs/phpstan-bugs.neon @@ -80,6 +80,11 @@ parameters: count: 1 path: ../../../src/pocketmine/network/mcpe/protocol/DataPacket.php + - + message: "#^Parameter \\#1 \\$yamlString of class pocketmine\\\\plugin\\\\PluginDescription constructor expects array\\|string, array\\ given\\.$#" + count: 1 + path: ../../../src/pocketmine/plugin/ScriptPluginLoader.php + - message: "#^Dead catch \\- ReflectionException is never thrown in the try block\\.$#" count: 2