]> git.joonet.de Git - adminer.git/commitdiff
PHPStan: Fix errors in Plugins
authorJakub Vrana <jakub@vrana.cz>
Fri, 28 Mar 2025 11:26:14 +0000 (12:26 +0100)
committerJakub Vrana <jakub@vrana.cz>
Fri, 28 Mar 2025 11:47:09 +0000 (12:47 +0100)
adminer/include/plugins.inc.php
phpstan.neon

index caa4f932bd41bb6a37e3382eb764b3812d1144d9..3454a1e0b6bd7c9d7a225b335d441cbdeba9df95 100644 (file)
@@ -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<object> @visibility protected(set) */ public array $plugins;
        /** @visibility protected(set) */ public string $error = ''; // HTML
-       public $operators; //! delete
-       private $hooks = array();
-       private $append;
+       /** @var ?list<string> */ public ?array $operators; //! delete
+       /** @var list<object>[] */ private array $hooks = array();
 
        /** Register plugins
        * @param ?list<object> $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;
index 2b931b35801856fbeb67978f4c9fabdc28a73048..4769dde5bdfe9eecfc8597feae90f75811861068 100644 (file)
@@ -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