From b20491503a7acd6543e9cb23837b908669486e98 Mon Sep 17 00:00:00 2001 From: Romain Lecouvreur <102067890+RomainLvr@users.noreply.github.com> Date: Mon, 20 Jan 2025 16:28:29 +0100 Subject: [PATCH] Refractor phpstan level 5 (#408) * Refractor phpstan level 5 * Update inc/profile.class.php Co-authored-by: Romain B. <8530352+Rom1-B@users.noreply.github.com> * Update composer & apply suggestions * Fix code * Fix phpstan --------- Co-authored-by: Romain B. <8530352+Rom1-B@users.noreply.github.com> --- ajax/dropdownReference.php | 2 +- composer.json | 4 +- composer.lock | 138 ++++++++++++++-------------- front/order.form.php | 2 +- front/order_supplier.form.php | 2 +- front/reference.form.php | 4 +- front/surveysupplier.form.php | 2 +- hook.php | 3 - inc/bill.class.php | 27 +++--- inc/config.class.php | 4 - inc/link.class.php | 31 +++---- inc/order.class.php | 72 +++++++-------- inc/order_item.class.php | 149 ++++++++++++++++++------------- inc/order_supplier.class.php | 6 +- inc/preference.class.php | 8 +- inc/profile.class.php | 9 +- inc/reception.class.php | 38 ++++---- inc/reference.class.php | 18 ++-- inc/reference_supplier.class.php | 20 +++-- inc/surveysupplier.class.php | 11 ++- phpstan.neon | 3 +- 21 files changed, 287 insertions(+), 266 deletions(-) diff --git a/ajax/dropdownReference.php b/ajax/dropdownReference.php index cb144f2bd9..3a272320a4 100644 --- a/ajax/dropdownReference.php +++ b/ajax/dropdownReference.php @@ -37,7 +37,7 @@ // Make a select box for references if (isset($_POST["itemtype"])) { - $entity_restrict = getEntitiesRestrictRequest("AND", 'r', '', $_POST['entities_id'], 1); + $entity_restrict = getEntitiesRestrictRequest("AND", 'r', '', $_POST['entities_id'], true); $query = "SELECT s.`plugin_order_references_id` as id, s.`price_taxfree`, s.`reference_code`, r.`name` FROM `glpi_plugin_order_references_suppliers` s LEFT JOIN `glpi_plugin_order_references` r diff --git a/composer.json b/composer.json index dc77b0d374..d976f2b31c 100644 --- a/composer.json +++ b/composer.json @@ -7,8 +7,8 @@ "glpi-project/tools": "^0.7", "php-parallel-lint/php-parallel-lint": "^1.4", "phpstan/extension-installer": "^1.4", - "phpstan/phpstan": "^1.12", - "phpstan/phpstan-deprecation-rules": "^1.2", + "phpstan/phpstan": "^2.1", + "phpstan/phpstan-deprecation-rules": "^2.0", "squizlabs/php_codesniffer": "^3.11" }, "config": { diff --git a/composer.lock b/composer.lock index 094ac87754..b98119de79 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": "7c6d9484eb6a71163038516a0f85a57b", + "content-hash": "c073a2582f64321eaa468b32972d0073", "packages": [ { "name": "masnathan/odtphp", @@ -233,20 +233,20 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.7", + "version": "2.1.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "dc2b9976bd8b0f84ec9b0e50cc35378551de7af0" + "reference": "cd6e973e04b4c2b94c86e8612b5a65f0da0e08e7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/dc2b9976bd8b0f84ec9b0e50cc35378551de7af0", - "reference": "dc2b9976bd8b0f84ec9b0e50cc35378551de7af0", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/cd6e973e04b4c2b94c86e8612b5a65f0da0e08e7", + "reference": "cd6e973e04b4c2b94c86e8612b5a65f0da0e08e7", "shasum": "" }, "require": { - "php": "^7.2|^8.0" + "php": "^7.4|^8.0" }, "conflict": { "phpstan/phpstan-shim": "*" @@ -287,30 +287,30 @@ "type": "github" } ], - "time": "2024-10-18T11:12:07+00:00" + "time": "2025-01-05T16:43:48+00:00" }, { "name": "phpstan/phpstan-deprecation-rules", - "version": "1.2.1", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-deprecation-rules.git", - "reference": "f94d246cc143ec5a23da868f8f7e1393b50eaa82" + "reference": "1cc1259cb91ee4cfbb5c39bca9f635f067c910b4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/f94d246cc143ec5a23da868f8f7e1393b50eaa82", - "reference": "f94d246cc143ec5a23da868f8f7e1393b50eaa82", + "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/1cc1259cb91ee4cfbb5c39bca9f635f067c910b4", + "reference": "1cc1259cb91ee4cfbb5c39bca9f635f067c910b4", "shasum": "" }, "require": { - "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.12" + "php": "^7.4 || ^8.0", + "phpstan/phpstan": "^2.0" }, "require-dev": { "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/phpstan-phpunit": "^1.0", - "phpunit/phpunit": "^9.5" + "phpstan/phpstan-phpunit": "^2.0", + "phpunit/phpunit": "^9.6" }, "type": "phpstan-extension", "extra": { @@ -332,9 +332,9 @@ "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/1.2.1" + "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/2.0.1" }, - "time": "2024-09-11T15:52:35+00:00" + "time": "2024-11-28T21:56:36+00:00" }, { "name": "psr/container", @@ -466,16 +466,16 @@ }, { "name": "symfony/console", - "version": "v5.4.44", + "version": "v5.4.47", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "5b5a0aa66e3296e303e22490f90f521551835a83" + "reference": "c4ba980ca61a9eb18ee6bcc73f28e475852bb1ed" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/5b5a0aa66e3296e303e22490f90f521551835a83", - "reference": "5b5a0aa66e3296e303e22490f90f521551835a83", + "url": "https://api.github.com/repos/symfony/console/zipball/c4ba980ca61a9eb18ee6bcc73f28e475852bb1ed", + "reference": "c4ba980ca61a9eb18ee6bcc73f28e475852bb1ed", "shasum": "" }, "require": { @@ -545,7 +545,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v5.4.44" + "source": "https://github.com/symfony/console/tree/v5.4.47" }, "funding": [ { @@ -561,20 +561,20 @@ "type": "tidelift" } ], - "time": "2024-09-20T07:56:40+00:00" + "time": "2024-11-06T11:30:55+00:00" }, { "name": "symfony/deprecation-contracts", - "version": "v2.5.3", + "version": "v2.5.4", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "80d075412b557d41002320b96a096ca65aa2c98d" + "reference": "605389f2a7e5625f273b53960dc46aeaf9c62918" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/80d075412b557d41002320b96a096ca65aa2c98d", - "reference": "80d075412b557d41002320b96a096ca65aa2c98d", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/605389f2a7e5625f273b53960dc46aeaf9c62918", + "reference": "605389f2a7e5625f273b53960dc46aeaf9c62918", "shasum": "" }, "require": { @@ -582,12 +582,12 @@ }, "type": "library", "extra": { + "thanks": { + "url": "https://github.com/symfony/contracts", + "name": "symfony/contracts" + }, "branch-alias": { "dev-main": "2.5-dev" - }, - "thanks": { - "name": "symfony/contracts", - "url": "https://github.com/symfony/contracts" } }, "autoload": { @@ -612,7 +612,7 @@ "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v2.5.3" + "source": "https://github.com/symfony/deprecation-contracts/tree/v2.5.4" }, "funding": [ { @@ -628,7 +628,7 @@ "type": "tidelift" } ], - "time": "2023-01-24T14:02:46+00:00" + "time": "2024-09-25T14:11:13+00:00" }, { "name": "symfony/polyfill-ctype", @@ -656,8 +656,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -732,8 +732,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -810,8 +810,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -894,8 +894,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -968,8 +968,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -1044,8 +1044,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -1124,8 +1124,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -1182,16 +1182,16 @@ }, { "name": "symfony/service-contracts", - "version": "v2.5.3", + "version": "v2.5.4", "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", - "reference": "a2329596ddc8fd568900e3fc76cba42489ecc7f3" + "reference": "f37b419f7aea2e9abf10abd261832cace12e3300" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/a2329596ddc8fd568900e3fc76cba42489ecc7f3", - "reference": "a2329596ddc8fd568900e3fc76cba42489ecc7f3", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/f37b419f7aea2e9abf10abd261832cace12e3300", + "reference": "f37b419f7aea2e9abf10abd261832cace12e3300", "shasum": "" }, "require": { @@ -1207,12 +1207,12 @@ }, "type": "library", "extra": { + "thanks": { + "url": "https://github.com/symfony/contracts", + "name": "symfony/contracts" + }, "branch-alias": { "dev-main": "2.5-dev" - }, - "thanks": { - "name": "symfony/contracts", - "url": "https://github.com/symfony/contracts" } }, "autoload": { @@ -1245,7 +1245,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/service-contracts/tree/v2.5.3" + "source": "https://github.com/symfony/service-contracts/tree/v2.5.4" }, "funding": [ { @@ -1261,20 +1261,20 @@ "type": "tidelift" } ], - "time": "2023-04-21T15:04:16+00:00" + "time": "2024-09-25T14:11:13+00:00" }, { "name": "symfony/string", - "version": "v5.4.44", + "version": "v5.4.47", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "832caa16b6d9aac6bf11747315225f5aba384c24" + "reference": "136ca7d72f72b599f2631aca474a4f8e26719799" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/832caa16b6d9aac6bf11747315225f5aba384c24", - "reference": "832caa16b6d9aac6bf11747315225f5aba384c24", + "url": "https://api.github.com/repos/symfony/string/zipball/136ca7d72f72b599f2631aca474a4f8e26719799", + "reference": "136ca7d72f72b599f2631aca474a4f8e26719799", "shasum": "" }, "require": { @@ -1331,7 +1331,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v5.4.44" + "source": "https://github.com/symfony/string/tree/v5.4.47" }, "funding": [ { @@ -1347,20 +1347,20 @@ "type": "tidelift" } ], - "time": "2024-09-20T07:56:40+00:00" + "time": "2024-11-10T20:33:58+00:00" }, { "name": "twig/twig", - "version": "v3.11.2", + "version": "v3.11.3", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "5b580ec1882b54c98cbd8c0f8a3ca5d1904db6b1" + "reference": "3b06600ff3abefaf8ff55d5c336cd1c4253f8c7e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/5b580ec1882b54c98cbd8c0f8a3ca5d1904db6b1", - "reference": "5b580ec1882b54c98cbd8c0f8a3ca5d1904db6b1", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/3b06600ff3abefaf8ff55d5c336cd1c4253f8c7e", + "reference": "3b06600ff3abefaf8ff55d5c336cd1c4253f8c7e", "shasum": "" }, "require": { @@ -1415,7 +1415,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.11.2" + "source": "https://github.com/twigphp/Twig/tree/v3.11.3" }, "funding": [ { @@ -1427,7 +1427,7 @@ "type": "tidelift" } ], - "time": "2024-11-06T18:50:16+00:00" + "time": "2024-11-07T12:34:41+00:00" } ], "aliases": [], diff --git a/front/order.form.php b/front/order.form.php index 5da6946541..2698f07cbc 100644 --- a/front/order.form.php +++ b/front/order.form.php @@ -76,7 +76,7 @@ $id = $_GET['id']; } $pluginOrderOrder->check($id, DELETE); - $pluginOrderOrder->delete(['id' => $id], 1); + $pluginOrderOrder->delete(['id' => $id], true); $pluginOrderOrder->redirectToList(); } else if (isset($_POST["update"])) { /* update order */ diff --git a/front/order_supplier.form.php b/front/order_supplier.form.php index 7b47675b21..76e4e0f59f 100644 --- a/front/order_supplier.form.php +++ b/front/order_supplier.form.php @@ -62,7 +62,7 @@ } else if (isset($_POST["delete"])) { if (PluginOrderOrder_Supplier::canCreate()) { foreach ($_POST["check"] as $ID => $value) { - if ($supplier->delete(["id" => $ID], 0, 0)) { + if ($supplier->delete(["id" => $ID], false, false)) { $new_value = __("Delete", "order") . " " . __("Supplier Detail", "order") . " : " . $ID; $order->addHistory('PluginOrderOrder', "", $new_value, $_POST["plugin_order_orders_id"]); } diff --git a/front/reference.form.php b/front/reference.form.php index 415889fff7..67c33692ab 100644 --- a/front/reference.form.php +++ b/front/reference.form.php @@ -75,7 +75,7 @@ /* purge order */ } else if (isset($_POST["purge"])) { $reference->check($_POST['id'], UPDATE); - $reference->delete($_POST, 1); + $reference->delete($_POST, true); $reference->redirectToList(); /* update order */ @@ -89,7 +89,7 @@ Html::popheader( PluginOrderReference::getTypeName(1), $_SERVER['PHP_SELF'], - "management", + true, "PluginOrderMenu", "references" ); diff --git a/front/surveysupplier.form.php b/front/surveysupplier.form.php index 41c2d5b2a2..dd0cf680a1 100644 --- a/front/surveysupplier.form.php +++ b/front/surveysupplier.form.php @@ -52,7 +52,7 @@ } else if (isset($_POST["delete"])) { if (PluginOrderSurveySupplier::canCreate()) { foreach ($_POST["check"] as $ID => $value) { - $PluginOrderSurveySupplier->delete(["id" => $ID], 0, 0); + $PluginOrderSurveySupplier->delete(["id" => $ID], false, false); } } Html::redirect($_SERVER['HTTP_REFERER']); diff --git a/hook.php b/hook.php index 176a015e61..17b03dc212 100644 --- a/hook.php +++ b/hook.php @@ -323,7 +323,6 @@ function plugin_order_giveItem($type, $ID, $data, $num) } else { return " "; } - break; case "glpi_plugin_order_references.models_id": if (file_exists(GLPI_ROOT . "/src/" . $itemtype . "Model.php")) { return Dropdown::getDropdownName( @@ -333,14 +332,12 @@ function plugin_order_giveItem($type, $ID, $data, $num) } else { return " "; } - break; case "glpi_plugin_order_references.templates_id": if (!$itemnum) { return " "; } else { return $reference->getTemplateName($itemtype, $itemnum); } - break; } return ""; } diff --git a/inc/bill.class.php b/inc/bill.class.php index f5382450a2..24d496dd42 100644 --- a/inc/bill.class.php +++ b/inc/bill.class.php @@ -299,23 +299,23 @@ public static function showItems(PluginOrderBill $bill) if ($data['itemtype'] == 'PluginOrderReferenceFree') { $reference = new PluginOrderReferenceFree(); - $reference->getFromDB($data["plugin_order_references_id"]); + $reference->getFromDB((int) $data["plugin_order_references_id"]); } else { $reference = new PluginOrderReference(); - $reference->getFromDB($data["plugin_order_references_id"]); + $reference->getFromDB((int) $data["plugin_order_references_id"]); } echo ""; if (PluginOrderReference::canView()) { echo $reference->getLink(); } else { - echo $reference->getName(true); + echo $reference->getName(); } echo ""; echo ""; Dropdown::getDropdownName( "glpi_plugin_order_deliverystates", - $data["plugin_order_deliverystates_id"] + (int) $data["plugin_order_deliverystates_id"] ); echo ""; echo ""; @@ -438,7 +438,7 @@ public static function showOrder($data_ref, $result_ref, $canedit, $order, $refe if (file_exists($CFG_GLPI['root_doc'] . "/src/" . $data["itemtype"] . "Type.php")) { echo Dropdown::getDropdownName( getTableForItemType($data["itemtype"] . "Type"), - $data["types_id"] + (int) $data["types_id"] ); } echo ""; @@ -448,14 +448,14 @@ public static function showOrder($data_ref, $result_ref, $canedit, $order, $refe if (file_exists($CFG_GLPI['root_doc'] . "/src/" . $data["itemtype"] . "Model.php")) { echo Dropdown::getDropdownName( getTableForItemType($data["itemtype"] . "Model"), - $data["models_id"] + (int) $data["models_id"] ); } $bill = new PluginOrderBill(); echo ""; if ($data["plugin_order_bills_id"] > 0) { - if ($bill->can($data['plugin_order_bills_id'], READ)) { - echo "" . $bill->getName(true) . ""; + if ($bill->can((int) $data['plugin_order_bills_id'], READ)) { + echo "" . $bill->getName() . ""; } else { echo $bill->getName(); } @@ -464,7 +464,7 @@ public static function showOrder($data_ref, $result_ref, $canedit, $order, $refe echo ""; echo Dropdown::getDropdownName( getTableForItemType('PluginOrderBillState'), - $data['plugin_order_billstates_id'] + (int) $data['plugin_order_billstates_id'] ); echo ""; echo ""; @@ -607,13 +607,15 @@ public static function uninstall() } + /** + * @return array|string + */ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if (!$withtemplate) { switch ($item->getType()) { case 'PluginOrderOrder': return self::getTypeName(); - break; case __CLASS__: $ong[1] = __("Orders", "order"); $ong[2] = _n("Associated item", "Associated items", 2); @@ -626,11 +628,10 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { - - if ($item->getType() == 'PluginOrderOrder') { + if ($item instanceof PluginOrderOrder) { $order_item = new PluginOrderOrder_Item(); $order_item->showBillsItems($item); - } else if ($item->getType() == __CLASS__) { + } else if ($item instanceof self) { switch ($tabnum) { case 1: self::showOrdersItems($item); diff --git a/inc/config.class.php b/inc/config.class.php index 39362357d1..e597c9a8d6 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -792,7 +792,6 @@ public static function install(Migration $migration) $config = new self(); $config->getFromDB(1); - $templateID = false; $migration->addField($table, "tickettemplates_id_delivery", "int {$default_key_sign} NOT NULL default '0'"); $migration->migrationOneTable($table); @@ -808,9 +807,6 @@ public static function install(Migration $migration) $migration->addField($table, "transmit_budget_change", "bool"); $migration->migrationOneTable($table); - if ($templateID) { - $config->update(['id' => 1, 'tickettemplates_id_delivery' => $templateID]); - } //version 2.0.1 $migration->addField($table, "use_free_reference", "bool"); diff --git a/inc/link.class.php b/inc/link.class.php index ded894a6d7..079c27f925 100644 --- a/inc/link.class.php +++ b/inc/link.class.php @@ -476,7 +476,7 @@ public function showOrderLinkItem($numref, $data_ref, $canedit, $plugin_order_or echo "" . __("Serial number") . ""; foreach ($all_data as $data) { - $detailID = $data["IDD"]; + $detailID = (int) $data["IDD"]; echo ""; @@ -504,10 +504,10 @@ public function showOrderLinkItem($numref, $data_ref, $canedit, $plugin_order_or echo "" . $PluginOrderReference->getReceptionReferenceLink($data) . ""; } echo "" . $PluginOrderReception->getReceptionStatus($detailID) . ""; - echo "" . Dropdown::getDropdownName(getTableForItemType(Entity::class), $data["entities_id"]) . ""; + echo "" . Dropdown::getDropdownName(getTableForItemType(Entity::class), (int) $data["entities_id"]) . ""; echo "" . Html::convDate($data["delivery_date"]) . ""; echo "" . $this->getReceptionItemName($data["items_id"], $data["itemtype"]); - echo "" . $this->getItemSerialNumber($data["items_id"], $data["itemtype"]) . ""; + echo "" . $this->getItemSerialNumber((int) $data["items_id"], $data["itemtype"]) . ""; } echo ""; echo ""; @@ -584,7 +584,6 @@ public static function showMassiveActionsSubForm(MassiveAction $ma) switch ($ma->getAction()) { case 'generation': return $link->showItemGenerationForm($ma->POST); - break; case 'createLink': $reference->getFromDB($ma->POST["plugin_order_references_id"]); $reference->dropdownAllItemsByType( @@ -630,7 +629,7 @@ public static function processMassiveActionsForOneItemtype( ] ], 'WHERE' => [ - 'glpi_plugin_order_orders_items.id' => array_keys($ma->items[__CLASS__]) + 'glpi_plugin_order_orders_items.id' => array_keys($ma->getItems()[__CLASS__]) ] ]); foreach ($additional_data_ite as $add_values) { @@ -642,7 +641,7 @@ public static function processMassiveActionsForOneItemtype( switch ($ma->getAction()) { case 'generation': $newIDs = $link->generateNewItem($ma->POST); - foreach ($ma->items[__CLASS__] as $key => $val) { + foreach ($ma->getItems()[__CLASS__] as $key => $val) { if (isset($newIDs[$key]) && $newIDs[$key]) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { @@ -658,11 +657,11 @@ public static function processMassiveActionsForOneItemtype( foreach ($ids as $id) { $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO); } - return false; + break; } $order_item = new PluginOrderOrder_Item(); - foreach ($ma->items[__CLASS__] as $key => $val) { + foreach ($ma->getItems()[__CLASS__] as $key => $val) { $order_item->getFromDB($val); if ($order_item->fields["states_id"] == PluginOrderOrder::ORDER_DEVICE_NOT_DELIVRED) { $ma->addMessage(__("Cannot link items not delivered", "order")); @@ -680,7 +679,7 @@ public static function processMassiveActionsForOneItemtype( break; case 'deleteLink': - foreach ($ma->items[__CLASS__] as $key => $val) { + foreach ($ma->getItems()[__CLASS__] as $key => $val) { $link->deleteLinkWithItem( $key, $ma->POST['add_items'][$key]['itemtype'], @@ -808,7 +807,7 @@ public function generateInfoComRelatedToOrder($entity, $detailID, $itemtype, $it $fields["immo_number"] = autoName( $fields["immo_number"], "immo_number", - 1, + true, 'Infocom', $entity ); @@ -1169,14 +1168,8 @@ public function generateNewItem($params) unset($item->fields["date_mod"]); $input = []; - $fields = []; foreach ($item->fields as $key => $value) { - if ( - $value != '' - && (!isset($fields[$key]) - || $fields[$key] == '' - || $fields[$key] == 0) - ) { + if ($value != '') { $input[$key] = $value; } } @@ -1340,7 +1333,7 @@ public static function countForOrder(PluginOrderOrder $item) public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if ( - $item->getType() == 'PluginOrderOrder' + $item instanceof PluginOrderOrder && $item->checkIfDetailExists($item->getID(), true) && Session::haveRight('plugin_order_order', READ) ) { @@ -1355,7 +1348,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { - if ($item->getType() == 'PluginOrderOrder') { + if ($item instanceof PluginOrderOrder) { $link = new self(); $link->showOrderLink($item->getID()); } diff --git a/inc/order.class.php b/inc/order.class.php index 8fe6e708bc..1acf180f50 100644 --- a/inc/order.class.php +++ b/inc/order.class.php @@ -660,34 +660,35 @@ public function defineTabs($options = []) return $ong; } - + /** + * @return array|string + */ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { - switch ($item->getType()) { - case 'Budget': - return __("Orders", "order"); - case __CLASS__: - $ong = []; - $config = PluginOrderConfig::getConfig(); - if ( - Session::haveRightsOr("plugin_order_order", [ - self::RIGHT_VALIDATION, - self::RIGHT_CANCEL, - self::RIGHT_UNDO_VALIDATION - ]) - ) { - $ong[1] = __("Validation", "order"); - } - if ( - $config->canGenerateOrderPDF() - && ($item->getState() > PluginOrderOrderState::DRAFT - || $this->canGenerateWithoutValidation()) - ) { - // generation - $ong[2] = __("Purchase order", "order"); - } + if ($item instanceof Budget) { + return __("Orders", "order"); + } else if ($item instanceof self) { + $ong = []; + $config = PluginOrderConfig::getConfig(); + if ( + Session::haveRightsOr("plugin_order_order", [ + self::RIGHT_VALIDATION, + self::RIGHT_CANCEL, + self::RIGHT_UNDO_VALIDATION + ]) + ) { + $ong[1] = __("Validation", "order"); + } + if ( + $config->canGenerateOrderPDF() + && ($item->getState() > PluginOrderOrderState::DRAFT + || $this->canGenerateWithoutValidation()) + ) { + // generation + $ong[2] = __("Purchase order", "order"); + } - return $ong; + return $ong; } return ''; } @@ -698,9 +699,9 @@ public static function displayTabContentForItem( $tabnum = 1, $withtemplate = 0 ) { - if ($item->getType() == 'Budget') { + if ($item instanceof Budget) { self::showForBudget($item->getField('id')); - } else if ($item->getType() == __CLASS__) { + } else if ($item instanceof self) { switch ($tabnum) { case 1: $item->showValidationForm($item->getID()); @@ -897,7 +898,7 @@ public function showForm($ID, $options = []) "; - return; + return true; } $this->initForm($ID, $options); @@ -1820,7 +1821,7 @@ public function generateOrder($params) ); $tax = new PluginOrderOrderTax(); - $tax->getFromDB($data["plugin_order_ordertaxes_id"]); + $tax->getFromDB((int) $data["plugin_order_ordertaxes_id"]); $listeArticles[] = [ 'quantity' => $quantity, @@ -1848,7 +1849,7 @@ public function generateOrder($params) ); $tax = new PluginOrderOrderTax(); - $tax->getFromDB($data["plugin_order_ordertaxes_id"]); + $tax->getFromDB((int) $data["plugin_order_ordertaxes_id"]); $listeArticles[] = [ 'quantity' => $quantity, @@ -1872,9 +1873,9 @@ public function generateOrder($params) $articleValues['titleArticle'] = $element['ref']; $articleValues['refArticle'] = $element['refnumber']; $articleValues['TVAArticle'] = $element['taxe']; - $articleValues['HTPriceArticle'] = Html::formatNumber($element['price_taxfree']); + $articleValues['HTPriceArticle'] = Html::formatNumber((float) $element['price_taxfree']); if ($element['discount'] != 0) { - $articleValues['discount'] = Html::formatNumber($element['discount']) . " %"; + $articleValues['discount'] = Html::formatNumber((float) $element['discount']) . " %"; } else { $articleValues['discount'] = ""; } @@ -2402,7 +2403,7 @@ public static function showMassiveActionsSubForm(MassiveAction $ma) Html::submit(_x('button', 'Post'), ['name' => 'massiveaction']); return true; } - return ""; + return true; } @@ -2448,7 +2449,6 @@ public static function processMassiveActionsForOneItemtype(MassiveAction $ma, Co } } return; - break; } return; } @@ -2856,7 +2856,9 @@ public static function install(Migration $migration) //Remove unused notifications $notification = new Notification(); - $notification->deleteByCriteria("`itemtype`='PluginOrderOrder_Item'"); + $notification->deleteByCriteria([ + 'itemtype' => 'PluginOrderOrder_Item', + ]); //2.7.0 $migration->addField($table, "global_discount", "FLOAT NOT NULL default '0'"); diff --git a/inc/order_item.class.php b/inc/order_item.class.php index be391a043a..4e293e4ef5 100644 --- a/inc/order_item.class.php +++ b/inc/order_item.class.php @@ -217,7 +217,7 @@ public function rawSearchOptions() } - public static function updateItem($item) + public static function updateItem(CommonDBTM $item) { //TO DO : Must do check same values or update infocom @@ -285,7 +285,6 @@ public static function updateItem($item) } } - public static function getClasses($all = false) { /** @var array $ORDER_TYPES */ @@ -904,15 +903,19 @@ public function getItems($rand, $data_ref, $plugin_order_orders_id, $numref, $ca echo "function showQuantity$rand() {\n"; echo "$('#quantity$rand').hide();"; echo "$('#viewaccept$rand').show();"; - Ajax::updateItemJsCode("viewquantity$rand", Plugin::getWebDir('order') . "/ajax/inputnumber.php", [ - 'maxlength' => 15, - 'size' => 8, - 'name' => 'quantity', - 'class' => 'quantity', - 'force_integer' => true, - 'min' => rawurlencode($quantity), - 'data' => rawurlencode($quantity) - ], false); + Ajax::updateItemJsCode( + "viewquantity$rand", + Plugin::getWebDir('order') . "/ajax/inputnumber.php", + [ + 'maxlength' => 15, + 'size' => 8, + 'name' => 'quantity', + 'class' => 'quantity', + 'force_integer' => true, + 'min' => rawurlencode($quantity), + 'data' => rawurlencode($quantity) + ] + ); echo "}"; echo "\n"; echo "
\n"; @@ -1005,13 +1008,17 @@ public function getItems($rand, $data_ref, $plugin_order_orders_id, $numref, $ca echo "function showPricetaxfree$rand() {\n"; echo "$('#pricetaxfree$rand').hide();"; echo "$('#viewaccept$rand').show();"; - Ajax::updateItemJsCode("viewpricetaxfree$rand", Plugin::getWebDir('order') . "/ajax/inputnumber.php", [ - 'maxlength' => 15, - 'size' => 8, - 'name' => 'price_taxfree', - 'class' => 'decimal', - 'data' => rawurlencode($price_taxfree) - ], false); + Ajax::updateItemJsCode( + "viewpricetaxfree$rand", + Plugin::getWebDir('order') . "/ajax/inputnumber.php", + [ + 'maxlength' => 15, + 'size' => 8, + 'name' => 'price_taxfree', + 'class' => 'decimal', + 'data' => rawurlencode($price_taxfree) + ] + ); echo "}"; echo "\n"; echo "
\n"; @@ -1031,13 +1038,17 @@ public function getItems($rand, $data_ref, $plugin_order_orders_id, $numref, $ca echo "function showDiscount$rand() {\n"; echo "$('#discount$rand').hide();"; echo "$('#viewaccept$rand').show();"; - Ajax::updateItemJsCode("viewdiscount$rand", Plugin::getWebDir('order') . "/ajax/inputnumber.php", [ - 'maxlength' => 15, - 'size' => 8, - 'name' => 'discount', - 'class' => 'smalldecimal', - 'data' => rawurlencode($discount) - ], false); + Ajax::updateItemJsCode( + "viewdiscount$rand", + Plugin::getWebDir('order') . "/ajax/inputnumber.php", + [ + 'maxlength' => 15, + 'size' => 8, + 'name' => 'discount', + 'class' => 'smalldecimal', + 'data' => rawurlencode($discount) + ] + ); echo "}"; echo "\n"; echo "
\n"; @@ -1133,7 +1144,7 @@ public function getItems($rand, $data_ref, $plugin_order_orders_id, $numref, $ca while ($data = $DB->fetchArray($result)) { $rand_line = mt_rand(); - Session::addToNavigateListItems($this->getType(), $data['IDD']); + Session::addToNavigateListItems($this->getType(), (int) $data['IDD']); // Compute for detail_hideForm javascript function $hideForm .= "$('#detail_pricetaxfree$rand_line').show();\n"; @@ -1182,31 +1193,35 @@ public function getItems($rand, $data_ref, $plugin_order_orders_id, $numref, $ca echo "function showDetailPricetaxfree$rand_line() {\n"; echo "$('#detail_pricetaxfree$rand_line').hide();"; echo "$('#detail_viewaccept$global_rand').show();"; - Ajax::updateItemJsCode("detail_viewpricetaxfree$rand_line", Plugin::getWebDir('order') . "/ajax/inputnumber.php", [ - 'maxlength' => 15, - 'size' => 8, - 'name' => 'detail_price_taxfree[' . $data["IDD"] . ']', - 'class' => 'decimal', - 'data' => rawurlencode($data["price_taxfree"]) - ], false); + Ajax::updateItemJsCode( + "detail_viewpricetaxfree$rand_line", + Plugin::getWebDir('order') . "/ajax/inputnumber.php", + [ + 'maxlength' => 15, + 'size' => 8, + 'name' => 'detail_price_taxfree[' . $data["IDD"] . ']', + 'class' => 'decimal', + 'data' => rawurlencode($data["price_taxfree"]) + ] + ); echo "}"; echo "\n"; echo "
\n"; - echo Html::formatNumber($data["price_taxfree"]); + echo Html::formatNumber((float) $data["price_taxfree"]); echo "
"; echo "
\n"; echo "
"; echo ""; } else { - echo "" . Html::formatNumber($data["price_taxfree"]) . ""; + echo "" . Html::formatNumber((float) $data["price_taxfree"]) . ""; } /* taxe */ echo ""; echo Dropdown::getDropdownName( getTableForItemType("PluginOrderOrderTax"), - $data["plugin_order_ordertaxes_id"] + (int) $data["plugin_order_ordertaxes_id"] ); echo ""; /* reduction */ @@ -1219,29 +1234,33 @@ public function getItems($rand, $data_ref, $plugin_order_orders_id, $numref, $ca echo "function showDetailDiscount$rand_line() {\n"; echo "$('#detail_discount$rand_line').hide();"; echo "$('#detail_viewaccept$global_rand').show();"; - Ajax::updateItemJsCode("detail_viewdiscount$rand_line", Plugin::getWebDir('order') . "/ajax/inputnumber.php", [ - 'maxlength' => 15, - 'size' => 8, - 'name' => 'detail_discount[' . $data["IDD"] . ']', - 'class' => 'smalldecimal', - 'data' => rawurlencode($data["discount"]) - ], false); + Ajax::updateItemJsCode( + "detail_viewdiscount$rand_line", + Plugin::getWebDir('order') . "/ajax/inputnumber.php", + [ + 'maxlength' => 15, + 'size' => 8, + 'name' => 'detail_discount[' . $data["IDD"] . ']', + 'class' => 'smalldecimal', + 'data' => rawurlencode($data["discount"]) + ] + ); echo "}"; echo "\n"; echo "
\n"; - echo Html::formatNumber($data["discount"]); + echo Html::formatNumber((float) $data["discount"]); echo "
"; echo "
\n"; echo "
"; echo ""; } else { - echo "" . Html::formatNumber($data["discount"]) . ""; + echo "" . Html::formatNumber((float) $data["discount"]) . ""; } /* price with reduction */ - echo "" . Html::formatNumber($data["price_discounted"]) . ""; + echo "" . Html::formatNumber((float) $data["price_discounted"]) . ""; /* price ati */ - echo "" . Html::formatNumber($data["price_ati"]) . ""; + echo "" . Html::formatNumber((float) $data["price_ati"]) . ""; /* status */ echo "" . $reception->getReceptionStatus($data["IDD"]) . ""; @@ -1367,7 +1386,7 @@ public function showPluginFromItems($itemtype, $ID) $twig_option = []; $order = new PluginOrderOrder(); $order->getFromDB($infos['id']); - $twig_option['order_link'] = $order->getLink(PluginOrderOrder::canView()); + $twig_option['order_link'] = $order->getLink(); $result = getAllDataFromTable( self::getTable(), @@ -1382,7 +1401,7 @@ public function showPluginFromItems($itemtype, $ID) $reference = new PluginOrderReference(); $reference->getFromDB($link['plugin_order_references_id']); if (Session::haveRight('plugin_order_reference', READ)) { - $twig_option['reference_link'] = $reference->getLink(PluginOrderReference::canView()); + $twig_option['reference_link'] = $reference->getLink(); } $twig_option['delivery_date'] = Html::convDate($link["delivery_date"]); } @@ -1432,7 +1451,7 @@ public function showForm($ID, $options = []) echo "" . __("Order", "order") . ": "; echo ""; - echo $order_order->getLink(true); + echo $order_order->getLink(); echo ""; echo "" . __("Reference") . ": "; @@ -1575,12 +1594,12 @@ public function showBillsItems(PluginOrderOrder $order) "' GROUP BY `plugin_order_bills_id`") as $item ) { if ( - isset($item->fields['plugin_order_bills_id']) - && $item->fields['plugin_order_bills_id'] + isset($item['plugin_order_bills_id']) + && $item['plugin_order_bills_id'] ) { echo ""; - if ($bill->can($item->fields['plugin_order_bills_id'], READ)) { - echo "" . $bill->getName() . ""; + if ($bill->can($item['plugin_order_bills_id'], READ)) { + echo "" . $bill->getName() . ""; } else { echo "" . $bill->getName() . ""; } @@ -1723,7 +1742,7 @@ public function showBillsItemsDetail($data_ref, $result_ref, $canedit, $order, $ if (file_exists(GLPI_ROOT . "/src/" . $data["itemtype"] . "Type.php")) { echo Dropdown::getDropdownName( getTableForItemType($data["itemtype"] . "Type"), - $data["types_id"] + (int) $data["types_id"] ); } echo ""; @@ -1732,14 +1751,14 @@ public function showBillsItemsDetail($data_ref, $result_ref, $canedit, $order, $ if (file_exists(GLPI_ROOT . "/src/" . $data["itemtype"] . "Model.php")) { echo Dropdown::getDropdownName( getTableForItemType($data["itemtype"] . "Model"), - $data["models_id"] + (int) $data["models_id"] ); } $bill = new PluginOrderBill(); echo ""; if ($data["plugin_order_bills_id"] > 0) { - if ($bill->can($data['plugin_order_bills_id'], READ)) { - echo "" . $bill->getName(true) . ""; + if ($bill->can((int) $data['plugin_order_bills_id'], READ)) { + echo "" . $bill->getName() . ""; } else { echo $bill->getName(); } @@ -1748,7 +1767,7 @@ public function showBillsItemsDetail($data_ref, $result_ref, $canedit, $order, $ echo ""; echo Dropdown::getDropdownName( getTableForItemType('PluginOrderBillState'), - $data['plugin_order_billstates_id'] + (int) $data['plugin_order_billstates_id'] ); echo ""; echo ""; @@ -1815,7 +1834,7 @@ public function updateQuantity($post) ); $item = $DB->fetchArray($data); - $this->getFromDB($item['id']); + $this->getFromDB((int) $item['id']); $to_add = $post['quantity'] - $quantity; $this->addDetails( $this->fields['plugin_order_references_id'], @@ -2115,9 +2134,10 @@ public static function countForItem(CommonDBTM $item) public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { + /** @var CommonDBTM $item */ if (in_array(get_class($item), PluginOrderOrder_Item::getClasses(true))) { $orderlink = new PluginOrderLink(); - if (!$orderlink->isItemLinkedToOrder(get_class($item), $item->getID())) { + if (!$orderlink->isItemLinkedToOrder(get_class($item), $item->getField('id'))) { return ''; } @@ -2139,12 +2159,15 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { - if (get_class($item) == 'PluginOrderOrder') { + if ($item instanceof PluginOrderOrder) { if (!$item->fields['is_template']) { $order_item = new self(); $order_item->showItem($item->getID()); } - } else if (in_array($item->getType(), PluginOrderOrder_Item::getClasses(true))) { + } else if ( + is_subclass_of($item, CommonDBTM::class) + && in_array($item->getType(), PluginOrderOrder_Item::getClasses(true)) + ) { $order_item = new self(); $order_item->showPluginFromItems(get_class($item), $item->getField('id')); } diff --git a/inc/order_supplier.class.php b/inc/order_supplier.class.php index 419a95b810..515f7338c3 100644 --- a/inc/order_supplier.class.php +++ b/inc/order_supplier.class.php @@ -455,12 +455,14 @@ public static function uninstall() } + /** + * @return array|string + */ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { switch (get_class($item)) { case 'Supplier': return [1 => __("Orders", "order")]; - break; case 'PluginOrderOrder': $config = PluginOrderConfig::getConfig(); if ($config->canUseSupplierInformations() && $item->fields['suppliers_id']) { @@ -486,7 +488,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ $order_supplier = new self(); if ($item->can($item->getID(), READ)) { self::showOrderSupplierInfos($item->getID()); - $order_supplier->showForm("", ['plugin_order_orders_id' => $item->getID()]); + $order_supplier->showForm(-1, ['plugin_order_orders_id' => $item->getID()]); } break; } diff --git a/inc/preference.class.php b/inc/preference.class.php index e1bed12bec..f8e9ca888f 100644 --- a/inc/preference.class.php +++ b/inc/preference.class.php @@ -146,7 +146,7 @@ public static function dropdownListFiles($name, $extension, $directory, $value = * * Check if at least one template exists * @since 1.5.3 - * @return true if at least one template exists, false otherwise + * @return bool true if at least one template exists, false otherwise */ public static function atLeastOneTemplateExists() { @@ -159,7 +159,7 @@ public static function atLeastOneTemplateExists() * * Check if at least one signature exists * @since 1.5.3 - * @return true if at least one signature exists, false otherwise + * @return bool true if at least one signature exists, false otherwise */ public static function atLeastOneSignatureExists() { @@ -284,7 +284,9 @@ public static function uninstall() $DB->query("DROP TABLE IF EXISTS `" . self::getTable() . "`") or die($DB->error()); } - + /** + * @return array|string + */ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if (get_class($item) == 'Preference') { diff --git a/inc/profile.class.php b/inc/profile.class.php index 0105f91e44..421440d694 100644 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -153,11 +153,12 @@ public static function uninstall() self::removeRightsFromSession(); } - + /** + * @return array|string + */ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { - $type = get_class($item); - if ($type == 'Profile') { + if ($item instanceof Profile) { if ($item->getField('id') && $item->getField('interface') != 'helpdesk') { return [1 => __("Orders", "order")]; } @@ -168,7 +169,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { - if ($item->getType() == 'Profile') { + if ($item instanceof Profile) { $prof = new self(); self::addDefaultProfileInfos($item->getID(), [ 'plugin_order_order' => 0, // All rights : CREATE + READ + ... diff --git a/inc/reception.class.php b/inc/reception.class.php index c214eeacf3..7764ef6be8 100644 --- a/inc/reception.class.php +++ b/inc/reception.class.php @@ -44,8 +44,6 @@ class PluginOrderReception extends CommonDBChild public static $checkParentRights = self::DONT_CHECK_ITEM_RIGHTS; - private $table; - public static function getTable($classname = null) { @@ -83,19 +81,21 @@ public function getFromDBByOrder($plugin_order_orders_id) /** @var \DBmysql $DB */ global $DB; - $query = "SELECT * FROM `" . $this->table . "` - WHERE `plugin_order_orders_id` = '" . $plugin_order_orders_id . "' "; - if ($result = $DB->query($query)) { - if ($DB->numrows($result) != 1) { - return false; - } - $this->fields = $DB->fetchAssoc($result); + $query = [ + 'FROM' => self::getTable(), + 'WHERE' => ['plugin_order_orders_id' => $plugin_order_orders_id], + ]; + $result = $DB->request($query); + + foreach ($result as $fields) { + $this->fields = $fields; if (is_array($this->fields) && count($this->fields)) { return true; } else { return false; } } + return false; } @@ -276,7 +276,7 @@ public function showForm($ID, $options = []) 'name' => "plugin_order_bills_id", 'value' => $this->fields["plugin_order_bills_id"] ]); - } else if (Session::haveRight("plugin_order_bill", UPDATE)) { + } else if (Session::haveRight("plugin_order_bill", READ)) { echo Dropdown::getDropdownName( "glpi_plugin_order_bills", $this->fields["plugin_order_bills_id"] @@ -489,7 +489,7 @@ public function showOrderReceptionItem($data_ref, $numref, $canedit, $reference, foreach ($all_data as $data) { $detailID = $data["IDD"]; - Session::addToNavigateListItems($this->getType(), $detailID); + Session::addToNavigateListItems($this->getType(), (int) $detailID); echo ""; $status = 1; if ($typeRef != 'SoftwareLicense') { @@ -501,7 +501,7 @@ public function showOrderReceptionItem($data_ref, $numref, $canedit, $reference, if ($order_order->canDeliver() && $status) { echo ""; - Html::showMassiveActionCheckBox(__CLASS__, $detailID); + Html::showMassiveActionCheckBox(__CLASS__, (int) $detailID); echo ""; } else { echo ""; @@ -528,13 +528,13 @@ public function showOrderReceptionItem($data_ref, $numref, $canedit, $reference, } echo ""; - echo "" . Dropdown::getDropdownName(getTableForItemType(Entity::class), $data["entities_id"]) . ""; + echo "" . Dropdown::getDropdownName(getTableForItemType(Entity::class), (int) $data["entities_id"]) . ""; echo "" . Html::convDate($data["delivery_date"]) . ""; echo "" . $data["delivery_number"] . ""; echo "" . Dropdown::getDropdownName( "glpi_plugin_order_deliverystates", - $data["plugin_order_deliverystates_id"] + (int) $data["plugin_order_deliverystates_id"] ) . ""; echo Html::hidden( "id[$detailID]", @@ -593,7 +593,7 @@ public function showOrderReceptionItem($data_ref, $numref, $canedit, $reference, 'plugin_order_orders_id' => $orders_id, 'plugin_order_references_id' => $references_id, ], - false, + '', false ) . " }"); @@ -783,7 +783,7 @@ public function updateBulkReceptionStatus($params) } else { for ($i = 0; $i < $params['number_reception']; $i++) { $this->receptionOneItem( - $DB->result($result, $i, 0), + $DB->result($result, $i, 'id'), $params['plugin_order_orders_id'], $params["delivery_date"], $params["delivery_number"], @@ -1124,8 +1124,8 @@ public static function countForOrder(PluginOrderOrder $item) public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if ( - $item->getType() == 'PluginOrderOrder' - && Session::haveRight('plugin_order_order', PluginOrderOrder::canView()) + $item instanceof PluginOrderOrder + && PluginOrderOrder::canView() && $item->getState() > PluginOrderOrderState::WAITING_FOR_APPROVAL ) { return self::createTabEntry(__("Item delivered", "order"), self::countForOrder($item)); @@ -1136,7 +1136,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { - if ($item->getType() == 'PluginOrderOrder') { + if ($item instanceof PluginOrderOrder) { $reception = new self(); $reception->showOrderReception($item->getID()); } diff --git a/inc/reference.class.php b/inc/reference.class.php index a1bfc1eec6..5a9e529125 100644 --- a/inc/reference.class.php +++ b/inc/reference.class.php @@ -263,7 +263,6 @@ public static function getSpecificValueToDisplay($field, $values, array $options case 'itemtype': $item = new $values['itemtype'](); return $item->getTypeName(); - break; } return ''; } @@ -381,7 +380,9 @@ public function defineTabs($options = []) return $ong; } - + /** + * @return array|string + */ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if (get_class($item) == __CLASS__) { @@ -393,7 +394,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { - if ($item->getType() == __CLASS__) { + if ($item instanceof self) { $item->showOrders($item); } return true; @@ -817,7 +818,7 @@ public function showOrders($ref) echo ""; echo ""; $order->getFromDB($data['plugin_order_orders_id']); - echo $order->getLink(PluginOrderOrder::canView()); + echo $order->getLink(); echo ""; echo ""; @@ -935,7 +936,7 @@ public static function showMassiveActionsSubForm(MassiveAction $ma) _sx('button', 'Post') . "\" >"; return true; } - return ""; + return false; } @@ -982,16 +983,17 @@ public static function processMassiveActionsForOneItemtype(MassiveAction $ma, Co } } return; - break; case "copy_reference": foreach ($ids as $id) { - if ($item->getFromDB($id)) { + if ( + $item instanceof self + && $item->getFromDB($id) + ) { $item->copy($id); } $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK); } return; - break; } return; } diff --git a/inc/reference_supplier.class.php b/inc/reference_supplier.class.php index 254226336f..0f93c27518 100644 --- a/inc/reference_supplier.class.php +++ b/inc/reference_supplier.class.php @@ -156,7 +156,9 @@ public function defineTabs($options = []) return $ong; } - + /** + * @return array|string + */ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if (get_class($item) == __CLASS__) { @@ -171,7 +173,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { $reference_supplier = new self(); - if ($item->getType() == 'PluginOrderReference') { + if ($item instanceof PluginOrderReference) { if ($item->can($item->getID(), UPDATE)) { $reference_supplier->showForm(0, ['plugin_order_references_id' => $item->getID()]); } @@ -208,7 +210,7 @@ public function showForm($ID, $options = []) if ($ID > 0) { $supplier = new Supplier(); $supplier->getFromDB($this->fields['suppliers_id']); - echo $supplier->getLink(Session::haveRight('supplier', READ)); + echo $supplier->getLink(); } else { $suppliers = []; $query = "SELECT `suppliers_id` @@ -300,7 +302,7 @@ public function showReferenceManufacturers($ID) echo Html::hidden('plugin_order_references_id', ['value' => $ID]); while ($data = $DB->fetchArray($result)) { - Session::addToNavigateListItems($this->getType(), $data['id']); + Session::addToNavigateListItems($this->getType(), (int) $data['id']); echo Html::hidden("item[" . $data["id"] . "]", ['value' => $ID]); echo ""; echo ""; @@ -315,12 +317,12 @@ public function showReferenceManufacturers($ID) $link = Toolbox::getItemTypeFormURL($this->getType()); echo "" - . Dropdown::getDropdownName("glpi_suppliers", $data["suppliers_id"]) . ""; + . Dropdown::getDropdownName("glpi_suppliers", (int) $data["suppliers_id"]) . ""; echo ""; echo $data["reference_code"]; echo ""; echo ""; - echo Html::formatNumber($data["price_taxfree"]); + echo Html::formatNumber((float) $data["price_taxfree"]); echo ""; echo ""; } @@ -539,11 +541,11 @@ public static function showReferencesFromSupplier($ID) while ($data = $DB->fetchArray($result)) { echo ""; echo ""; - echo Dropdown::getDropdownName("glpi_entities", $data["entities_id"]); + echo Dropdown::getDropdownName("glpi_entities", (int) $data["entities_id"]); echo ""; echo ""; - echo Dropdown::getDropdownName("glpi_manufacturers", $data["manufacturers_id"]); + echo Dropdown::getDropdownName("glpi_manufacturers", (int) $data["manufacturers_id"]); echo ""; echo ""; @@ -561,7 +563,7 @@ public static function showReferencesFromSupplier($ID) echo ""; echo ""; - echo number_format($data["price_taxfree"], 2); + echo number_format((float) $data["price_taxfree"], 2); echo ""; echo ""; } diff --git a/inc/surveysupplier.class.php b/inc/surveysupplier.class.php index 6c403a894f..2b20a5453f 100644 --- a/inc/surveysupplier.class.php +++ b/inc/surveysupplier.class.php @@ -402,7 +402,7 @@ public static function showOrderSupplierSurvey($ID) if ($DB->numrows($result) > 0) { while ($data = $DB->fetchArray($result)) { - Session::addToNavigateListItems(__CLASS__, $data['id']); + Session::addToNavigateListItems(__CLASS__, (int) $data['id']); echo Html::hidden("item[" . $data["id"] . "]", ['value' => $ID]); echo ""; echo ""; @@ -416,7 +416,7 @@ public static function showOrderSupplierSurvey($ID) echo ""; $link = Toolbox::getItemTypeFormURL(__CLASS__); echo "" - . Dropdown::getDropdownName("glpi_suppliers", $data["suppliers_id"]) . ""; + . Dropdown::getDropdownName("glpi_suppliers", (int) $data["suppliers_id"]) . ""; echo ""; $total = $survey->getTotalNotation($ID); echo $total . " / 5"; @@ -553,7 +553,6 @@ public static function uninstall() $DB->query("DROP TABLE IF EXISTS `" . self::getTable() . "`") or die($DB->error()); } - public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if ($item instanceof PluginOrderOrder) { @@ -562,10 +561,10 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) $config->canUseSupplierSatisfaction() && $item->getState() == PluginOrderOrderState::DELIVERED ) { - return [1 => __("Supplier quality", "order")]; + return __("Supplier quality", "order"); } } - return []; + return ''; } @@ -578,7 +577,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ !$survey->checkIfSupplierSurveyExists($item->getID()) && $item->can($item->getID(), UPDATE) ) { - $survey->showForm("", ['plugin_order_orders_id' => $item->getID()]); + $survey->showForm(-1, ['plugin_order_orders_id' => $item->getID()]); } } diff --git a/phpstan.neon b/phpstan.neon index 139d323b4a..19bbd107b1 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,7 +1,7 @@ parameters: parallel: maximumNumberOfProcesses: 2 - level: 1 + level: 5 bootstrapFiles: - ../../inc/based_config.php paths: @@ -17,6 +17,7 @@ parameters: - ../../stubs/glpi_constants.php ignoreErrors: - '#Call to deprecated method query\(\) of class DBmysql:#' + - '#Path in include_once\(\) ".*?/files/_plugins/order/generate/custom\.php" is not a file or it does not exist\.#' excludePaths: - 'inc/referenceinjection.class.php' - 'inc/orderinjection.class.php'