From 820dce2958a1c6deaaa8c489306e88eb9f3ff516 Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Mon, 30 Oct 2023 09:22:47 +0100 Subject: [PATCH 1/7] phpstan lvl 0 --- composer.json | 1 + composer.lock | 66 ++++++++++++++++++++++++- inc/container.class.php | 12 ++++- inc/containerdisplaycondition.class.php | 2 + inc/field.class.php | 2 + inc/inventory.class.php | 2 + inc/labeltranslation.class.php | 1 + inc/profile.class.php | 1 + inc/statusoverride.class.php | 1 + inc/toolbox.class.php | 1 + phpstan.neon | 14 ++++++ 11 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 phpstan.neon diff --git a/composer.json b/composer.json index 2a585bb2..7c3e4d3f 100644 --- a/composer.json +++ b/composer.json @@ -6,6 +6,7 @@ "require-dev": { "glpi-project/tools": "^0.6", "php-parallel-lint/php-parallel-lint": "^1.3", + "phpstan/phpstan": "^1.10", "squizlabs/php_codesniffer": "^3.6" }, "config": { diff --git a/composer.lock b/composer.lock index dd2eb416..33a3d0bf 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": "2a7360182e8cc8ad1b72d964a2117b49", + "content-hash": "58837d5ac5e6f067ef743b888ea5c7e9", "packages": [ { "name": "symfony/deprecation-contracts", @@ -341,6 +341,68 @@ }, "time": "2022-02-21T12:50:22+00:00" }, + { + "name": "phpstan/phpstan", + "version": "1.10.38", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "5302bb402c57f00fb3c2c015bac86e0827e4b691" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/5302bb402c57f00fb3c2c015bac86e0827e4b691", + "reference": "5302bb402c57f00fb3c2c015bac86e0827e4b691", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", + "type": "tidelift" + } + ], + "time": "2023-10-06T14:19:14+00:00" + }, { "name": "psr/container", "version": "1.1.2", @@ -1208,5 +1270,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 11e55ba0..613d95cc 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -474,6 +474,8 @@ public static function getSpecificValueToDisplay($field, $values, array $options } return $obj; } + + return ''; } @@ -487,7 +489,7 @@ public function getValueToSelect($field_id_or_search_options, $name = '', $value return Dropdown::showFromArray($name, self::getTypes(), $options); case $this->getTable() . '.itemtypes': $options['display'] = false; - return Dropdown::showFromArray($name, self::getItemtypes(), $options); + return Dropdown::showFromArray($name, self::getItemtypes(false), $options); } return parent::getValueToSelect($field_id_or_search_options, $name, $values, $options); @@ -1114,6 +1116,8 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) } return $tabs_entries; } + + return ''; } @@ -1133,6 +1137,8 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ return PluginFieldsField::showForTabContainer($data['id'], $item); } } + + return true; } /** @@ -1576,6 +1582,8 @@ public static function postItemAdd(CommonDBTM $item) } return $item->input = []; } + + return true; } /** @@ -1601,6 +1609,8 @@ public static function preItemUpdate(CommonDBTM $item) } return $item->input = []; } + + return true; } diff --git a/inc/containerdisplaycondition.class.php b/inc/containerdisplaycondition.class.php index a06ee833..44861077 100644 --- a/inc/containerdisplaycondition.class.php +++ b/inc/containerdisplaycondition.class.php @@ -551,6 +551,8 @@ public function showForm($ID, array $options = []) : self::removeBlackListedOption(Search::getOptions($this->fields['itemtype']), $this->fields['itemtype']), ]; TemplateRenderer::getInstance()->display('@fields/forms/container_display_condition.html.twig', $twig_params); + + return true; } public function getCloneRelations(): array diff --git a/inc/field.class.php b/inc/field.class.php index a3c5bbcf..a506b473 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -774,6 +774,8 @@ public function showForm($ID, $options = []) echo ""; $this->showFormButtons($options); + + return true; } public static function showForTabContainer($c_id, $item) diff --git a/inc/inventory.class.php b/inc/inventory.class.php index ed1cc905..a406329a 100644 --- a/inc/inventory.class.php +++ b/inc/inventory.class.php @@ -57,6 +57,7 @@ public static function updateInventory($params = []) if ($itemtype == Computer::getType()) { //load inventory from DB because //FI not update XML file if computer is not update + /** @phpstan-ignore-next-line */ $db_info = new PluginFusioninventoryInventoryComputerComputer(); if ($db_info->getFromDBByCrit(['computers_id' => $items_id])) { $arrayinventory = unserialize(gzuncompress($db_info->fields['serialized_inventory'])); @@ -68,6 +69,7 @@ public static function updateInventory($params = []) //Load XML file because FI always update XML file and don't store inventory into DB $file = self::loadXMLFile($itemtype, $items_id); if ($file !== false) { + /** @phpstan-ignore-next-line */ $arrayinventory = PluginFusioninventoryFormatconvert::XMLtoArray($file); if (isset($arrayinventory['CUSTOM'])) { self::updateFields($arrayinventory['CUSTOM']['CONTAINER'], $itemtype, $items_id); diff --git a/inc/labeltranslation.class.php b/inc/labeltranslation.class.php index 058a3813..28e56046 100644 --- a/inc/labeltranslation.class.php +++ b/inc/labeltranslation.class.php @@ -129,6 +129,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { self::showTranslations($item); + return true; } /** diff --git a/inc/profile.class.php b/inc/profile.class.php index 58b7132e..f9509dda 100644 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -126,6 +126,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ echo ""; echo ""; Html::closeForm(); + return true; } public static function updateProfile($input) diff --git a/inc/statusoverride.class.php b/inc/statusoverride.class.php index 78e9093c..4413d9c8 100644 --- a/inc/statusoverride.class.php +++ b/inc/statusoverride.class.php @@ -412,5 +412,6 @@ public function showForm($ID, array $options = []) 'container_fields' => self::getFieldsChoiceForContainer($container_id), ]; TemplateRenderer::getInstance()->display('@fields/forms/status_override.html.twig', $twig_params); + return true; } } diff --git a/inc/toolbox.class.php b/inc/toolbox.class.php index 8e9b3b1d..88826949 100644 --- a/inc/toolbox.class.php +++ b/inc/toolbox.class.php @@ -321,6 +321,7 @@ public static function getGlpiItemtypes(): array $plugin = new Plugin(); if ($plugin->isActivated('genericobject') && method_exists('PluginGenericobjectType', 'getTypes')) { $go_itemtypes = []; + /** @phpstan-ignore-next-line */ foreach (array_keys(PluginGenericobjectType::getTypes()) as $go_itemtype) { if (!class_exists($go_itemtype)) { continue; diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 00000000..0d4f38f7 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,14 @@ +parameters: + parallel: + maximumNumberOfProcesses: 2 + level: 0 + bootstrapFiles: + - ../../inc/based_config.php + - setup.php + paths: + - inc + scanDirectories: + - ../../inc + - ../../src + stubFiles: + - ../../stubs/glpi_constants.php From aeab53fb7b93d10d712204d45db717360ab5c015 Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Mon, 30 Oct 2023 09:45:06 +0100 Subject: [PATCH 2/7] phpstan lvl 1 --- inc/containerdisplaycondition.class.php | 6 ++++-- inc/field.class.php | 6 +++--- inc/inventory.class.php | 4 +++- phpstan.neon | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/inc/containerdisplaycondition.class.php b/inc/containerdisplaycondition.class.php index 44861077..82acbd63 100644 --- a/inc/containerdisplaycondition.class.php +++ b/inc/containerdisplaycondition.class.php @@ -198,6 +198,8 @@ private static function getItemtypesForContainer(int $container_id): array { global $DB; + $results = []; + $iterator = $DB->request([ 'SELECT' => ['itemtypes'], 'FROM' => PluginFieldsContainer::getTable(), @@ -212,9 +214,9 @@ private static function getItemtypesForContainer(int $container_id): array foreach ($itemtypes as $itemtype) { $results[$itemtype] = $itemtype::getTypeName(); } - return $results; } - return []; + + return $results; } diff --git a/inc/field.class.php b/inc/field.class.php index a506b473..b19eb432 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -272,7 +272,7 @@ public function prepareInputForAdd($input) //reject adding for same dropdown on same bloc if (!empty($found)) { - Session::AddMessageAfterRedirect(__("You cannot add same field 'dropdown' on same bloc", 'fields', false, ERROR)); + Session::AddMessageAfterRedirect(__("You cannot add same field 'dropdown' on same bloc", 'fields'), false, ERROR); return false; } @@ -676,8 +676,8 @@ public function showForm($ID, $options = []) { $rand = mt_rand(); + $container = new PluginFieldsContainer(); if (isset($options['parent_id']) && !empty($options['parent_id'])) { - $container = new PluginFieldsContainer(); $container->getFromDB($options['parent_id']); } else if ( isset($options['parent']) @@ -697,7 +697,7 @@ public function showForm($ID, $options = []) } $this->initForm($ID, $options); - $this->showFormHeader($ID, $options); + $this->showFormHeader($options); echo ""; echo "" . __("Label") . " : "; diff --git a/inc/inventory.class.php b/inc/inventory.class.php index a406329a..3eedca2f 100644 --- a/inc/inventory.class.php +++ b/inc/inventory.class.php @@ -39,7 +39,8 @@ public static function updateInventory($params = []) $availaibleItemType = ["Computer","Printer","NetworkEquipment"]; foreach (array_keys($params['inventory_data']) as $itemtype) { if (in_array($itemtype, $availaibleItemType)) { - //retrive items id switch itemtype + $items_id = 0; + //retrieve items id switch itemtype switch ($itemtype) { case Computer::getType(): $items_id = $params['computers_id']; @@ -110,6 +111,7 @@ public static function loadXMLFile($itemtype, $items_id) } //Check if the file exists with the .xml extension (new format) + /** @phpstan-ignore-next-line */ $file = PLUGIN_FUSIONINVENTORY_XML_DIR . strtolower($itemtype) . "/" . $folder . "/" . $items_id; if (file_exists($file . '.xml')) { $file .= '.xml'; diff --git a/phpstan.neon b/phpstan.neon index 0d4f38f7..7d28e224 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,7 +1,7 @@ parameters: parallel: maximumNumberOfProcesses: 2 - level: 0 + level: 1 bootstrapFiles: - ../../inc/based_config.php - setup.php From 31203abb11cb36369799d88ea00e28c8f0be90b1 Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Tue, 31 Oct 2023 09:04:54 +0100 Subject: [PATCH 3/7] Extend conf, new fixes --- ajax/reorder.php | 3 +++ front/commondropdown.form.php | 2 +- front/commondropdown.php | 2 +- hook.php | 1 + phpstan.neon | 3 +++ 5 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ajax/reorder.php b/ajax/reorder.php index 3efae82a..8356c9da 100644 --- a/ajax/reorder.php +++ b/ajax/reorder.php @@ -44,6 +44,9 @@ $old_order = (int)$_POST['old_order']; $new_order = (int)$_POST['new_order']; +/** @var DBmysql $DB */ +global $DB; + // Retrieve id of field to update $field_iterator = $DB->request( [ diff --git a/front/commondropdown.form.php b/front/commondropdown.form.php index 06ae450a..cc20a260 100644 --- a/front/commondropdown.form.php +++ b/front/commondropdown.form.php @@ -30,7 +30,7 @@ include "../../../inc/includes.php"; if (preg_match('/[a-z]/i', $_REQUEST['ddtype']) !== 1) { - throw new \RuntimeException(sprintf('Invalid itemtype "%"', $_REQUEST['ddtype'])); + throw new \RuntimeException(sprintf('Invalid itemtype "%1$s"', $_REQUEST['ddtype'])); } $path = PLUGINFIELDS_FRONT_PATH . '/' . $_REQUEST['ddtype'] . '.form.php'; require_once $path; diff --git a/front/commondropdown.php b/front/commondropdown.php index d0f3f71b..ebd334be 100644 --- a/front/commondropdown.php +++ b/front/commondropdown.php @@ -30,7 +30,7 @@ include "../../../inc/includes.php"; if (preg_match('/[a-z]/i', $_REQUEST['ddtype']) !== 1) { - throw new \RuntimeException(sprintf('Invalid itemtype "%"', $_REQUEST['ddtype'])); + throw new \RuntimeException(sprintf('Invalid itemtype "%1$s"', $_REQUEST['ddtype'])); } $path = PLUGINFIELDS_FRONT_PATH . '/' . $_REQUEST['ddtype'] . '.php'; require_once $path; diff --git a/hook.php b/hook.php index 84f77f2f..e7aef829 100644 --- a/hook.php +++ b/hook.php @@ -252,6 +252,7 @@ function plugin_fields_rule_matched($params = []) switch ($params['sub_type']) { case "PluginFusioninventoryTaskpostactionRule": + /** @phpstan-ignore-next-line */ $agent = new PluginFusioninventoryAgent(); if (isset($params['input']['plugin_fusioninventory_agents_id'])) { diff --git a/phpstan.neon b/phpstan.neon index 7d28e224..d6186dcb 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -7,6 +7,9 @@ parameters: - setup.php paths: - inc + - front + - ajax + - hook.php scanDirectories: - ../../inc - ../../src From 72af0aa8bd4321610e7d957f5dbf58ccea0b9df6 Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Mon, 6 Nov 2023 11:23:53 +0100 Subject: [PATCH 4/7] Update 3rd party libs --- composer.json | 2 +- composer.lock | 162 ++++++++++++++++++++++++++------------------------ 2 files changed, 84 insertions(+), 80 deletions(-) diff --git a/composer.json b/composer.json index 7c3e4d3f..da444512 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "symfony/yaml": "^5.4" }, "require-dev": { - "glpi-project/tools": "^0.6", + "glpi-project/tools": "^0.7.1", "php-parallel-lint/php-parallel-lint": "^1.3", "phpstan/phpstan": "^1.10", "squizlabs/php_codesniffer": "^3.6" diff --git a/composer.lock b/composer.lock index 33a3d0bf..faad12ad 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": "58837d5ac5e6f067ef743b888ea5c7e9", + "content-hash": "5b54b981574317523605770d0cd75545", "packages": [ { "name": "symfony/deprecation-contracts", @@ -75,16 +75,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.27.0", + "version": "v1.28.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "5bbc823adecdae860bb64756d639ecfec17b050a" + "reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/5bbc823adecdae860bb64756d639ecfec17b050a", - "reference": "5bbc823adecdae860bb64756d639ecfec17b050a", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb", + "reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb", "shasum": "" }, "require": { @@ -99,7 +99,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.27-dev" + "dev-main": "1.28-dev" }, "thanks": { "name": "symfony/polyfill", @@ -137,7 +137,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.27.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.28.0" }, "funding": [ { @@ -153,20 +153,20 @@ "type": "tidelift" } ], - "time": "2022-11-03T14:55:06+00:00" + "time": "2023-01-26T09:26:14+00:00" }, { "name": "symfony/yaml", - "version": "v5.4.23", + "version": "v5.4.30", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "4cd2e3ea301aadd76a4172756296fe552fb45b0b" + "reference": "c6980e82a6656f6ebfabfd82f7585794cb122554" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/4cd2e3ea301aadd76a4172756296fe552fb45b0b", - "reference": "4cd2e3ea301aadd76a4172756296fe552fb45b0b", + "url": "https://api.github.com/repos/symfony/yaml/zipball/c6980e82a6656f6ebfabfd82f7585794cb122554", + "reference": "c6980e82a6656f6ebfabfd82f7585794cb122554", "shasum": "" }, "require": { @@ -212,7 +212,7 @@ "description": "Loads and dumps YAML files", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/yaml/tree/v5.4.23" + "source": "https://github.com/symfony/yaml/tree/v5.4.30" }, "funding": [ { @@ -228,28 +228,32 @@ "type": "tidelift" } ], - "time": "2023-04-23T19:33:36+00:00" + "time": "2023-10-27T18:36:14+00:00" } ], "packages-dev": [ { "name": "glpi-project/tools", - "version": "0.6.4", + "version": "0.7.1", "source": { "type": "git", "url": "https://github.com/glpi-project/tools.git", - "reference": "8ef917fa2967e716eaed198bb803f418a80cd621" + "reference": "4bc5a725d9f4da0ee946ad3cbdd54a782d2f40fb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/glpi-project/tools/zipball/8ef917fa2967e716eaed198bb803f418a80cd621", - "reference": "8ef917fa2967e716eaed198bb803f418a80cd621", + "url": "https://api.github.com/repos/glpi-project/tools/zipball/4bc5a725d9f4da0ee946ad3cbdd54a782d2f40fb", + "reference": "4bc5a725d9f4da0ee946ad3cbdd54a782d2f40fb", "shasum": "" }, "require": { "symfony/console": "^5.4 || ^6.0", "twig/twig": "^3.3" }, + "require-dev": { + "nikic/php-parser": "^4.13", + "phpstan/phpstan-src": "^1.10" + }, "bin": [ "bin/extract-locales", "bin/licence-headers-check", @@ -258,7 +262,7 @@ "type": "library", "autoload": { "psr-4": { - "Glpi\\": "src/" + "GlpiProject\\Tools\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -282,7 +286,7 @@ "issues": "https://github.com/glpi-project/tools/issues", "source": "https://github.com/glpi-project/tools" }, - "time": "2023-07-27T12:32:25+00:00" + "time": "2023-10-16T11:40:35+00:00" }, { "name": "php-parallel-lint/php-parallel-lint", @@ -343,16 +347,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.38", + "version": "1.10.41", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "5302bb402c57f00fb3c2c015bac86e0827e4b691" + "reference": "c6174523c2a69231df55bdc65b61655e72876d76" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/5302bb402c57f00fb3c2c015bac86e0827e4b691", - "reference": "5302bb402c57f00fb3c2c015bac86e0827e4b691", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/c6174523c2a69231df55bdc65b61655e72876d76", + "reference": "c6174523c2a69231df55bdc65b61655e72876d76", "shasum": "" }, "require": { @@ -401,7 +405,7 @@ "type": "tidelift" } ], - "time": "2023-10-06T14:19:14+00:00" + "time": "2023-11-05T12:57:57+00:00" }, { "name": "psr/container", @@ -510,16 +514,16 @@ }, { "name": "symfony/console", - "version": "v5.4.26", + "version": "v5.4.28", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "b504a3d266ad2bb632f196c0936ef2af5ff6e273" + "reference": "f4f71842f24c2023b91237c72a365306f3c58827" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/b504a3d266ad2bb632f196c0936ef2af5ff6e273", - "reference": "b504a3d266ad2bb632f196c0936ef2af5ff6e273", + "url": "https://api.github.com/repos/symfony/console/zipball/f4f71842f24c2023b91237c72a365306f3c58827", + "reference": "f4f71842f24c2023b91237c72a365306f3c58827", "shasum": "" }, "require": { @@ -589,7 +593,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v5.4.26" + "source": "https://github.com/symfony/console/tree/v5.4.28" }, "funding": [ { @@ -605,20 +609,20 @@ "type": "tidelift" } ], - "time": "2023-07-19T20:11:33+00:00" + "time": "2023-08-07T06:12:30+00:00" }, { "name": "symfony/polyfill-intl-grapheme", - "version": "v1.27.0", + "version": "v1.28.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-grapheme.git", - "reference": "511a08c03c1960e08a883f4cffcacd219b758354" + "reference": "875e90aeea2777b6f135677f618529449334a612" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/511a08c03c1960e08a883f4cffcacd219b758354", - "reference": "511a08c03c1960e08a883f4cffcacd219b758354", + "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/875e90aeea2777b6f135677f618529449334a612", + "reference": "875e90aeea2777b6f135677f618529449334a612", "shasum": "" }, "require": { @@ -630,7 +634,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.27-dev" + "dev-main": "1.28-dev" }, "thanks": { "name": "symfony/polyfill", @@ -670,7 +674,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.27.0" + "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.28.0" }, "funding": [ { @@ -686,20 +690,20 @@ "type": "tidelift" } ], - "time": "2022-11-03T14:55:06+00:00" + "time": "2023-01-26T09:26:14+00:00" }, { "name": "symfony/polyfill-intl-normalizer", - "version": "v1.27.0", + "version": "v1.28.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-normalizer.git", - "reference": "19bd1e4fcd5b91116f14d8533c57831ed00571b6" + "reference": "8c4ad05dd0120b6a53c1ca374dca2ad0a1c4ed92" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/19bd1e4fcd5b91116f14d8533c57831ed00571b6", - "reference": "19bd1e4fcd5b91116f14d8533c57831ed00571b6", + "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/8c4ad05dd0120b6a53c1ca374dca2ad0a1c4ed92", + "reference": "8c4ad05dd0120b6a53c1ca374dca2ad0a1c4ed92", "shasum": "" }, "require": { @@ -711,7 +715,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.27-dev" + "dev-main": "1.28-dev" }, "thanks": { "name": "symfony/polyfill", @@ -754,7 +758,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.27.0" + "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.28.0" }, "funding": [ { @@ -770,20 +774,20 @@ "type": "tidelift" } ], - "time": "2022-11-03T14:55:06+00:00" + "time": "2023-01-26T09:26:14+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.27.0", + "version": "v1.28.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534" + "reference": "42292d99c55abe617799667f454222c54c60e229" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/8ad114f6b39e2c98a8b0e3bd907732c207c2b534", - "reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/42292d99c55abe617799667f454222c54c60e229", + "reference": "42292d99c55abe617799667f454222c54c60e229", "shasum": "" }, "require": { @@ -798,7 +802,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.27-dev" + "dev-main": "1.28-dev" }, "thanks": { "name": "symfony/polyfill", @@ -837,7 +841,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.27.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.28.0" }, "funding": [ { @@ -853,20 +857,20 @@ "type": "tidelift" } ], - "time": "2022-11-03T14:55:06+00:00" + "time": "2023-07-28T09:04:16+00:00" }, { "name": "symfony/polyfill-php73", - "version": "v1.27.0", + "version": "v1.28.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php73.git", - "reference": "9e8ecb5f92152187c4799efd3c96b78ccab18ff9" + "reference": "fe2f306d1d9d346a7fee353d0d5012e401e984b5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/9e8ecb5f92152187c4799efd3c96b78ccab18ff9", - "reference": "9e8ecb5f92152187c4799efd3c96b78ccab18ff9", + "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/fe2f306d1d9d346a7fee353d0d5012e401e984b5", + "reference": "fe2f306d1d9d346a7fee353d0d5012e401e984b5", "shasum": "" }, "require": { @@ -875,7 +879,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.27-dev" + "dev-main": "1.28-dev" }, "thanks": { "name": "symfony/polyfill", @@ -916,7 +920,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php73/tree/v1.27.0" + "source": "https://github.com/symfony/polyfill-php73/tree/v1.28.0" }, "funding": [ { @@ -932,20 +936,20 @@ "type": "tidelift" } ], - "time": "2022-11-03T14:55:06+00:00" + "time": "2023-01-26T09:26:14+00:00" }, { "name": "symfony/polyfill-php80", - "version": "v1.27.0", + "version": "v1.28.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "7a6ff3f1959bb01aefccb463a0f2cd3d3d2fd936" + "reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/7a6ff3f1959bb01aefccb463a0f2cd3d3d2fd936", - "reference": "7a6ff3f1959bb01aefccb463a0f2cd3d3d2fd936", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/6caa57379c4aec19c0a12a38b59b26487dcfe4b5", + "reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5", "shasum": "" }, "require": { @@ -954,7 +958,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.27-dev" + "dev-main": "1.28-dev" }, "thanks": { "name": "symfony/polyfill", @@ -999,7 +1003,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.27.0" + "source": "https://github.com/symfony/polyfill-php80/tree/v1.28.0" }, "funding": [ { @@ -1015,7 +1019,7 @@ "type": "tidelift" } ], - "time": "2022-11-03T14:55:06+00:00" + "time": "2023-01-26T09:26:14+00:00" }, { "name": "symfony/service-contracts", @@ -1102,16 +1106,16 @@ }, { "name": "symfony/string", - "version": "v5.4.26", + "version": "v5.4.29", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "1181fe9270e373537475e826873b5867b863883c" + "reference": "e41bdc93def20eaf3bfc1537c4e0a2b0680a152d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/1181fe9270e373537475e826873b5867b863883c", - "reference": "1181fe9270e373537475e826873b5867b863883c", + "url": "https://api.github.com/repos/symfony/string/zipball/e41bdc93def20eaf3bfc1537c4e0a2b0680a152d", + "reference": "e41bdc93def20eaf3bfc1537c4e0a2b0680a152d", "shasum": "" }, "require": { @@ -1168,7 +1172,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v5.4.26" + "source": "https://github.com/symfony/string/tree/v5.4.29" }, "funding": [ { @@ -1184,20 +1188,20 @@ "type": "tidelift" } ], - "time": "2023-06-28T12:46:07+00:00" + "time": "2023-09-13T11:47:41+00:00" }, { "name": "twig/twig", - "version": "v3.7.0", + "version": "v3.7.1", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "5cf942bbab3df42afa918caeba947f1b690af64b" + "reference": "a0ce373a0ca3bf6c64b9e3e2124aca502ba39554" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/5cf942bbab3df42afa918caeba947f1b690af64b", - "reference": "5cf942bbab3df42afa918caeba947f1b690af64b", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/a0ce373a0ca3bf6c64b9e3e2124aca502ba39554", + "reference": "a0ce373a0ca3bf6c64b9e3e2124aca502ba39554", "shasum": "" }, "require": { @@ -1207,7 +1211,7 @@ }, "require-dev": { "psr/container": "^1.0|^2.0", - "symfony/phpunit-bridge": "^4.4.9|^5.0.9|^6.0" + "symfony/phpunit-bridge": "^5.4.9|^6.3" }, "type": "library", "autoload": { @@ -1243,7 +1247,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.7.0" + "source": "https://github.com/twigphp/Twig/tree/v3.7.1" }, "funding": [ { @@ -1255,7 +1259,7 @@ "type": "tidelift" } ], - "time": "2023-07-26T07:16:09+00:00" + "time": "2023-08-28T11:09:02+00:00" } ], "aliases": [], From 88ac28ed2abfdfef6a8082060d10578d476d9ed1 Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Mon, 6 Nov 2023 11:24:06 +0100 Subject: [PATCH 5/7] Also check setup.php file --- phpstan.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index d6186dcb..60bb85d3 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,12 +4,12 @@ parameters: level: 1 bootstrapFiles: - ../../inc/based_config.php - - setup.php paths: - inc - front - ajax - hook.php + - setup.php scanDirectories: - ../../inc - ../../src From 31e53906dab98b0a170ee36187805eb28fa9811b Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Mon, 6 Nov 2023 11:24:45 +0100 Subject: [PATCH 6/7] Suggested change --- phpstan.neon | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpstan.neon b/phpstan.neon index 60bb85d3..8feb5069 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -15,3 +15,5 @@ parameters: - ../../src stubFiles: - ../../stubs/glpi_constants.php +rules: + - GlpiProject\Tools\PHPStan\Rules\GlobalVarTypeRule From ffd27d9395ffe7095f6422701f7b4731fde6dc56 Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Mon, 6 Nov 2023 14:10:15 +0100 Subject: [PATCH 7/7] Fix CS --- hook.php | 2 ++ inc/container.class.php | 10 ++++++++++ inc/containerdisplaycondition.class.php | 4 ++++ inc/dropdown.class.php | 1 + inc/field.class.php | 10 ++++++++++ inc/labeltranslation.class.php | 3 +++ inc/profile.class.php | 3 +++ inc/statusoverride.class.php | 9 +++++++++ inc/toolbox.class.php | 5 +++++ setup.php | 5 ++++- 10 files changed, 51 insertions(+), 1 deletion(-) diff --git a/hook.php b/hook.php index e7aef829..62ffa5d9 100644 --- a/hook.php +++ b/hook.php @@ -246,6 +246,7 @@ function plugin_fields_getRuleActions($params = []) function plugin_fields_rule_matched($params = []) { + /** @var DBmysql $DB */ global $DB; $container = new PluginFieldsContainer(); @@ -320,6 +321,7 @@ function plugin_fields_giveItem($itemtype, $ID, $data, $num) */ function plugin_datainjection_populate_fields() { + /** @var array $INJECTABLE_TYPES */ global $INJECTABLE_TYPES; $container = new PluginFieldsContainer(); diff --git a/inc/container.class.php b/inc/container.class.php index 613d95cc..00d67cf7 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -70,6 +70,7 @@ public function getForbiddenStandardMassiveAction() */ public static function installBaseData(Migration $migration, $version) { + /** @var DBmysql $DB */ global $DB; $default_charset = DBConnection::getDefaultCharset(); @@ -158,6 +159,7 @@ public static function installBaseData(Migration $migration, $version) */ public static function installUserData(Migration $migration, $version) { + /** @var DBmysql $DB */ global $DB; // -> 0.90-1.3: generated class moved @@ -337,6 +339,7 @@ public static function installUserData(Migration $migration, $version) public static function uninstall() { + /** @var DBmysql $DB */ global $DB; //uninstall container table and class @@ -663,6 +666,7 @@ public static function generateTemplate($fields) // phpcs:ignore PSR1.Methods.CamelCapsMethodName public function pre_deleteItem() { + /** @var DBmysql $DB */ global $DB; $_SESSION['delete_container'] = true; @@ -1001,6 +1005,7 @@ public static function getTypes() public static function getEntries($type = 'tab', $full = false): array { + /** @var DBmysql $DB */ global $DB; $condition = [ @@ -1062,6 +1067,7 @@ public static function getEntries($type = 'tab', $full = false): array public static function getUsedItemtypes($type = 'all', $must_be_active = false) { + /** @var DBmysql $DB */ global $DB; $itemtypes = []; $where = []; @@ -1152,6 +1158,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ */ public function updateFieldsValues($data, $itemtype, $massiveaction = false) { + /** @var DBmysql $DB */ global $DB; if (self::validateValues($data, $itemtype, $massiveaction) === false) { @@ -1212,6 +1219,7 @@ public function updateFieldsValues($data, $itemtype, $massiveaction = false) private function addRichTextFiles(CommonDBTM $object): void { + /** @var DBmysql $DB */ global $DB; $richtext_fields_iterator = $DB->request([ @@ -1389,6 +1397,7 @@ public static function constructHistory( */ public static function validateValues($data, $itemtype, $massiveaction) { + /** @var DBmysql $DB */ global $DB; $valid = true; @@ -1776,6 +1785,7 @@ private static function populateData($c_id, CommonDBTM $item) public static function getAddSearchOptions($itemtype, $containers_id = false) { + /** @var DBmysql $DB */ global $DB; $opt = []; diff --git a/inc/containerdisplaycondition.class.php b/inc/containerdisplaycondition.class.php index 82acbd63..ac677094 100644 --- a/inc/containerdisplaycondition.class.php +++ b/inc/containerdisplaycondition.class.php @@ -56,6 +56,7 @@ class PluginFieldsContainerDisplayCondition extends CommonDBChild */ public static function installBaseData(Migration $migration, $version) { + /** @var DBmysql $DB */ global $DB; $default_charset = DBConnection::getDefaultCharset(); $default_collation = DBConnection::getDefaultCollation(); @@ -142,6 +143,7 @@ public static function getConditionName($condition) public static function uninstall() { + /** @var DBmysql $DB */ global $DB; $DB->query("DROP TABLE IF EXISTS `" . self::getTable() . "`"); return true; @@ -175,6 +177,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ public static function getDisplayConditionForContainer(int $container_id): array { + /** @var DBmysql $DB */ global $DB; $iterator = $DB->request([ 'SELECT' => [ @@ -196,6 +199,7 @@ public static function getDisplayConditionForContainer(int $container_id): array private static function getItemtypesForContainer(int $container_id): array { + /** @var DBmysql $DB */ global $DB; $results = []; diff --git a/inc/dropdown.class.php b/inc/dropdown.class.php index 4623b24e..7b1f36f8 100644 --- a/inc/dropdown.class.php +++ b/inc/dropdown.class.php @@ -87,6 +87,7 @@ public static function installUserData(Migration $migration, $version) public static function uninstall() { + /** @var DBmysql $DB */ global $DB; //remove dropdown tables and files diff --git a/inc/field.class.php b/inc/field.class.php index b19eb432..80fb1859 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -63,6 +63,7 @@ public function getForbiddenStandardMassiveAction() */ public static function installBaseData(Migration $migration, $version) { + /** @var DBmysql $DB */ global $DB; $default_charset = DBConnection::getDefaultCharset(); @@ -170,6 +171,7 @@ public static function installBaseData(Migration $migration, $version) */ private static function migrateToStableSO(Migration $migration): void { + /** @var DBmysql $DB */ global $DB; // Flatten itemtype list @@ -229,6 +231,7 @@ private static function migrateToStableSO(Migration $migration): void public static function uninstall() { + /** @var DBmysql $DB */ global $DB; $DB->query("DROP TABLE IF EXISTS `" . self::getTable() . "`"); @@ -395,6 +398,7 @@ public function pre_deleteItem() // phpcs:ignore PSR1.Methods.CamelCapsMethodName public function post_purgeItem() { + /** @var DBmysql $DB */ global $DB; $table = getTableForItemType(__CLASS__); @@ -482,6 +486,7 @@ public function prepareName($input, bool $prevent_duplicated = true) */ public function getNextRanking() { + /** @var DBmysql $DB */ global $DB; $iterator = $DB->request([ @@ -538,6 +543,10 @@ public function defineTabs($options = []) public function showSummary($container) { + /** + * @var DBmysql $DB + * @var array $CFG_GLPI + */ global $DB, $CFG_GLPI; $cID = $container->fields['id']; @@ -1224,6 +1233,7 @@ public static function prepareHtmlFields( public static function showSingle($itemtype, $searchOption, $massiveaction = false) { + /** @var DBmysql $DB */ global $DB; //clean dropdown [pre/su]fix if exists diff --git a/inc/labeltranslation.class.php b/inc/labeltranslation.class.php index 28e56046..464d0972 100644 --- a/inc/labeltranslation.class.php +++ b/inc/labeltranslation.class.php @@ -45,6 +45,7 @@ class PluginFieldsLabelTranslation extends CommonDBChild */ public static function installBaseData(Migration $migration, $version) { + /** @var DBmysql $DB */ global $DB; $default_charset = DBConnection::getDefaultCharset(); @@ -90,6 +91,7 @@ public static function installBaseData(Migration $migration, $version) public static function uninstall() { + /** @var DBmysql $DB */ global $DB; $DB->query("DROP TABLE IF EXISTS `" . self::getTable() . "`"); @@ -297,6 +299,7 @@ public function showFormForItem($itemtype, $items_id, $id = -1) */ public static function getAlreadyTranslatedForItem($itemtype, $items_id) { + /** @var DBmysql $DB */ global $DB; $iterator = $DB->request( diff --git a/inc/profile.class.php b/inc/profile.class.php index f9509dda..7f518bf8 100644 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -47,6 +47,7 @@ class PluginFieldsProfile extends CommonDBRelation */ public static function installBaseData(Migration $migration, $version) { + /** @var DBmysql $DB */ global $DB; $default_charset = DBConnection::getDefaultCharset(); @@ -75,6 +76,7 @@ public static function installBaseData(Migration $migration, $version) public static function uninstall() { + /** @var DBmysql $DB */ global $DB; $DB->query("DROP TABLE IF EXISTS `" . self::getTable() . "`"); @@ -200,6 +202,7 @@ public static function deleteProfile(Profile $profile) public static function getRightOnContainer(int $profile_id, int $container_id): int { + /** @var DBmysql $DB */ global $DB; $container_profile = $DB->request( diff --git a/inc/statusoverride.class.php b/inc/statusoverride.class.php index 4413d9c8..d46dc878 100644 --- a/inc/statusoverride.class.php +++ b/inc/statusoverride.class.php @@ -47,6 +47,7 @@ class PluginFieldsStatusOverride extends CommonDBChild */ public static function installBaseData(Migration $migration, $version) { + /** @var DBmysql $DB */ global $DB; $default_charset = DBConnection::getDefaultCharset(); @@ -76,6 +77,7 @@ public static function installBaseData(Migration $migration, $version) public static function uninstall() { + /** @var DBmysql $DB */ global $DB; $DB->query("DROP TABLE IF EXISTS `" . self::getTable() . "`"); @@ -129,12 +131,14 @@ public function post_getFromDB() public static function getStatusItemtypes(): array { + /** @var array $CFG_GLPI */ global $CFG_GLPI; return array_merge(['Ticket', 'Change', 'Problem', 'Project', 'ProjectTask'], $CFG_GLPI['state_types']); } public static function countOverridesForContainer(int $container_id) { + /** @var DBmysql $DB */ global $DB; $fields_table = PluginFieldsField::getTable(); @@ -166,6 +170,7 @@ public static function countOverridesForContainer(int $container_id) public static function getOverridesForContainer(int $container_id): array { + /** @var DBmysql $DB */ global $DB; $fields_table = PluginFieldsField::getTable(); @@ -237,6 +242,7 @@ public static function getOverridesForItemtypeAndStatus(int $container_id, strin private static function getItemtypesForContainer(int $container_id): array { + /** @var DBmysql $DB */ global $DB; $iterator = $DB->request([ @@ -281,6 +287,7 @@ public static function getStatusFieldName(string $itemtype): string private static function addStatusNames(array &$overrides): void { + /** @var DBmysql $DB */ global $DB; $statuses = [ @@ -319,6 +326,7 @@ private static function addStatusNames(array &$overrides): void private static function getFieldsChoiceForContainer(int $container_id): array { + /** @var DBmysql $DB */ global $DB; $iterator = $DB->request([ @@ -346,6 +354,7 @@ private static function getFieldsChoiceForContainer(int $container_id): array public static function getStatusDropdownForItemtype(string $itemtype, array $values = []): string { + /** @var DBmysql $DB */ global $DB; $statuses = []; diff --git a/inc/toolbox.class.php b/inc/toolbox.class.php index 88826949..1c8ef656 100644 --- a/inc/toolbox.class.php +++ b/inc/toolbox.class.php @@ -98,6 +98,7 @@ private function replaceIntByLetters($str) */ public function fixFieldsNames(Migration $migration, $condition) { + /** @var DBmysql $DB */ global $DB; $bad_named_fields = []; @@ -207,6 +208,10 @@ public function fixFieldsNames(Migration $migration, $condition) */ public static function getGlpiItemtypes(): array { + /** + * @var array $CFG_GLPI + * @var array $PLUGIN_HOOKS + */ global $CFG_GLPI, $PLUGIN_HOOKS; $assets_itemtypes = [ diff --git a/setup.php b/setup.php index 42b187f5..40ee8750 100644 --- a/setup.php +++ b/setup.php @@ -73,6 +73,7 @@ */ function plugin_init_fields() { + /** @var array $PLUGIN_HOOKS */ global $PLUGIN_HOOKS; $PLUGIN_HOOKS['csrf_compliant']['fields'] = true; @@ -93,7 +94,7 @@ function plugin_init_fields() // When a Category is changed during ticket creation if ( - isset($_POST) && !empty($_POST) + !empty($_POST) && isset($_POST['_plugin_fields_type']) && $_SERVER['REQUEST_URI'] ?? '' == Ticket::getFormURL() ) { @@ -235,6 +236,7 @@ function plugin_fields_check_prerequisites() */ function plugin_fields_checkFiles() { + /** @var DBmysql $DB */ global $DB; // Clean all existing files @@ -262,6 +264,7 @@ function plugin_fields_checkFiles() function plugin_fields_exportBlockAsYaml($container_id = null) { + /** @var DBmysql $DB */ global $DB; $yaml_conf = [