From 5e6b08fd7776c7a0f11433b435350140209aa4a2 Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Fri, 3 Nov 2023 08:18:06 +0100 Subject: [PATCH 1/8] phpstan lvl 1 --- composer.json | 1 + composer.lock | 66 +++++++++++++++++++++++++++++- front/application.form.php | 5 ++- inc/mailcollectorfeature.class.php | 7 ++-- phpstan.neon | 17 ++++++++ 5 files changed, 90 insertions(+), 6 deletions(-) create mode 100644 phpstan.neon diff --git a/composer.json b/composer.json index 106dcbb..dff97e7 100644 --- a/composer.json +++ b/composer.json @@ -5,6 +5,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" }, "provide": { diff --git a/composer.lock b/composer.lock index 96887a4..0bd1ebd 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": "c29a3e8f6bed84ccf16d5162da0b9e05", + "content-hash": "e06cd13915ee2c8cc1ae2b28654f96c0", "packages": [], "packages-dev": [ { @@ -116,6 +116,68 @@ }, "time": "2022-02-21T12:50:22+00:00" }, + { + "name": "phpstan/phpstan", + "version": "1.10.40", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "93c84b5bf7669920d823631e39904d69b9c7dc5d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/93c84b5bf7669920d823631e39904d69b9c7dc5d", + "reference": "93c84b5bf7669920d823631e39904d69b9c7dc5d", + "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-30T14:48:31+00:00" + }, { "name": "psr/container", "version": "1.1.2", @@ -1132,5 +1194,5 @@ "platform-overrides": { "php": "7.4.0" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/front/application.form.php b/front/application.form.php index a843f8b..27cc493 100644 --- a/front/application.form.php +++ b/front/application.form.php @@ -30,6 +30,9 @@ include('../../../inc/includes.php'); +/** @var array */ +global $_UPOST; + $dropdown = new PluginOauthimapApplication(); if (isset($_POST['id']) && isset($_POST['request_authorization'])) { @@ -38,7 +41,7 @@ } else { Html::requireJs('clipboard'); - if (array_key_exists('client_secret', $_POST)) { + if (array_key_exists('client_secret', $_POST) && array_key_exists('client_secret', $_UPOST)) { // Client secret must not be altered. $_POST['client_secret'] = $_UPOST['client_secret']; } diff --git a/inc/mailcollectorfeature.class.php b/inc/mailcollectorfeature.class.php index ee84790..6291ea5 100644 --- a/inc/mailcollectorfeature.class.php +++ b/inc/mailcollectorfeature.class.php @@ -68,7 +68,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ { switch ($item->getType()) { case PluginOauthimapApplication::class: - MailCollectorFeature::showMailCollectorsForApplication($item, $tabnum); + MailCollectorFeature::showMailCollectorsForApplication($item); break; } @@ -308,10 +308,11 @@ public static function updateMailCollectorOnAuthorizationCallback( 'login' => $authorization->fields['email'], ] ); + Html::redirect($mailcollector->getLinkURL()); } } - Html::redirect($mailcollector->getLinkURL()); + Html::back(); } /** @@ -412,7 +413,7 @@ private static function deactivateMailCollectors(string $protocol_type, ?string * @param string $login * @param bool $only_active * - * @return void + * @return array */ private static function getAssociatedMailCollectors( string $protocol_type, diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..d6186dc --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,17 @@ +parameters: + parallel: + maximumNumberOfProcesses: 2 + level: 1 + bootstrapFiles: + - ../../inc/based_config.php + - setup.php + paths: + - inc + - front + - ajax + - hook.php + scanDirectories: + - ../../inc + - ../../src + stubFiles: + - ../../stubs/glpi_constants.php From 222e1dd52e7fefdd359f4af7da954aa96752ded6 Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Fri, 3 Nov 2023 08:27:19 +0100 Subject: [PATCH 2/8] Run phpstan checks, try improve CI matrix --- .github/workflows/continuous-integration.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index c506ff9..2065fa3 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -19,6 +19,9 @@ jobs: matrix: include: - {php-version: "7.4"} + - {php-version: "8.1"} + - {php-version: "8.2"} + - {php-version: "8.3-rc"} steps: - name: "Checkout" uses: "actions/checkout@v4" @@ -51,13 +54,15 @@ jobs: vendor/bin/licence-headers-check --ansi --no-interaction tests: - name: "Test on GLPI ${{ matrix.glpi-version }}" + name: "Test on GLPI ${{ matrix.glpi-version }} with PHP ${{ matrix.php-version }}" runs-on: "ubuntu-latest" strategy: fail-fast: false matrix: include: - {glpi-version: "10.0", php-version: "7.4", db-image: "mysql:8.0"} + - {glpi-version: "10.0", php-version: "8.2", db-image: "mysql:8.0"} + - {glpi-version: "main", php-version: "8.2", db-image: "mysql:8.0"} services: app: image: "ghcr.io/glpi-project/githubactions-php:${{ matrix.php-version }}" @@ -95,3 +100,5 @@ jobs: docker exec ${{ job.services.app.id }} bin/console glpi:database:install --ansi --no-interaction --db-name=glpi --db-host=db --db-user=root --strict-configuration docker exec ${{ job.services.app.id }} bin/console glpi:plugin:install --ansi --no-interaction --username=glpi oauthimap docker exec ${{ job.services.app.id }} bin/console glpi:plugin:activate --ansi --no-interaction oauthimap + - name: PHPStan checks + run: docker exec ${{ job.services.app.id }} cd plugins/oauthimap && php vendor/bin/phpstan analyze --ansi --memory-limit=1G --no-interaction --no-progress From bd5c2ea077359b5750813feca201652d3be226fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Anne?= Date: Fri, 3 Nov 2023 08:46:54 +0100 Subject: [PATCH 3/8] Update .github/workflows/continuous-integration.yml --- .github/workflows/continuous-integration.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 2065fa3..258edff 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -100,5 +100,5 @@ jobs: docker exec ${{ job.services.app.id }} bin/console glpi:database:install --ansi --no-interaction --db-name=glpi --db-host=db --db-user=root --strict-configuration docker exec ${{ job.services.app.id }} bin/console glpi:plugin:install --ansi --no-interaction --username=glpi oauthimap docker exec ${{ job.services.app.id }} bin/console glpi:plugin:activate --ansi --no-interaction oauthimap - - name: PHPStan checks - run: docker exec ${{ job.services.app.id }} cd plugins/oauthimap && php vendor/bin/phpstan analyze --ansi --memory-limit=1G --no-interaction --no-progress + - name: "PHPStan checks" + run: docker exec ${{ job.services.app.id }} bash -c "cd plugins/oauthimap && php vendor/bin/phpstan analyze --ansi --memory-limit=1G --no-interaction --no-progress" From 6861d766584f8ebb3d4639e2d16f6de55b6195a4 Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Fri, 3 Nov 2023 09:04:43 +0100 Subject: [PATCH 4/8] Update .github/workflows/continuous-integration.yml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cédric Anne --- .github/workflows/continuous-integration.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 258edff..0b17028 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -62,7 +62,6 @@ jobs: include: - {glpi-version: "10.0", php-version: "7.4", db-image: "mysql:8.0"} - {glpi-version: "10.0", php-version: "8.2", db-image: "mysql:8.0"} - - {glpi-version: "main", php-version: "8.2", db-image: "mysql:8.0"} services: app: image: "ghcr.io/glpi-project/githubactions-php:${{ matrix.php-version }}" From 60854a54998de7c37aea830304f560161c2d3f77 Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Fri, 3 Nov 2023 09:04:52 +0100 Subject: [PATCH 5/8] Update phpstan.neon MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cédric Anne --- phpstan.neon | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpstan.neon b/phpstan.neon index d6186dc..3383ff8 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 0fd143ccb71c8a091af501f81a2566708f4a0f08 Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Fri, 3 Nov 2023 09:08:04 +0100 Subject: [PATCH 6/8] Fix redirection --- inc/mailcollectorfeature.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/inc/mailcollectorfeature.class.php b/inc/mailcollectorfeature.class.php index 6291ea5..7542697 100644 --- a/inc/mailcollectorfeature.class.php +++ b/inc/mailcollectorfeature.class.php @@ -58,7 +58,6 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) } return CommonGLPI::createTabEntry(MailCollector::getTypeName(Session::getPluralNumber()), $count); - break; } return ''; @@ -297,9 +296,10 @@ public static function updateMailCollectorOnAuthorizationCallback( PluginOauthimapAuthorization $authorization, array $params = [] ): void { + $mailcollector = new MailCollector(); + $redirect = $mailcollector->getSearchURL(); if ($success) { // Store authorized email into MailCollector - $mailcollector = new MailCollector(); $mailcollector_id = $params[$mailcollector->getForeignKeyField()] ?? null; if ($mailcollector_id !== null && $mailcollector->getFromDB($mailcollector_id)) { $mailcollector->update( @@ -308,11 +308,11 @@ public static function updateMailCollectorOnAuthorizationCallback( 'login' => $authorization->fields['email'], ] ); - Html::redirect($mailcollector->getLinkURL()); + $redirect = $mailcollector->getLinkURL(); } } - Html::back(); + Html::redirect($redirect); } /** From 85fda27a71790c57d83ee877c296ffdff0a318db Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Fri, 3 Nov 2023 09:09:09 +0100 Subject: [PATCH 7/8] phpstan extensions --- composer.json | 7 +++- composer.lock | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 99 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index dff97e7..2b998c8 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,9 @@ "require-dev": { "glpi-project/tools": "^0.6", "php-parallel-lint/php-parallel-lint": "^1.3", + "phpstan/extension-installer": "^1.3", "phpstan/phpstan": "^1.10", + "phpstan/phpstan-deprecation-rules": "^1.1", "squizlabs/php_codesniffer": "^3.6" }, "provide": { @@ -16,6 +18,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 0bd1ebd..077c084 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": "e06cd13915ee2c8cc1ae2b28654f96c0", + "content-hash": "b475f12a9971c0d1af29215fee9b291f", "packages": [], "packages-dev": [ { @@ -116,6 +116,50 @@ }, "time": "2022-02-21T12:50:22+00:00" }, + { + "name": "phpstan/extension-installer", + "version": "1.3.1", + "source": { + "type": "git", + "url": "https://github.com/phpstan/extension-installer.git", + "reference": "f45734bfb9984c6c56c4486b71230355f066a58a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/extension-installer/zipball/f45734bfb9984c6c56c4486b71230355f066a58a", + "reference": "f45734bfb9984c6c56c4486b71230355f066a58a", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^2.0", + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.9.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", + "support": { + "issues": "https://github.com/phpstan/extension-installer/issues", + "source": "https://github.com/phpstan/extension-installer/tree/1.3.1" + }, + "time": "2023-05-24T08:59:17+00:00" + }, { "name": "phpstan/phpstan", "version": "1.10.40", @@ -178,6 +222,54 @@ ], "time": "2023-10-30T14:48:31+00:00" }, + { + "name": "phpstan/phpstan-deprecation-rules", + "version": "1.1.4", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan-deprecation-rules.git", + "reference": "089d8a8258ed0aeefdc7b68b6c3d25572ebfdbaa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/089d8a8258ed0aeefdc7b68b6c3d25572ebfdbaa", + "reference": "089d8a8258ed0aeefdc7b68b6c3d25572ebfdbaa", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.10.3" + }, + "require-dev": { + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/phpstan-php-parser": "^1.1", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/phpunit": "^9.5" + }, + "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/1.1.4" + }, + "time": "2023-08-05T09:02:04+00:00" + }, { "name": "psr/container", "version": "1.1.2", From 1f49bcfaf4c67d522f266738063ebb81afb10e89 Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Fri, 3 Nov 2023 09:10:06 +0100 Subject: [PATCH 8/8] Update tools version --- composer.json | 2 +- composer.lock | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 2b998c8..e325f91 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "php": ">=7.4" }, "require-dev": { - "glpi-project/tools": "^0.6", + "glpi-project/tools": "^0.7.1", "php-parallel-lint/php-parallel-lint": "^1.3", "phpstan/extension-installer": "^1.3", "phpstan/phpstan": "^1.10", diff --git a/composer.lock b/composer.lock index 077c084..42470d2 100644 --- a/composer.lock +++ b/composer.lock @@ -4,27 +4,31 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b475f12a9971c0d1af29215fee9b291f", + "content-hash": "e0c0d417353c37eedd4b88ee3961debf", "packages": [], "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", @@ -33,7 +37,7 @@ "type": "library", "autoload": { "psr-4": { - "Glpi\\": "src/" + "GlpiProject\\Tools\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -57,7 +61,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",