From 6bf9a305de7d722d15736f379cac944a5310ebee Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 3 May 2025 19:23:50 +0100 Subject: [PATCH 1/4] Rename confusing PHPStan rule name it never occurred to me that this was misleading until I read some Devin documentation, noticed that Devin misunderstood was the class was for, and then realized actually Devin understood correctly, and it was the name of the class that was wrong. Funny how that happens... --- phpstan.neon.dist | 2 +- tests/phpstan/configs/phpstan-bugs.neon | 2 +- ...fStringRule.php => UnsafeForeachArrayWithStringKeysRule.php} | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename tests/phpstan/rules/{UnsafeForeachArrayOfStringRule.php => UnsafeForeachArrayWithStringKeysRule.php} (98%) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 13f35c1218..391f0f54cd 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -15,7 +15,7 @@ rules: - pocketmine\phpstan\rules\DisallowEnumComparisonRule - pocketmine\phpstan\rules\DisallowForeachByReferenceRule - pocketmine\phpstan\rules\ExplodeLimitRule - - pocketmine\phpstan\rules\UnsafeForeachArrayOfStringRule + - pocketmine\phpstan\rules\UnsafeForeachArrayWithStringKeysRule # - pocketmine\phpstan\rules\ThreadedSupportedTypesRule parameters: diff --git a/tests/phpstan/configs/phpstan-bugs.neon b/tests/phpstan/configs/phpstan-bugs.neon index aeb3fae29f..cb92bf9682 100644 --- a/tests/phpstan/configs/phpstan-bugs.neon +++ b/tests/phpstan/configs/phpstan-bugs.neon @@ -256,5 +256,5 @@ parameters: message: '#^Strict comparison using \=\=\= between 0 and 0 will always evaluate to true\.$#' identifier: identical.alwaysTrue count: 1 - path: ../rules/UnsafeForeachArrayOfStringRule.php + path: ../rules/UnsafeForeachArrayWithStringKeysRule.php diff --git a/tests/phpstan/rules/UnsafeForeachArrayOfStringRule.php b/tests/phpstan/rules/UnsafeForeachArrayWithStringKeysRule.php similarity index 98% rename from tests/phpstan/rules/UnsafeForeachArrayOfStringRule.php rename to tests/phpstan/rules/UnsafeForeachArrayWithStringKeysRule.php index 34056131b5..83f47f092d 100644 --- a/tests/phpstan/rules/UnsafeForeachArrayOfStringRule.php +++ b/tests/phpstan/rules/UnsafeForeachArrayWithStringKeysRule.php @@ -41,7 +41,7 @@ use function sprintf; /** * @implements Rule */ -final class UnsafeForeachArrayOfStringRule implements Rule{ +final class UnsafeForeachArrayWithStringKeysRule implements Rule{ public function getNodeType() : string{ return Foreach_::class; From 2a42e2c75d1c1b92d17559833899ce35940da269 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 4 May 2025 16:41:40 +0100 Subject: [PATCH 2/4] Drop PluginLoader from Plugin, expose path instead we already had this anyway, and it's already being reflected into. Instead of DevTools checking for FolderPluginLoader instances, it could just check if the file is a directory instead. --- src/crash/CrashDump.php | 4 +--- src/plugin/Plugin.php | 4 ++-- src/plugin/PluginBase.php | 7 +------ src/plugin/PluginManager.php | 2 +- 4 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/crash/CrashDump.php b/src/crash/CrashDump.php index 49a587c34c..df7c9199d9 100644 --- a/src/crash/CrashDump.php +++ b/src/crash/CrashDump.php @@ -259,10 +259,8 @@ class CrashDump{ } if(file_exists($filePath)){ - $reflection = new \ReflectionClass(PluginBase::class); - $file = $reflection->getProperty("file"); foreach($this->server->getPluginManager()->getPlugins() as $plugin){ - $filePath = Filesystem::cleanPath($file->getValue($plugin)); + $filePath = Filesystem::cleanPath($plugin->getFile()); if(str_starts_with($frameCleanPath, $filePath)){ $this->data->plugin = $plugin->getName(); break; diff --git a/src/plugin/Plugin.php b/src/plugin/Plugin.php index ae64d443b9..b71e3f5fb0 100644 --- a/src/plugin/Plugin.php +++ b/src/plugin/Plugin.php @@ -34,7 +34,7 @@ use pocketmine\Server; */ interface Plugin{ - public function __construct(PluginLoader $loader, Server $server, PluginDescription $description, string $dataFolder, string $file, string $resourceFolder); + public function __construct(Server $server, PluginDescription $description, string $dataFolder, string $file, string $resourceFolder); public function isEnabled() : bool; @@ -59,7 +59,7 @@ interface Plugin{ public function getLogger() : \AttachableLogger; - public function getPluginLoader() : PluginLoader; + public function getFile() : string; public function getScheduler() : TaskScheduler; diff --git a/src/plugin/PluginBase.php b/src/plugin/PluginBase.php index a32339e84e..727e935910 100644 --- a/src/plugin/PluginBase.php +++ b/src/plugin/PluginBase.php @@ -59,7 +59,6 @@ abstract class PluginBase implements Plugin, CommandExecutor{ private TaskScheduler $scheduler; public function __construct( - private PluginLoader $loader, private Server $server, private PluginDescription $description, private string $dataFolder, @@ -311,14 +310,10 @@ abstract class PluginBase implements Plugin, CommandExecutor{ return $this->description->getFullName(); } - protected function getFile() : string{ + public function getFile() : string{ return $this->file; } - public function getPluginLoader() : PluginLoader{ - return $this->loader; - } - public function getScheduler() : TaskScheduler{ return $this->scheduler; } diff --git a/src/plugin/PluginManager.php b/src/plugin/PluginManager.php index 1a74b64e75..3750af3ef8 100644 --- a/src/plugin/PluginManager.php +++ b/src/plugin/PluginManager.php @@ -220,7 +220,7 @@ class PluginManager{ * @var Plugin $plugin * @see Plugin::__construct() */ - $plugin = new $mainClass($loader, $this->server, $description, $dataFolder, $prefixed, $prefixed . "/resources/"); + $plugin = new $mainClass($this->server, $description, $dataFolder, $prefixed, $prefixed . "/resources/"); $this->plugins[$plugin->getDescription()->getName()] = $plugin; return $plugin; From 912a5d6ad0cc8a0cbe407557bd483234b17af7a6 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 4 May 2025 16:45:25 +0100 Subject: [PATCH 3/4] Remove TODO --- src/plugin/PluginBase.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plugin/PluginBase.php b/src/plugin/PluginBase.php index 727e935910..3b401d44a8 100644 --- a/src/plugin/PluginBase.php +++ b/src/plugin/PluginBase.php @@ -66,7 +66,6 @@ abstract class PluginBase implements Plugin, CommandExecutor{ private string $resourceFolder, ){ $this->dataFolder = rtrim($dataFolder, "/" . DIRECTORY_SEPARATOR) . "/"; - //TODO: this is accessed externally via reflection, not unused $this->file = rtrim($file, "/" . DIRECTORY_SEPARATOR) . "/"; $this->resourceFolder = rtrim(str_replace(DIRECTORY_SEPARATOR, "/", $resourceFolder), "/") . "/"; From eb3922fc7e9e847ef59427d3aa833ff15781d8a2 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 4 May 2025 17:10:01 +0100 Subject: [PATCH 4/4] shut --- src/crash/CrashDump.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/crash/CrashDump.php b/src/crash/CrashDump.php index df7c9199d9..15c48c7a77 100644 --- a/src/crash/CrashDump.php +++ b/src/crash/CrashDump.php @@ -26,7 +26,6 @@ namespace pocketmine\crash; use Composer\InstalledVersions; use pocketmine\errorhandler\ErrorTypeToStringMap; use pocketmine\network\mcpe\protocol\ProtocolInfo; -use pocketmine\plugin\PluginBase; use pocketmine\plugin\PluginManager; use pocketmine\Server; use pocketmine\thread\ThreadCrashInfoFrame;