diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 4ac7b44100..f93819d569 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -13,7 +13,7 @@ rules: - pocketmine\phpstan\rules\DisallowDynamicNewRule - pocketmine\phpstan\rules\DisallowForeachByReferenceRule - pocketmine\phpstan\rules\ExplodeLimitRule - - pocketmine\phpstan\rules\UnsafeForeachArrayOfStringRule + - pocketmine\phpstan\rules\UnsafeForeachArrayWithStringKeysRule # - pocketmine\phpstan\rules\ThreadedSupportedTypesRule parameters: diff --git a/src/crash/CrashDump.php b/src/crash/CrashDump.php index 49a587c34c..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; @@ -259,10 +258,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 89584556ab..07f4024234 100644 --- a/src/plugin/PluginBase.php +++ b/src/plugin/PluginBase.php @@ -58,7 +58,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, @@ -66,7 +65,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), "/") . "/"; @@ -301,14 +299,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; 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;