diff --git a/composer.json b/composer.json index ccfcea2..8524552 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,9 @@ "require-dev": { "glpi-project/tools": "^0.7.4", "php-parallel-lint/php-parallel-lint": "^1.4", + "phpstan/extension-installer": "^1.4", "phpstan/phpstan": "^2.1", + "phpstan/phpstan-deprecation-rules": "^2.0", "squizlabs/php_codesniffer": "^3.11" }, "config": { @@ -13,6 +15,9 @@ "platform": { "php": "7.4.0" }, - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "phpstan/extension-installer": true + } } } diff --git a/composer.lock b/composer.lock index 4568db8..bbfb515 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": "f238b81b4d6e04cada13e3ce8af695da", + "content-hash": "b8695e4c5c62263ae2dea24ab8f24248", "packages": [], "packages-dev": [ { @@ -124,18 +124,66 @@ }, "time": "2024-03-27T12:14:49+00:00" }, + { + "name": "phpstan/extension-installer", + "version": "1.4.3", + "source": { + "type": "git", + "url": "https://github.com/phpstan/extension-installer.git", + "reference": "85e90b3942d06b2326fba0403ec24fe912372936" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/extension-installer/zipball/85e90b3942d06b2326fba0403ec24fe912372936", + "reference": "85e90b3942d06b2326fba0403ec24fe912372936", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^2.0", + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.9.0 || ^2.0" + }, + "require-dev": { + "composer/composer": "^2.0", + "php-parallel-lint/php-parallel-lint": "^1.2.0", + "phpstan/phpstan-strict-rules": "^0.11 || ^0.12 || ^1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "PHPStan\\ExtensionInstaller\\Plugin" + }, + "autoload": { + "psr-4": { + "PHPStan\\ExtensionInstaller\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Composer plugin for automatic installation of PHPStan extensions", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "issues": "https://github.com/phpstan/extension-installer/issues", + "source": "https://github.com/phpstan/extension-installer/tree/1.4.3" + }, + "time": "2024-09-04T20:21:43+00:00" + }, { "name": "phpstan/phpstan", - "version": "2.1.0", + "version": "2.1.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "2392d360fdf54ea253aa6c68cad1d4ba2e54e927" + "reference": "cd6e973e04b4c2b94c86e8612b5a65f0da0e08e7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/2392d360fdf54ea253aa6c68cad1d4ba2e54e927", - "reference": "2392d360fdf54ea253aa6c68cad1d4ba2e54e927", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/cd6e973e04b4c2b94c86e8612b5a65f0da0e08e7", + "reference": "cd6e973e04b4c2b94c86e8612b5a65f0da0e08e7", "shasum": "" }, "require": { @@ -180,7 +228,54 @@ "type": "github" } ], - "time": "2024-12-31T07:30:03+00:00" + "time": "2025-01-05T16:43:48+00:00" + }, + { + "name": "phpstan/phpstan-deprecation-rules", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan-deprecation-rules.git", + "reference": "1cc1259cb91ee4cfbb5c39bca9f635f067c910b4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/1cc1259cb91ee4cfbb5c39bca9f635f067c910b4", + "reference": "1cc1259cb91ee4cfbb5c39bca9f635f067c910b4", + "shasum": "" + }, + "require": { + "php": "^7.4 || ^8.0", + "phpstan/phpstan": "^2.0" + }, + "require-dev": { + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/phpstan-phpunit": "^2.0", + "phpunit/phpunit": "^9.6" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "rules.neon" + ] + } + }, + "autoload": { + "psr-4": { + "PHPStan\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan rules for detecting usage of deprecated classes, methods, properties, constants and traits.", + "support": { + "issues": "https://github.com/phpstan/phpstan-deprecation-rules/issues", + "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/2.0.1" + }, + "time": "2024-11-28T21:56:36+00:00" }, { "name": "psr/container", @@ -312,16 +407,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": { @@ -391,7 +486,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v5.4.44" + "source": "https://github.com/symfony/console/tree/v5.4.47" }, "funding": [ { @@ -407,20 +502,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": { @@ -428,12 +523,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": { @@ -458,7 +553,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": [ { @@ -474,7 +569,7 @@ "type": "tidelift" } ], - "time": "2023-01-24T14:02:46+00:00" + "time": "2024-09-25T14:11:13+00:00" }, { "name": "symfony/polyfill-ctype", @@ -502,8 +597,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -578,8 +673,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -656,8 +751,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -740,8 +835,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -814,8 +909,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -890,8 +985,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -970,8 +1065,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -1028,16 +1123,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": { @@ -1053,12 +1148,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": { @@ -1091,7 +1186,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": [ { @@ -1107,20 +1202,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": { @@ -1177,7 +1272,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v5.4.44" + "source": "https://github.com/symfony/string/tree/v5.4.47" }, "funding": [ { @@ -1193,20 +1288,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": { @@ -1261,7 +1356,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": [ { @@ -1273,7 +1368,7 @@ "type": "tidelift" } ], - "time": "2024-11-06T18:50:16+00:00" + "time": "2024-11-07T12:34:41+00:00" } ], "aliases": [], diff --git a/front/ticket.php b/front/ticket.php index 91b4a74..8af29da 100644 --- a/front/ticket.php +++ b/front/ticket.php @@ -34,7 +34,7 @@ Html::popHeader(__('Setup'), $_SERVER['PHP_SELF'], true); if (!isset($_GET["plugcreditentity"])) { - throw new \RuntimeException('Invalid params provided!', 'credit'); + throw new \RuntimeException('Invalid params provided!'); } else { $_GET['plugcreditentity'] = (int) $_GET['plugcreditentity']; } diff --git a/inc/entity.class.php b/inc/entity.class.php index c6fdf03..2d401b8 100644 --- a/inc/entity.class.php +++ b/inc/entity.class.php @@ -40,7 +40,11 @@ public static function getTypeName($nb = 0) public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { - $nb = self::countForItem($item); + if ($item instanceof CommonDBTM) { + $nb = self::countForItem($item); + } else { + $nb = 0; + } switch ($item->getType()) { case 'Entity': if ($_SESSION['glpishow_count_on_tabs']) { @@ -50,15 +54,12 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) default: return self::getTypeName($nb); } - return ''; } public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { - switch ($item->getType()) { - case 'Entity': - self::showForItemtype($item); - break; + if ($item instanceof Entity) { + self::showForItemtype($item); } return true; } @@ -90,7 +91,7 @@ public function prepareInputForAdd($input) public function prepareInputForUpdate($input) { - if (isset($input['name']) && strlen($input['name']) == '') { + if (isset($input['name']) && strlen($input['name']) === 0) { Session::addMessageAfterRedirect(__('Credit voucher name is mandatory.', 'credit')); return false; } @@ -652,7 +653,7 @@ public static function install(Migration $migration) KEY `end_date` (`end_date`) ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC; SQL; - $DB->query($query) or die($DB->error()); + $DB->doQuery($query); } else { // 1.5.0 $migration->addField($table, 'overconsumption_allowed', 'bool', ['update' => "1"]); diff --git a/inc/entityconfig.class.php b/inc/entityconfig.class.php index 1e4c4e7..90cfa97 100644 --- a/inc/entityconfig.class.php +++ b/inc/entityconfig.class.php @@ -199,7 +199,7 @@ public static function install(Migration $migration) KEY `plugin_credit_entities_id_solutions` (`plugin_credit_entities_id_solutions`) ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC; SQL; - $DB->query($query) or die($DB->error()); + $DB->doQuery($query); } // During 1.10.0 dev phase, entity config were stored in GLPI config table diff --git a/inc/ticket.class.php b/inc/ticket.class.php index 03124f3..d6ab675 100644 --- a/inc/ticket.class.php +++ b/inc/ticket.class.php @@ -40,26 +40,26 @@ public static function getTypeName($nb = 0) public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { - $nb = self::countForItem($item); - switch ($item->getType()) { - case 'Ticket': - if ($_SESSION['glpishow_count_on_tabs']) { - return self::createTabEntry(self::getTypeName($nb), $nb); - } else { - return self::getTypeName($nb); - } - default: + if ($item instanceof CommonDBTM) { + $nb = self::countForItem($item); + } else { + $nb = 0; + } + if ($item instanceof Ticket) { + if ($_SESSION['glpishow_count_on_tabs']) { + return self::createTabEntry(self::getTypeName($nb), $nb); + } else { return self::getTypeName($nb); + } + } else { + return self::getTypeName($nb); } - return ''; } public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { - switch ($item->getType()) { - case 'Ticket': - self::showForTicket($item); - break; + if ($item instanceof Ticket) { + self::showForTicket($item); } return true; } @@ -149,10 +149,9 @@ public static function getConsumedForCreditEntity($ID) ], ]; - if ($result = $DB->request($request)) { - if ($row = $result->current()) { - $tot = $row['sum']; - } + $result = $DB->request($request); + if ($row = $result->current()) { + $tot = $row['sum']; } return $tot; @@ -403,7 +402,7 @@ public static function displayVoucherInTicketProcessingForm($params) $consume = $entity_config->fields['consume_voucher_for_solutions'] ?? 0; } else if ($item instanceof TicketTask) { $consume = $entity_config->fields['consume_voucher_for_tasks'] ?? 0; - } else if ($item instanceof ITILFollowup) { + } else { $consume = $entity_config->fields['consume_voucher_for_followups'] ?? 0; } @@ -562,7 +561,7 @@ public static function displayConsumed($ID) */ public static function consumeVoucher(CommonDBTM $item) { - if (!is_array($item->input) || !count($item->input)) { + if (!count($item->input)) { return; } @@ -572,8 +571,8 @@ public static function consumeVoucher(CommonDBTM $item) $ticketId = $item->fields['tickets_id']; } else if ( array_key_exists('itemtype', $item->fields) - && array_key_exists('items_id', $item->fields) - && 'Ticket' == $item->fields['itemtype'] + && array_key_exists('items_id', $item->fields) + && 'Ticket' == $item->fields['itemtype'] ) { // Ticket ID can be found in `items_id` field for ITILFollowup and ITILSolution. $ticketId = $item->fields['items_id']; @@ -725,7 +724,7 @@ public static function install(Migration $migration) KEY `users_id` (`users_id`) ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC; SQL; - $DB->query($query) or die($DB->error()); + $DB->doQuery($query); } else { // Fix #1 in 1.0.1 : change tinyint to int for tickets_id $migration->changeField($table, 'tickets_id', 'tickets_id', "int {$default_key_sign} NOT NULL DEFAULT 0"); diff --git a/inc/ticketconfig.class.php b/inc/ticketconfig.class.php index dd8ee5f..3bcd550 100644 --- a/inc/ticketconfig.class.php +++ b/inc/ticketconfig.class.php @@ -314,7 +314,7 @@ public static function install(Migration $migration) KEY `plugin_credit_entities_id_solutions` (`plugin_credit_entities_id_solutions`) ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC; SQL; - $DB->query($query) or die($DB->error()); + $DB->doQuery($query); } // During 1.10.0 dev phase, fields were named differently and had no keys diff --git a/inc/type.class.php b/inc/type.class.php index 7ba6011..4411dc0 100644 --- a/inc/type.class.php +++ b/inc/type.class.php @@ -80,7 +80,7 @@ public static function install(Migration $migration) KEY `date_creation` (`date_creation`) ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC; SQL; - $DB->query($query) or die($DB->error()); + $DB->doQuery($query); } return true; diff --git a/phpstan.neon b/phpstan.neon index bd46d21..064dfec 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,7 +1,7 @@ parameters: parallel: maximumNumberOfProcesses: 2 - level: 2 + level: 5 bootstrapFiles: - ../../inc/based_config.php paths: