From a1e4395b9e7fc8c24343d99effd9511d9ae491af Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Mon, 30 Oct 2023 09:22:47 +0100 Subject: [PATCH] phpstan lvl 0 --- .github/workflows/continuous-integration.yml | 28 ++++++--- 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 +++++ 12 files changed, 119 insertions(+), 12 deletions(-) create mode 100644 phpstan.neon diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index e172cb3c..2e9b9825 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -19,6 +19,10 @@ jobs: matrix: include: - {php-version: "7.4"} + - {php-version: "8.0"} + - {php-version: "8.1"} + - {php-version: "8.2"} + - {php-version: "8.3-rc"} steps: - name: "Checkout" uses: "actions/checkout@v4" @@ -28,15 +32,6 @@ jobs: php-version: "${{ matrix.php-version }}" coverage: "none" tools: "composer, cs2pr" - - name: "Get Composer cache directory" - id: "composer-cache" - run: | - echo "::set-output name=dir::$(composer config cache-files-dir)" - - name: "Restore dependencies cache" - uses: "actions/cache@v3" - with: - path: "${{ steps.composer-cache.outputs.dir }}" - key: "${{ github.job }}-${{ matrix.php-version }}-dependencies-${{ hashFiles('**/composer.lock') }}" - name: "Install Composer dependencies" run: | composer install --ansi --no-interaction --no-progress --prefer-dist @@ -49,3 +44,18 @@ jobs: - name: "Check for missing/outdated headers" run: | vendor/bin/licence-headers-check --ansi --no-interaction + - name: Checkout GLPI + uses: actions/checkout@v4 + with: + repository: glpi-project/glpi + path: glpi + fetch-depth: 1 + ref: 10.0/bugfixes + - name: Install xmllint + run: sudo apt-get install -y gettext + - name: "Build dependencies / translations" + run: cd glpi && php bin/console dependencies install && php bin/console locales:compile + - name: Copy plugin + run: rsync -avr --exclude='glpi' ./* glpi/plugins/fields/ + - name: PHPStan checks + run: cd glpi/plugins/fields && php vendor/bin/phpstan analyze --ansi --memory-limit=1G --no-interaction --no-progress 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