1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-05 14:17:26 +02:00

PHPStan: Fix errors in Plugins

This commit is contained in:
Jakub Vrana
2025-03-28 12:26:14 +01:00
parent a691bcbf15
commit c2c8992dd0
2 changed files with 11 additions and 9 deletions

View 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;

View 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