From 8a5b79d8883d07605776e022bb40379c93ca293a Mon Sep 17 00:00:00 2001 From: Rom1-B Date: Thu, 20 Mar 2025 13:17:20 +0100 Subject: [PATCH] phpstan level 5 --- composer.json | 9 +- composer.lock | 134 ++++++++++++++++++++---- inc/container.class.php | 8 +- inc/containerdisplaycondition.class.php | 4 +- inc/field.class.php | 4 +- inc/labeltranslation.class.php | 4 +- inc/profile.class.php | 4 +- inc/statusoverride.class.php | 4 +- setup.php | 2 +- 9 files changed, 137 insertions(+), 36 deletions(-) diff --git a/composer.json b/composer.json index 4a55c077..953287a1 100644 --- a/composer.json +++ b/composer.json @@ -7,13 +7,18 @@ "friendsofphp/php-cs-fixer": "^3.70", "glpi-project/tools": "^0.7.4", "php-parallel-lint/php-parallel-lint": "^1.4", - "phpstan/phpstan": "^2.1" + "phpstan/extension-installer": "^1.4", + "phpstan/phpstan": "^2.1", + "phpstan/phpstan-deprecation-rules": "^2.0" }, "config": { "optimize-autoloader": true, "platform": { "php": "7.4.0" }, - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "phpstan/extension-installer": true + } } } diff --git a/composer.lock b/composer.lock index 46baee26..1b85fa07 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d1ba919bc14cf081d7308798a92be93f", + "content-hash": "ad7193a3d1c81feb9e66e3f471645fd8", "packages": [ { "name": "symfony/deprecation-contracts", @@ -629,16 +629,16 @@ }, { "name": "friendsofphp/php-cs-fixer", - "version": "v3.70.0", + "version": "v3.73.1", "source": { "type": "git", "url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git", - "reference": "2ecd5aae0edc937f0d5aa4a22d1d705c6b2e084e" + "reference": "ffcb8200a42045e65049af7910cfd022f631b064" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/2ecd5aae0edc937f0d5aa4a22d1d705c6b2e084e", - "reference": "2ecd5aae0edc937f0d5aa4a22d1d705c6b2e084e", + "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/ffcb8200a42045e65049af7910cfd022f631b064", + "reference": "ffcb8200a42045e65049af7910cfd022f631b064", "shasum": "" }, "require": { @@ -646,6 +646,7 @@ "composer/semver": "^3.4", "composer/xdebug-handler": "^3.0.3", "ext-filter": "*", + "ext-hash": "*", "ext-json": "*", "ext-tokenizer": "*", "fidry/cpu-core-counter": "^1.2", @@ -668,18 +669,18 @@ "symfony/stopwatch": "^5.4 || ^6.4 || ^7.0" }, "require-dev": { - "facile-it/paraunit": "^1.3.1 || ^2.5", - "infection/infection": "^0.29.10", - "justinrainbow/json-schema": "^5.3 || ^6.0", + "facile-it/paraunit": "^1.3.1 || ^2.6", + "infection/infection": "^0.29.14", + "justinrainbow/json-schema": "^5.3 || ^6.2", "keradus/cli-executor": "^2.1", "mikey179/vfsstream": "^1.6.12", "php-coveralls/php-coveralls": "^2.7", "php-cs-fixer/accessible-object": "^1.1", "php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.6", "php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.6", - "phpunit/phpunit": "^9.6.22 || ^10.5.45 || ^11.5.7", - "symfony/var-dumper": "^5.4.48 || ^6.4.18 || ^7.2.0", - "symfony/yaml": "^5.4.45 || ^6.4.18 || ^7.2.0" + "phpunit/phpunit": "^9.6.22 || ^10.5.45 || ^11.5.12", + "symfony/var-dumper": "^5.4.48 || ^6.4.18 || ^7.2.3", + "symfony/yaml": "^5.4.45 || ^6.4.18 || ^7.2.3" }, "suggest": { "ext-dom": "For handling output formats in XML", @@ -720,7 +721,7 @@ ], "support": { "issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues", - "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.70.0" + "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.73.1" }, "funding": [ { @@ -728,7 +729,7 @@ "type": "github" } ], - "time": "2025-02-22T23:30:51+00:00" + "time": "2025-03-19T23:42:16+00:00" }, { "name": "glpi-project/tools", @@ -847,18 +848,66 @@ }, "time": "2024-03-27T12:14:49+00:00" }, + { + "name": "phpstan/extension-installer", + "version": "1.4.3", + "source": { + "type": "git", + "url": "https://github.com/phpstan/extension-installer.git", + "reference": "85e90b3942d06b2326fba0403ec24fe912372936" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/extension-installer/zipball/85e90b3942d06b2326fba0403ec24fe912372936", + "reference": "85e90b3942d06b2326fba0403ec24fe912372936", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^2.0", + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.9.0 || ^2.0" + }, + "require-dev": { + "composer/composer": "^2.0", + "php-parallel-lint/php-parallel-lint": "^1.2.0", + "phpstan/phpstan-strict-rules": "^0.11 || ^0.12 || ^1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "PHPStan\\ExtensionInstaller\\Plugin" + }, + "autoload": { + "psr-4": { + "PHPStan\\ExtensionInstaller\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Composer plugin for automatic installation of PHPStan extensions", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "issues": "https://github.com/phpstan/extension-installer/issues", + "source": "https://github.com/phpstan/extension-installer/tree/1.4.3" + }, + "time": "2024-09-04T20:21:43+00:00" + }, { "name": "phpstan/phpstan", - "version": "2.1.6", + "version": "2.1.8", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "6eaec7c6c9e90dcfe46ad1e1ffa5171e2dab641c" + "reference": "f9adff3b87c03b12cc7e46a30a524648e497758f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/6eaec7c6c9e90dcfe46ad1e1ffa5171e2dab641c", - "reference": "6eaec7c6c9e90dcfe46ad1e1ffa5171e2dab641c", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/f9adff3b87c03b12cc7e46a30a524648e497758f", + "reference": "f9adff3b87c03b12cc7e46a30a524648e497758f", "shasum": "" }, "require": { @@ -903,7 +952,54 @@ "type": "github" } ], - "time": "2025-02-19T15:46:42+00:00" + "time": "2025-03-09T09:30:48+00:00" + }, + { + "name": "phpstan/phpstan-deprecation-rules", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan-deprecation-rules.git", + "reference": "1cc1259cb91ee4cfbb5c39bca9f635f067c910b4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/1cc1259cb91ee4cfbb5c39bca9f635f067c910b4", + "reference": "1cc1259cb91ee4cfbb5c39bca9f635f067c910b4", + "shasum": "" + }, + "require": { + "php": "^7.4 || ^8.0", + "phpstan/phpstan": "^2.0" + }, + "require-dev": { + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/phpstan-phpunit": "^2.0", + "phpunit/phpunit": "^9.6" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "rules.neon" + ] + } + }, + "autoload": { + "psr-4": { + "PHPStan\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan rules for detecting usage of deprecated classes, methods, properties, constants and traits.", + "support": { + "issues": "https://github.com/phpstan/phpstan-deprecation-rules/issues", + "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/2.0.1" + }, + "time": "2024-11-28T21:56:36+00:00" }, { "name": "psr/container", @@ -2964,5 +3060,5 @@ "platform-overrides": { "php": "7.4.0" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/inc/container.class.php b/inc/container.class.php index 5bd0c037..c3b6d856 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -96,7 +96,7 @@ public static function installBaseData(Migration $migration, $version) PRIMARY KEY (`id`), KEY `entities_id` (`entities_id`) ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; - $DB->query($query) or die($DB->error()); + $DB->doQuery($query) or die($DB->error()); } // multiple itemtype for one container @@ -309,7 +309,7 @@ public static function installUserData(Migration $migration, $version) } //drop old table - $DB->query('DROP TABLE ' . $osdata::getTable()); + $DB->doQuery('DROP TABLE ' . $osdata::getTable()); } else { $DB->update( 'glpi_plugin_fields_containers', @@ -372,7 +372,7 @@ public static function uninstall() } //drop global container table - $DB->query('DROP TABLE IF EXISTS `' . self::getTable() . '`'); + $DB->doQuery('DROP TABLE IF EXISTS `' . self::getTable() . '`'); //delete display preferences for this item $pref = new DisplayPreference(); @@ -740,7 +740,7 @@ public function pre_deleteItem() } else { //class does not exists; try to remove any existing table $tablename = getTableForItemType($classname); - $DB->query("DROP TABLE IF EXISTS `$tablename`"); + $DB->doQuery("DROP TABLE IF EXISTS `$tablename`"); } //clean session diff --git a/inc/containerdisplaycondition.class.php b/inc/containerdisplaycondition.class.php index 43a20ef2..bd108987 100644 --- a/inc/containerdisplaycondition.class.php +++ b/inc/containerdisplaycondition.class.php @@ -77,7 +77,7 @@ public static function installBaseData(Migration $migration, $version) PRIMARY KEY (`id`), KEY `plugin_fields_containers_id_itemtype` (`plugin_fields_containers_id`, `itemtype`) ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; - $DB->query($query) or die($DB->error()); + $DB->doQuery($query) or die($DB->error()); } return true; @@ -145,7 +145,7 @@ public static function uninstall() { /** @var DBmysql $DB */ global $DB; - $DB->query('DROP TABLE IF EXISTS `' . self::getTable() . '`'); + $DB->doQuery('DROP TABLE IF EXISTS `' . self::getTable() . '`'); return true; } diff --git a/inc/field.class.php b/inc/field.class.php index 933a21c4..02d43247 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -92,7 +92,7 @@ public static function installBaseData(Migration $migration, $version) KEY `is_active` (`is_active`), KEY `is_readonly` (`is_readonly`) ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; - $DB->query($query) or die($DB->error()); + $DB->doQuery($query) or die($DB->error()); } $migration->displayMessage("Updating $table"); @@ -233,7 +233,7 @@ public static function uninstall() /** @var DBmysql $DB */ global $DB; - $DB->query('DROP TABLE IF EXISTS `' . self::getTable() . '`'); + $DB->doQuery('DROP TABLE IF EXISTS `' . self::getTable() . '`'); return true; } diff --git a/inc/labeltranslation.class.php b/inc/labeltranslation.class.php index 140d7a56..a8b844df 100644 --- a/inc/labeltranslation.class.php +++ b/inc/labeltranslation.class.php @@ -69,7 +69,7 @@ public static function installBaseData(Migration $migration, $version) KEY `language` (`language`), UNIQUE KEY `unicity` (`itemtype`, `items_id`, `language`) ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; - $DB->query($query) or die($DB->error()); + $DB->doQuery($query) or die($DB->error()); } if ($DB->fieldExists($table, 'plugin_fields_itemtype')) { @@ -94,7 +94,7 @@ public static function uninstall() /** @var DBmysql $DB */ global $DB; - $DB->query('DROP TABLE IF EXISTS `' . self::getTable() . '`'); + $DB->doQuery('DROP TABLE IF EXISTS `' . self::getTable() . '`'); return true; } diff --git a/inc/profile.class.php b/inc/profile.class.php index 1ca2c91c..d6c72c3a 100644 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -68,7 +68,7 @@ public static function installBaseData(Migration $migration, $version) KEY `profiles_id` (`profiles_id`), KEY `plugin_fields_containers_id` (`plugin_fields_containers_id`) ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; - $DB->query($query) or die($DB->error()); + $DB->doQuery($query) or die($DB->error()); } return true; @@ -79,7 +79,7 @@ public static function uninstall() /** @var DBmysql $DB */ global $DB; - $DB->query('DROP TABLE IF EXISTS `' . self::getTable() . '`'); + $DB->doQuery('DROP TABLE IF EXISTS `' . self::getTable() . '`'); return true; } diff --git a/inc/statusoverride.class.php b/inc/statusoverride.class.php index 65715efa..73e52581 100644 --- a/inc/statusoverride.class.php +++ b/inc/statusoverride.class.php @@ -69,7 +69,7 @@ public static function installBaseData(Migration $migration, $version) PRIMARY KEY (`id`), KEY `plugin_fields_fields_id` (`plugin_fields_fields_id`) ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; - $DB->query($query) or die($DB->error()); + $DB->doQuery($query) or die($DB->error()); } return true; @@ -80,7 +80,7 @@ public static function uninstall() /** @var DBmysql $DB */ global $DB; - $DB->query('DROP TABLE IF EXISTS `' . self::getTable() . '`'); + $DB->doQuery('DROP TABLE IF EXISTS `' . self::getTable() . '`'); return true; } diff --git a/setup.php b/setup.php index c4365bf1..5a55d541 100644 --- a/setup.php +++ b/setup.php @@ -31,7 +31,7 @@ define('PLUGIN_FIELDS_VERSION', '1.21.19'); // Minimal GLPI version, inclusive -define('PLUGIN_FIELDS_MIN_GLPI', '10.0.0'); +define('PLUGIN_FIELDS_MIN_GLPI', '10.0.11'); // Maximum GLPI version, exclusive define('PLUGIN_FIELDS_MAX_GLPI', '10.0.99');