From b2362f2079fd8666bb9b4194ecc1feb084528ef3 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Tue, 26 Mar 2024 11:36:54 +0100 Subject: [PATCH 1/4] phpstan: Streamline vendor file location with local dev-env phpstan is not run with an action anymore, as the action runs it its own docker container and hence has no access to files outside the repository root. A side-effect of this is, that phpstan now **really** runs with the php version set up by the matrix. --- .github/workflows/php.yml | 14 +++++++------- phpstan.neon | 4 +++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 37078bb9..5e6d9544 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -32,12 +32,12 @@ jobs: - name: Setup dependencies run: | - composer require -n --no-progress overtrue/phplint - git clone --depth 1 https://github.com/Icinga/icingaweb2.git vendor/icingaweb2 - git clone --depth 1 https://github.com/Icinga/icingadb-web.git vendor/icingadb-web - git clone --depth 1 https://github.com/Icinga/icingaweb2-module-director.git vendor/icingaweb2-module-director - git clone --depth 1 -b snapshot/nightly https://github.com/Icinga/icinga-php-library.git vendor/icinga-php-library - git clone --depth 1 -b snapshot/nightly https://github.com/Icinga/icinga-php-thirdparty.git vendor/icinga-php-thirdparty + composer require -n --no-progress overtrue/phplint phpstan/phpstan + sudo git clone --depth 1 https://github.com/Icinga/icingaweb2.git /icingaweb2 + sudo git clone --depth 1 -b snapshot/nightly https://github.com/Icinga/icinga-php-library.git /usr/share/icinga-php/ipl + sudo git clone --depth 1 -b snapshot/nightly https://github.com/Icinga/icinga-php-thirdparty.git /usr/share/icinga-php/vendor + sudo git clone --depth 1 https://github.com/Icinga/icingadb-web.git /usr/share/icingaweb2-modules/icingadb-web + sudo git clone --depth 1 https://github.com/Icinga/icingaweb2-module-director.git /usr/share/icingaweb2-modules/icingaweb2-module-director - name: PHP Lint if: ${{ ! cancelled() }} @@ -49,7 +49,7 @@ jobs: - name: PHPStan if: ${{ ! cancelled() }} - uses: php-actions/phpstan@v3 + run: ./vendor/bin/phpstan analyse test: name: Unit tests with php ${{ matrix.php }} on ${{ matrix.os }} diff --git a/phpstan.neon b/phpstan.neon index 8c09b519..cd7850d9 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -13,7 +13,9 @@ parameters: - library scanDirectories: - - vendor + - /icingaweb2 + - /usr/share/icinga-php + - /usr/share/icingaweb2-modules excludePaths: - library/Businessprocess/Test From 004044a22ae18b700035c5daec98df642f62f586 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Tue, 26 Mar 2024 11:43:24 +0100 Subject: [PATCH 2/4] GithubActions: Add checks for php 8.3 --- .github/workflows/php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 5e6d9544..4eea0dec 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -61,7 +61,7 @@ jobs: strategy: fail-fast: false matrix: - php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] + php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] os: ['ubuntu-latest'] steps: From 1f8d74a61283e69cce3fc5518a13d2c35c65d4a8 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Tue, 26 Mar 2024 12:02:12 +0100 Subject: [PATCH 3/4] Sort: Fix var type error --- library/Businessprocess/Common/Sort.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/Businessprocess/Common/Sort.php b/library/Businessprocess/Common/Sort.php index 4728af3e..01bb569f 100644 --- a/library/Businessprocess/Common/Sort.php +++ b/library/Businessprocess/Common/Sort.php @@ -41,7 +41,9 @@ public function setSort(?string $sort): self return $this; } - list($sortBy, $direction) = Str::symmetricSplit($sort, ' ', 2, 'asc'); + /** @var array $res */ + $res = Str::symmetricSplit($sort, ' ', 2, 'asc'); + [$sortBy, $direction] = $res; switch ($sortBy) { case 'manual': From 087b1b6c8ef30600d218c254ec6576abca60c894 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Tue, 26 Mar 2024 11:43:52 +0100 Subject: [PATCH 4/4] phpstan: Separate baseline by php version --- phpstan-baseline-7x.neon | 81 ++++++++++++ phpstan-baseline-8x.neon | 81 ++++++++++++ phpstan-baseline-by-php-version.php | 12 ++ ...ine.neon => phpstan-baseline-standard.neon | 125 ++---------------- phpstan.neon | 3 +- 5 files changed, 186 insertions(+), 116 deletions(-) create mode 100644 phpstan-baseline-7x.neon create mode 100644 phpstan-baseline-8x.neon create mode 100644 phpstan-baseline-by-php-version.php rename phpstan-baseline.neon => phpstan-baseline-standard.neon (97%) diff --git a/phpstan-baseline-7x.neon b/phpstan-baseline-7x.neon new file mode 100644 index 00000000..0da77d7d --- /dev/null +++ b/phpstan-baseline-7x.neon @@ -0,0 +1,81 @@ +parameters: + ignoreErrors: + - + message: "#^Parameter \\#1 \\$fp of function fpassthru expects resource, resource\\|false given\\.$#" + count: 1 + path: application/controllers/ProcessController.php + + - + message: "#^Parameter \\#1 \\$fp of function fputcsv expects resource, resource\\|false given\\.$#" + count: 2 + path: application/controllers/ProcessController.php + + - + message: "#^Parameter \\#1 \\$fp of function rewind expects resource, resource\\|false given\\.$#" + count: 1 + path: application/controllers/ProcessController.php + + - + message: "#^Parameter \\#1 \\$str of function strtolower expects string, mixed given\\.$#" + count: 1 + path: application/controllers/ProcessController.php + + - + message: "#^Parameter \\#2 \\$args of function vsprintf expects array\\, array\\ given\\.$#" + count: 2 + path: library/Businessprocess/BpConfig.php + + - + message: "#^Parameter \\#2 \\$search of function array_key_exists expects array, array\\\\|null given\\.$#" + count: 1 + path: library/Businessprocess/BpNode.php + + - + message: "#^Parameter \\#1 \\$str of function ucfirst expects string, mixed given\\.$#" + count: 1 + path: library/Businessprocess/Modification/NodeAction.php + + - + message: "#^Parameter \\#2 \\$search of function array_key_exists expects array, mixed given\\.$#" + count: 1 + path: library/Businessprocess/Monitoring/Backend/Ido/Query/HostStatusQuery.php + + - + message: "#^Parameter \\#2 \\$search of function array_key_exists expects array, mixed given\\.$#" + count: 1 + path: library/Businessprocess/Monitoring/Backend/Ido/Query/ServiceStatusQuery.php + + - + message: "#^Parameter \\#2 \\.\\.\\.\\$args of function array_merge expects array, mixed given\\.$#" + count: 2 + path: library/Businessprocess/State/IcingaDbState.php + + - + message: "#^Parameter \\#1 \\$fp of function fclose expects resource, resource\\|false given\\.$#" + count: 1 + path: library/Businessprocess/Storage/LegacyConfigParser.php + + - + message: "#^Parameter \\#1 \\$fp of function fgets expects resource, resource\\|false given\\.$#" + count: 1 + path: library/Businessprocess/Storage/LegacyConfigParser.php + + - + message: "#^Parameter \\#1 \\$stack of function array_shift expects array, array\\\\|false given\\.$#" + count: 1 + path: library/Businessprocess/Storage/LegacyConfigParser.php + + - + message: "#^Parameter \\#2 \\$args of function vsprintf expects array\\, array\\ given\\.$#" + count: 1 + path: library/Businessprocess/Web/Controller.php + + - + message: "#^Parameter \\#1 \\$stack of function array_pop expects array, array\\\\|false given\\.$#" + count: 1 + path: library/Businessprocess/Web/Form/FormLoader.php + + - + message: "#^Parameter \\#1 \\$stack of function array_pop expects array, array\\\\|false given\\.$#" + count: 1 + path: library/Businessprocess/Web/Form/QuickForm.php diff --git a/phpstan-baseline-8x.neon b/phpstan-baseline-8x.neon new file mode 100644 index 00000000..bb0184b2 --- /dev/null +++ b/phpstan-baseline-8x.neon @@ -0,0 +1,81 @@ +parameters: + ignoreErrors: + - + message: "#^Parameter \\#1 \\$stream of function fpassthru expects resource, resource\\|false given\\.$#" + count: 1 + path: application/controllers/ProcessController.php + + - + message: "#^Parameter \\#1 \\$stream of function fputcsv expects resource, resource\\|false given\\.$#" + count: 2 + path: application/controllers/ProcessController.php + + - + message: "#^Parameter \\#1 \\$stream of function rewind expects resource, resource\\|false given\\.$#" + count: 1 + path: application/controllers/ProcessController.php + + - + message: "#^Parameter \\#1 \\$string of function strtolower expects string, mixed given\\.$#" + count: 1 + path: application/controllers/ProcessController.php + + - + message: "#^Parameter \\#2 \\$values of function vsprintf expects array\\, array\\ given\\.$#" + count: 2 + path: library/Businessprocess/BpConfig.php + + - + message: "#^Parameter \\#2 \\$array of function array_key_exists expects array, array\\\\|null given\\.$#" + count: 1 + path: library/Businessprocess/BpNode.php + + - + message: "#^Parameter \\#1 \\$string of function ucfirst expects string, mixed given\\.$#" + count: 1 + path: library/Businessprocess/Modification/NodeAction.php + + - + message: "#^Parameter \\#2 \\$array of function array_key_exists expects array, mixed given\\.$#" + count: 1 + path: library/Businessprocess/Monitoring/Backend/Ido/Query/HostStatusQuery.php + + - + message: "#^Parameter \\#2 \\$array of function array_key_exists expects array, mixed given\\.$#" + count: 1 + path: library/Businessprocess/Monitoring/Backend/Ido/Query/ServiceStatusQuery.php + + - + message: "#^Parameter \\#2 \\.\\.\\.\\$arrays of function array_merge expects array, mixed given\\.$#" + count: 2 + path: library/Businessprocess/State/IcingaDbState.php + + - + message: "#^Parameter \\#1 \\$array of function array_shift expects array, array\\\\|false given\\.$#" + count: 1 + path: library/Businessprocess/Storage/LegacyConfigParser.php + + - + message: "#^Parameter \\#1 \\$stream of function fclose expects resource, resource\\|false given\\.$#" + count: 1 + path: library/Businessprocess/Storage/LegacyConfigParser.php + + - + message: "#^Parameter \\#1 \\$stream of function fgets expects resource, resource\\|false given\\.$#" + count: 1 + path: library/Businessprocess/Storage/LegacyConfigParser.php + + - + message: "#^Parameter \\#2 \\$values of function vsprintf expects array\\, array\\ given\\.$#" + count: 1 + path: library/Businessprocess/Web/Controller.php + + - + message: "#^Parameter \\#1 \\$array of function array_pop expects array, array\\\\|false given\\.$#" + count: 1 + path: library/Businessprocess/Web/Form/FormLoader.php + + - + message: "#^Parameter \\#1 \\$array of function array_pop expects array, array\\\\|false given\\.$#" + count: 1 + path: library/Businessprocess/Web/Form/QuickForm.php diff --git a/phpstan-baseline-by-php-version.php b/phpstan-baseline-by-php-version.php new file mode 100644 index 00000000..4bd791e8 --- /dev/null +++ b/phpstan-baseline-by-php-version.php @@ -0,0 +1,12 @@ += 80000) { + $includes[] = __DIR__ . '/phpstan-baseline-8x.neon'; +} else { + $includes[] = __DIR__ . '/phpstan-baseline-7x.neon'; +} + +return [ + 'includes' => $includes +]; diff --git a/phpstan-baseline.neon b/phpstan-baseline-standard.neon similarity index 97% rename from phpstan-baseline.neon rename to phpstan-baseline-standard.neon index cd648b95..fa74e35a 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline-standard.neon @@ -285,26 +285,6 @@ parameters: count: 1 path: application/controllers/ProcessController.php - - - message: "#^Parameter \\#1 \\$stream of function fpassthru expects resource, resource\\|false given\\.$#" - count: 1 - path: application/controllers/ProcessController.php - - - - message: "#^Parameter \\#1 \\$stream of function fputcsv expects resource, resource\\|false given\\.$#" - count: 2 - path: application/controllers/ProcessController.php - - - - message: "#^Parameter \\#1 \\$stream of function rewind expects resource, resource\\|false given\\.$#" - count: 1 - path: application/controllers/ProcessController.php - - - - message: "#^Parameter \\#1 \\$string of function strtolower expects string, mixed given\\.$#" - count: 1 - path: application/controllers/ProcessController.php - - message: "#^Parameter \\#1 \\(mixed\\) of echo cannot be converted to string\\.$#" count: 1 @@ -505,11 +485,6 @@ parameters: count: 1 path: application/forms/AddNodeForm.php - - - message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#" - count: 1 - path: application/forms/AddNodeForm.php - - message: "#^Cannot call method getLabel\\(\\) on Zend_Form_Element\\|null\\.$#" count: 1 @@ -1280,11 +1255,6 @@ parameters: count: 1 path: library/Businessprocess/BpConfig.php - - - message: "#^Parameter \\#2 \\$values of function vsprintf expects array\\, array\\ given\\.$#" - count: 2 - path: library/Businessprocess/BpConfig.php - - message: "#^Property Icinga\\\\Module\\\\Businessprocess\\\\BpConfig\\:\\:\\$changeCount has no type specified\\.$#" count: 1 @@ -1555,11 +1525,6 @@ parameters: count: 1 path: library/Businessprocess/BpNode.php - - - message: "#^Parameter \\#2 \\$array of function array_key_exists expects array, array\\\\|null given\\.$#" - count: 1 - path: library/Businessprocess/BpNode.php - - message: "#^Property Icinga\\\\Module\\\\Businessprocess\\\\BpNode\\:\\:\\$childNames type has no value type specified in iterable type array\\.$#" count: 1 @@ -1995,11 +1960,6 @@ parameters: count: 1 path: library/Businessprocess/Modification/NodeAction.php - - - message: "#^Parameter \\#1 \\$string of function ucfirst expects string, mixed given\\.$#" - count: 1 - path: library/Businessprocess/Modification/NodeAction.php - - message: "#^Parameter \\#2 \\$nodeName of static method Icinga\\\\Module\\\\Businessprocess\\\\Modification\\\\NodeAction\\:\\:create\\(\\) expects string, mixed given\\.$#" count: 1 @@ -2055,11 +2015,6 @@ parameters: count: 1 path: library/Businessprocess/Modification/NodeApplyManualOrderAction.php - - - message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#" - count: 1 - path: library/Businessprocess/Modification/NodeApplyManualOrderAction.php - - message: "#^Method Icinga\\\\Module\\\\Businessprocess\\\\Modification\\\\NodeCopyAction\\:\\:applyManualSorting\\(\\) has parameter \\$bpNodes with no value type specified in iterable type array\\.$#" count: 1 @@ -2080,11 +2035,6 @@ parameters: count: 1 path: library/Businessprocess/Modification/NodeCopyAction.php - - - message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#" - count: 1 - path: library/Businessprocess/Modification/NodeCopyAction.php - - message: "#^Method Icinga\\\\Module\\\\Businessprocess\\\\Modification\\\\NodeCreateAction\\:\\:getProperties\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -2235,11 +2185,6 @@ parameters: count: 1 path: library/Businessprocess/Modification/NodeMoveAction.php - - - message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#" - count: 1 - path: library/Businessprocess/Modification/NodeMoveAction.php - - message: "#^Property Icinga\\\\Module\\\\Businessprocess\\\\Modification\\\\NodeMoveAction\\:\\:\\$from \\(int\\) does not accept int\\|false\\.$#" count: 1 @@ -2350,11 +2295,6 @@ parameters: count: 1 path: library/Businessprocess/Monitoring/Backend/Ido/Query/HostStatusQuery.php - - - message: "#^Parameter \\#2 \\$array of function array_key_exists expects array, mixed given\\.$#" - count: 1 - path: library/Businessprocess/Monitoring/Backend/Ido/Query/HostStatusQuery.php - - message: "#^Parameter \\#4 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#" count: 1 @@ -2375,11 +2315,6 @@ parameters: count: 1 path: library/Businessprocess/Monitoring/Backend/Ido/Query/ServiceStatusQuery.php - - - message: "#^Parameter \\#2 \\$array of function array_key_exists expects array, mixed given\\.$#" - count: 1 - path: library/Businessprocess/Monitoring/Backend/Ido/Query/ServiceStatusQuery.php - - message: "#^Parameter \\#4 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#" count: 1 @@ -2740,21 +2675,11 @@ parameters: count: 1 path: library/Businessprocess/Node.php - - - message: "#^Parameter \\#1 \\$name of static method Icinga\\\\Module\\\\Businessprocess\\\\BpConfig\\:\\:joinNodeName\\(\\) expects string, mixed given\\.$#" - count: 1 - path: library/Businessprocess/ProvidedHook/Icingadb/HostActions.php - - message: "#^Cannot access property \\$name on mixed\\.$#" count: 1 path: library/Businessprocess/ProvidedHook/Icingadb/ServiceActions.php - - - message: "#^Parameter \\#2 \\$suffix of static method Icinga\\\\Module\\\\Businessprocess\\\\BpConfig\\:\\:joinNodeName\\(\\) expects string\\|null, mixed given\\.$#" - count: 1 - path: library/Businessprocess/ProvidedHook/Icingadb/ServiceActions.php - - message: "#^Cannot access offset 'icingacli…' on mixed\\.$#" count: 2 @@ -2915,11 +2840,6 @@ parameters: count: 1 path: library/Businessprocess/Renderer/Renderer.php - - - message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#" - count: 1 - path: library/Businessprocess/Renderer/Renderer.php - - message: "#^Property Icinga\\\\Module\\\\Businessprocess\\\\Renderer\\\\Renderer\\:\\:\\$parent \\(Icinga\\\\Module\\\\Businessprocess\\\\BpNode\\) does not accept Icinga\\\\Module\\\\Businessprocess\\\\BpNode\\|null\\.$#" count: 1 @@ -3245,11 +3165,6 @@ parameters: count: 1 path: library/Businessprocess/State/IcingaDbState.php - - - message: "#^Parameter \\#2 \\.\\.\\.\\$arrays of function array_merge expects array, mixed given\\.$#" - count: 2 - path: library/Businessprocess/State/IcingaDbState.php - - message: "#^Method Icinga\\\\Module\\\\Businessprocess\\\\State\\\\MonitoringState\\:\\:apply\\(\\) has no return type specified\\.$#" count: 1 @@ -3530,11 +3445,6 @@ parameters: count: 1 path: library/Businessprocess/Storage/LegacyConfigParser.php - - - message: "#^Parameter \\#1 \\$array of function array_shift expects array, array\\\\|false given\\.$#" - count: 1 - path: library/Businessprocess/Storage/LegacyConfigParser.php - - message: "#^Parameter \\#1 \\$haystack of function strpos expects string, string\\|null given\\.$#" count: 1 @@ -3545,16 +3455,6 @@ parameters: count: 2 path: library/Businessprocess/Storage/LegacyConfigParser.php - - - message: "#^Parameter \\#1 \\$stream of function fclose expects resource, resource\\|false given\\.$#" - count: 1 - path: library/Businessprocess/Storage/LegacyConfigParser.php - - - - message: "#^Parameter \\#1 \\$stream of function fgets expects resource, resource\\|false given\\.$#" - count: 1 - path: library/Businessprocess/Storage/LegacyConfigParser.php - - message: "#^Parameter \\#1 \\$string of function substr expects string, string\\|null given\\.$#" count: 1 @@ -3670,6 +3570,11 @@ parameters: count: 1 path: library/Businessprocess/Storage/LegacyStorage.php + - + message: "#^Method Icinga\\\\Module\\\\Businessprocess\\\\Storage\\\\Storage\\:\\:__construct\\(\\) has parameter \\$config with generic class Icinga\\\\Data\\\\ConfigObject but does not specify its types\\: TValue$#" + count: 1 + path: library/Businessprocess/Storage/Storage.php + - message: "#^Method Icinga\\\\Module\\\\Businessprocess\\\\Storage\\\\Storage\\:\\:deleteProcess\\(\\) has parameter \\$name with no type specified\\.$#" count: 1 @@ -3710,6 +3615,11 @@ parameters: count: 1 path: library/Businessprocess/Storage/Storage.php + - + message: "#^Property Icinga\\\\Module\\\\Businessprocess\\\\Storage\\\\Storage\\:\\:\\$config with generic class Icinga\\\\Data\\\\ConfigObject does not specify its types\\: TValue$#" + count: 1 + path: library/Businessprocess/Storage/Storage.php + - message: "#^Method Icinga\\\\Module\\\\Businessprocess\\\\Web\\\\Component\\\\BpDashboardTile\\:\\:__construct\\(\\) has parameter \\$attributes with no type specified\\.$#" count: 1 @@ -3850,11 +3760,6 @@ parameters: count: 1 path: library/Businessprocess/Web/Controller.php - - - message: "#^Parameter \\#2 \\$values of function vsprintf expects array\\, array\\ given\\.$#" - count: 1 - path: library/Businessprocess/Web/Controller.php - - message: "#^Method Icinga\\\\Module\\\\Businessprocess\\\\Web\\\\FakeRequest\\:\\:getBaseUrl\\(\\) has parameter \\$raw with no type specified\\.$#" count: 1 @@ -3940,11 +3845,6 @@ parameters: count: 1 path: library/Businessprocess/Web/Form/FormLoader.php - - - message: "#^Parameter \\#1 \\$array of function array_pop expects array, array\\\\|false given\\.$#" - count: 1 - path: library/Businessprocess/Web/Form/FormLoader.php - - message: "#^Cannot call method setDecorators\\(\\) on Zend_Form_Element\\|null\\.$#" count: 1 @@ -4390,11 +4290,6 @@ parameters: count: 1 path: library/Businessprocess/Web/Form/QuickForm.php - - - message: "#^Parameter \\#1 \\$array of function array_pop expects array, array\\\\|false given\\.$#" - count: 1 - path: library/Businessprocess/Web/Form/QuickForm.php - - message: "#^Property Icinga\\\\Module\\\\Businessprocess\\\\Web\\\\Form\\\\QuickForm\\:\\:\\$deleteButtonName has no type specified\\.$#" count: 1 diff --git a/phpstan.neon b/phpstan.neon index cd7850d9..77094963 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,6 @@ includes: - - phpstan-baseline.neon + - phpstan-baseline-standard.neon + - phpstan-baseline-by-php-version.php parameters: level: max