diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 2c1132e9..b08065cc 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -32,11 +32,11 @@ 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/icingaweb2-module-director.git vendor/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 https://github.com/Icinga/icingaweb2-module-director.git /usr/share/icingaweb2-modules/director + 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 - name: PHP Lint if: ${{ ! cancelled() }} @@ -48,7 +48,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-baseline-7x.neon b/phpstan-baseline-7x.neon new file mode 100644 index 00000000..62ec10c9 --- /dev/null +++ b/phpstan-baseline-7x.neon @@ -0,0 +1,96 @@ +parameters: + ignoreErrors: + - + message: "#^Parameter \\#1 \\$x509certdata of function openssl_x509_read expects resource\\|string, mixed given\\.$#" + count: 1 + path: application/clicommands/ImportCommand.php + + - + message: "#^Parameter \\#1 \\$data of function bin2hex expects string, mixed given\\.$#" + count: 2 + path: library/X509/CertificateDetails.php + + - + message: "#^Parameter \\#1 \\$x509cert of function openssl_x509_parse expects resource\\|string, mixed given\\.$#" + count: 1 + path: library/X509/CertificateDetails.php + + - + message: "#^Parameter \\#2 \\$pieces of function implode expects array, array\\\\|false given\\.$#" + count: 1 + path: library/X509/CertificateDetails.php + + - + message: "#^Parameter \\#1 \\$certificate of function openssl_pkey_get_public expects resource\\|string, mixed given\\.$#" + count: 1 + path: library/X509/CertificateUtils.php + + - + message: "#^Parameter \\#1 \\$key of function openssl_pkey_get_details expects resource, resource\\|false given\\.$#" + count: 1 + path: library/X509/CertificateUtils.php + + - + message: "#^Parameter \\#1 \\$x509 of function openssl_x509_export expects resource\\|string, mixed given\\.$#" + count: 1 + path: library/X509/CertificateUtils.php + + - + message: "#^Parameter \\#1 \\$x509 of function openssl_x509_fingerprint expects resource\\|string, mixed given\\.$#" + count: 1 + path: library/X509/CertificateUtils.php + + - + message: "#^Parameter \\#1 \\$x509cert of function openssl_x509_parse expects resource\\|string, mixed given\\.$#" + count: 1 + path: library/X509/CertificateUtils.php + + - + message: "#^Parameter \\#2 \\$str of function explode expects string, string\\|false given\\.$#" + count: 1 + path: library/X509/CertificateUtils.php + + - + message: "#^Parameter \\#1 \\$a of function gmp_add expects GMP\\|int\\|string, GMP\\|null given\\.$#" + count: 1 + path: library/X509/Job.php + + - + message: "#^Parameter \\#1 \\$a of function gmp_and expects GMP\\|int\\|string, GMP\\|null given\\.$#" + count: 1 + path: library/X509/Job.php + + - + message: "#^Parameter \\#1 \\$input of function str_pad expects string, string\\|false given\\.$#" + count: 1 + path: library/X509/Job.php + + - + message: "#^Parameter \\#1 \\$str of function base64_encode expects string, mixed given\\.$#" + count: 1 + path: library/X509/Model/Behavior/DERBase64.php + + - + message: "#^Parameter \\#2 \\$str of function explode expects string, mixed given\\.$#" + count: 1 + path: library/X509/Model/Behavior/DERBase64.php + + - + message: "#^Parameter \\#1 \\$in_addr of function inet_ntop expects string, mixed given\\.$#" + count: 1 + path: library/X509/Model/Behavior/Ip.php + + - + message: "#^Parameter \\#1 \\$input of function str_pad expects string, string\\|false given\\.$#" + count: 1 + path: library/X509/Model/Behavior/Ip.php + + - + message: "#^Parameter \\#1 \\$ip_address of function inet_pton expects string, mixed given\\.$#" + count: 1 + path: library/X509/Model/Behavior/Ip.php + + - + message: "#^Parameter \\#1 \\$str of function ltrim expects string, mixed given\\.$#" + count: 1 + path: library/X509/Model/Behavior/Ip.php diff --git a/phpstan-baseline-8x.neon b/phpstan-baseline-8x.neon new file mode 100644 index 00000000..7ffc0fed --- /dev/null +++ b/phpstan-baseline-8x.neon @@ -0,0 +1,96 @@ +parameters: + ignoreErrors: + - + message: "#^Parameter \\#1 \\$certificate of function openssl_x509_read expects OpenSSLCertificate\\|string, mixed given\\.$#" + count: 1 + path: application/clicommands/ImportCommand.php + + - + message: "#^Parameter \\#1 \\$certificate of function openssl_x509_parse expects OpenSSLCertificate\\|string, mixed given\\.$#" + count: 1 + path: library/X509/CertificateDetails.php + + - + message: "#^Parameter \\#1 \\$string of function bin2hex expects string, mixed given\\.$#" + count: 2 + path: library/X509/CertificateDetails.php + + - + message: "#^Parameter \\#2 \\$array of function implode expects array\\|null, array\\\\|false given\\.$#" + count: 1 + path: library/X509/CertificateDetails.php + + - + message: "#^Parameter \\#1 \\$certificate of function openssl_x509_export expects OpenSSLCertificate\\|string, mixed given\\.$#" + count: 1 + path: library/X509/CertificateUtils.php + + - + message: "#^Parameter \\#1 \\$certificate of function openssl_x509_fingerprint expects OpenSSLCertificate\\|string, mixed given\\.$#" + count: 1 + path: library/X509/CertificateUtils.php + + - + message: "#^Parameter \\#1 \\$certificate of function openssl_x509_parse expects OpenSSLCertificate\\|string, mixed given\\.$#" + count: 1 + path: library/X509/CertificateUtils.php + + - + message: "#^Parameter \\#1 \\$key of function openssl_pkey_get_details expects OpenSSLAsymmetricKey, OpenSSLAsymmetricKey\\|false given\\.$#" + count: 1 + path: library/X509/CertificateUtils.php + + - + message: "#^Parameter \\#1 \\$public_key of function openssl_pkey_get_public expects array\\|OpenSSLAsymmetricKey\\|OpenSSLCertificate\\|string, mixed given\\.$#" + count: 1 + path: library/X509/CertificateUtils.php + + - + message: "#^Parameter \\#2 \\$string of function explode expects string, string\\|false given\\.$#" + count: 1 + path: library/X509/CertificateUtils.php + + - + message: "#^Parameter \\#1 \\$num1 of function gmp_add expects GMP\\|int\\|string, GMP\\|null given\\.$#" + count: 1 + path: library/X509/Job.php + + - + message: "#^Parameter \\#1 \\$num1 of function gmp_and expects GMP\\|int\\|string, GMP\\|null given\\.$#" + count: 1 + path: library/X509/Job.php + + - + message: "#^Parameter \\#1 \\$string of function str_pad expects string, string\\|false given\\.$#" + count: 1 + path: library/X509/Job.php + + - + message: "#^Parameter \\#1 \\$string of function base64_encode expects string, mixed given\\.$#" + count: 1 + path: library/X509/Model/Behavior/DERBase64.php + + - + message: "#^Parameter \\#2 \\$string of function explode expects string, mixed given\\.$#" + count: 1 + path: library/X509/Model/Behavior/DERBase64.php + + - + message: "#^Parameter \\#1 \\$ip of function inet_ntop expects string, mixed given\\.$#" + count: 1 + path: library/X509/Model/Behavior/Ip.php + + - + message: "#^Parameter \\#1 \\$ip of function inet_pton expects string, mixed given\\.$#" + count: 1 + path: library/X509/Model/Behavior/Ip.php + + - + message: "#^Parameter \\#1 \\$string of function ltrim expects string, mixed given\\.$#" + count: 1 + path: library/X509/Model/Behavior/Ip.php + + - + message: "#^Parameter \\#1 \\$string of function str_pad expects string, string\\|false given\\.$#" + count: 1 + path: library/X509/Model/Behavior/Ip.php diff --git a/phpstan-baseline-by-php-version.php b/phpstan-baseline-by-php-version.php new file mode 100644 index 00000000..20995351 --- /dev/null +++ b/phpstan-baseline-by-php-version.php @@ -0,0 +1,10 @@ += 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-common.neon similarity index 92% rename from phpstan-baseline.neon rename to phpstan-baseline-common.neon index d8f2198f..1bc2792d 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline-common.neon @@ -75,11 +75,6 @@ parameters: count: 1 path: application/clicommands/ImportCommand.php - - - message: "#^Parameter \\#1 \\$certificate of function openssl_x509_read expects OpenSSLCertificate\\|string, mixed given\\.$#" - count: 1 - path: application/clicommands/ImportCommand.php - - message: "#^Parameter \\#1 \\$file of static method Icinga\\\\Module\\\\X509\\\\CertificateUtils\\:\\:parseBundle\\(\\) expects string, mixed given\\.$#" count: 1 @@ -375,21 +370,6 @@ parameters: count: 1 path: library/X509/CertificateDetails.php - - - message: "#^Parameter \\#1 \\$certificate of function openssl_x509_parse expects OpenSSLCertificate\\|string, mixed given\\.$#" - count: 1 - path: library/X509/CertificateDetails.php - - - - message: "#^Parameter \\#1 \\$string of function bin2hex expects string, mixed given\\.$#" - count: 2 - path: library/X509/CertificateDetails.php - - - - message: "#^Parameter \\#2 \\$array of function implode expects array\\|null, array\\\\|false given\\.$#" - count: 1 - path: library/X509/CertificateDetails.php - - message: "#^Cannot access offset 'bits' on array\\|false\\.$#" count: 1 @@ -505,41 +485,16 @@ parameters: count: 1 path: library/X509/CertificateUtils.php - - - message: "#^Parameter \\#1 \\$certificate of function openssl_x509_export expects OpenSSLCertificate\\|string, mixed given\\.$#" - count: 1 - path: library/X509/CertificateUtils.php - - - - message: "#^Parameter \\#1 \\$certificate of function openssl_x509_fingerprint expects OpenSSLCertificate\\|string, mixed given\\.$#" - count: 1 - path: library/X509/CertificateUtils.php - - - - message: "#^Parameter \\#1 \\$certificate of function openssl_x509_parse expects OpenSSLCertificate\\|string, mixed given\\.$#" - count: 1 - path: library/X509/CertificateUtils.php - - message: "#^Parameter \\#1 \\$chainId of closure expects int, mixed given\\.$#" count: 1 path: library/X509/CertificateUtils.php - - - message: "#^Parameter \\#1 \\$key of function openssl_pkey_get_details expects OpenSSLAsymmetricKey, OpenSSLAsymmetricKey\\|false given\\.$#" - count: 1 - path: library/X509/CertificateUtils.php - - message: "#^Parameter \\#1 \\$orderBy of method ipl\\\\Orm\\\\Query\\:\\:orderBy\\(\\) expects array\\|int\\|string, ipl\\\\Sql\\\\Expression given\\.$#" count: 1 path: library/X509/CertificateUtils.php - - - message: "#^Parameter \\#1 \\$public_key of function openssl_pkey_get_public expects array\\|OpenSSLAsymmetricKey\\|OpenSSLCertificate\\|string, mixed given\\.$#" - count: 1 - path: library/X509/CertificateUtils.php - - message: "#^Parameter \\#2 \\$collection of closure expects array, mixed given\\.$#" count: 1 @@ -550,11 +505,6 @@ parameters: count: 1 path: library/X509/CertificateUtils.php - - - message: "#^Parameter \\#2 \\$string of function explode expects string, string\\|false given\\.$#" - count: 1 - path: library/X509/CertificateUtils.php - - message: "#^Method Icinga\\\\Module\\\\X509\\\\CertificatesTable\\:\\:createColumns\\(\\) has no return type specified\\.$#" count: 1 @@ -945,21 +895,6 @@ parameters: count: 1 path: library/X509/Job.php - - - message: "#^Parameter \\#1 \\$num1 of function gmp_add expects GMP\\|int\\|string, GMP\\|null given\\.$#" - count: 1 - path: library/X509/Job.php - - - - message: "#^Parameter \\#1 \\$num1 of function gmp_and expects GMP\\|int\\|string, GMP\\|null given\\.$#" - count: 1 - path: library/X509/Job.php - - - - message: "#^Parameter \\#1 \\$string of function str_pad expects string, string\\|false given\\.$#" - count: 1 - path: library/X509/Job.php - - message: "#^Parameter \\#2 \\$value of static method ipl\\\\Stdlib\\\\Filter\\:\\:equal\\(\\) expects array\\|bool\\|float\\|int\\|string, mixed given\\.$#" count: 1 @@ -970,16 +905,6 @@ parameters: count: 1 path: library/X509/Job.php - - - message: "#^Parameter \\#1 \\$string of function base64_encode expects string, mixed given\\.$#" - count: 1 - path: library/X509/Model/Behavior/DERBase64.php - - - - message: "#^Parameter \\#2 \\$string of function explode expects string, mixed given\\.$#" - count: 1 - path: library/X509/Model/Behavior/DERBase64.php - - message: "#^Method Icinga\\\\Module\\\\X509\\\\Model\\\\Behavior\\\\ExpressionInjector\\:\\:__construct\\(\\) has parameter \\$columns with no type specified\\.$#" count: 1 @@ -995,26 +920,6 @@ parameters: count: 1 path: library/X509/Model/Behavior/ExpressionInjector.php - - - message: "#^Parameter \\#1 \\$ip of function inet_ntop expects string, mixed given\\.$#" - count: 1 - path: library/X509/Model/Behavior/Ip.php - - - - message: "#^Parameter \\#1 \\$ip of function inet_pton expects string, mixed given\\.$#" - count: 1 - path: library/X509/Model/Behavior/Ip.php - - - - message: "#^Parameter \\#1 \\$string of function ltrim expects string, mixed given\\.$#" - count: 1 - path: library/X509/Model/Behavior/Ip.php - - - - message: "#^Parameter \\#1 \\$string of function str_pad expects string, string\\|false given\\.$#" - count: 1 - path: library/X509/Model/Behavior/Ip.php - - message: "#^Method Icinga\\\\Module\\\\X509\\\\Model\\\\X509Certificate\\:\\:createBehaviors\\(\\) has no return type specified\\.$#" count: 1 diff --git a/phpstan.neon b/phpstan.neon index 6b51bb43..efeb32e3 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,6 @@ includes: - - phpstan-baseline.neon + - phpstan-baseline-common.neon + - phpstan-baseline-by-php-version.php parameters: level: max @@ -13,7 +14,10 @@ parameters: - library scanDirectories: - - vendor + - /icingaweb2 + - /usr/share/icingaweb2-modules/director + - /usr/share/icinga-php/ipl + - /usr/share/icinga-php/vendor ignoreErrors: -