From c2c8992dd029dcdf9c644a37cfc75a5bb77b1b22 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Fri, 28 Mar 2025 12:26:14 +0100 Subject: [PATCH] PHPStan: Fix errors in Plugins --- adminer/include/plugins.inc.php | 17 +++++++++++------ phpstan.neon | 3 --- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/adminer/include/plugins.inc.php b/adminer/include/plugins.inc.php index caa4f932..3454a1e0 100644 --- a/adminer/include/plugins.inc.php +++ b/adminer/include/plugins.inc.php @@ -2,11 +2,12 @@ namespace Adminer; class Plugins { + /** @var true[] */ private static array $append = array('dumpFormat' => true, 'dumpOutput' => true, 'editRowPrint' => true, 'editFunctions' => true); // these hooks expect the value to be appended to the result + /** @var list @visibility protected(set) */ public array $plugins; /** @visibility protected(set) */ public string $error = ''; // HTML - public $operators; //! delete - private $hooks = array(); - private $append; + /** @var ?list */ public ?array $operators; //! delete + /** @var list[] */ private array $hooks = array(); /** Register plugins * @param ?list $plugins object instances or null to autoload plugins from adminer-plugins/ @@ -45,7 +46,6 @@ class Plugins { } } $this->plugins = $plugins; - $this->append = array_flip(array('dumpFormat', 'dumpOutput', 'editRowPrint', 'editFunctions')); // these hooks expect the value to be appended to the result $adminer = new Adminer; $plugins[] = $adminer; @@ -60,7 +60,12 @@ class Plugins { } } - function __call($name, $params) { + /** + * @param literal-string $name + * @param mixed[] $params + * @return mixed + */ + function __call($name, array $params) { $args = array(); foreach ($params as $key => $val) { // some plugins accept params by reference - we don't need to propage it outside, just to the other plugins @@ -70,7 +75,7 @@ class Plugins { foreach ($this->hooks[$name] as $plugin) { $value = call_user_func_array(array($plugin, $name), $args); if ($value !== null) { - if (!isset($this->append[$name])) { // non-null value from non-appending method short-circuits the other plugins + if (!self::$append[$name]) { // non-null value from non-appending method short-circuits the other plugins return $value; } $return = $value + (array) $return; diff --git a/phpstan.neon b/phpstan.neon index 2b931b35..4769dde5 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -13,7 +13,6 @@ parameters: - "~^Function (set_magic_quotes_runtime|mysql_)~" # PHP < 7 functions - "~an unknown class OCI-?Lob~" # this looks like PHPStan bug - "~^Variable \\$(adminer|connection|driver|drivers|error|HTTPS|LANG|langs|permanent|has_token|token|translations|VERSION) might not be defined~" # declared in bootstrap.inc.php - - "~^Method Adminer\\\\Plugins::\\w+\\(\\) with return type void~" # we use the same pattern for all methods - "~expects int, float given~" # this will work - "~expects bool~" # truthy values - "~fread expects int<1, max>, 100000~" # 1e6 @@ -38,8 +37,6 @@ parameters: - identifier: booleanAnd.leftAlwaysTrue - identifier: booleanAnd.rightAlwaysTrue - identifier: booleanAnd.rightAlwaysFalse - - identifier: booleanOr.alwaysTrue - - identifier: booleanOr.leftAlwaysTrue - identifier: ternary.alwaysTrue - identifier: if.alwaysTrue - identifier: while.alwaysTrue