diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 96cd3be8..c1d3f18b 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -17,7 +17,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: @@ -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 - git clone --depth 1 https://github.com/Icinga/icingaweb2-module-pdfexport.git vendor/pdfexport - 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/icingadb-web.git /usr/share/icingaweb2-modules/icingadb + sudo git clone --depth 1 https://github.com/Icinga/icingaweb2-module-pdfexport.git /usr/share/icingaweb2-modules/pdfexport + 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() }} @@ -49,4 +49,4 @@ jobs: - name: PHPStan if: ${{ ! cancelled() }} - uses: php-actions/phpstan@v3 + run: ./vendor/bin/phpstan analyse diff --git a/application/clicommands/DownloadCommand.php b/application/clicommands/DownloadCommand.php index 94a8c2aa..9b7c99d9 100644 --- a/application/clicommands/DownloadCommand.php +++ b/application/clicommands/DownloadCommand.php @@ -60,7 +60,9 @@ public function defaultAction() $report = Report::fromModel($report); - $format = strtolower($this->params->get('format', 'pdf')); + /** @var string $format */ + $format = $this->params->get('format', 'pdf'); + $format = strtolower($format); switch ($format) { case 'pdf': $content = Pdfexport::first()->htmlToPdf($report->toPdf()); @@ -75,6 +77,7 @@ public function defaultAction() throw new InvalidArgumentException(sprintf('Format %s is not supported', $format)); } + /** @var string $output */ $output = $this->params->get('output'); if ($output === null) { $name = sprintf( diff --git a/application/clicommands/ListCommand.php b/application/clicommands/ListCommand.php index c26a3d3a..2486ae0f 100644 --- a/application/clicommands/ListCommand.php +++ b/application/clicommands/ListCommand.php @@ -49,7 +49,9 @@ class ListCommand extends Command */ public function indexAction() { - $sort = strtolower($this->params->get('sort', 'id')); + /** @var string $sort */ + $sort = $this->params->get('sort', 'id'); + $sort = strtolower($sort); if ($sort !== 'id' && $sort !== 'name' && $sort !== 'author') { throw new InvalidArgumentException(sprintf('Sorting by %s is not supported', $sort)); diff --git a/library/Reporting/Actions/SendMail.php b/library/Reporting/Actions/SendMail.php index 122af0b8..a0dc42f6 100644 --- a/library/Reporting/Actions/SendMail.php +++ b/library/Reporting/Actions/SendMail.php @@ -57,9 +57,10 @@ public function execute(Report $report, array $config) throw new \InvalidArgumentException(); } - $recipients = array_filter(preg_split('/[\s,]+/', $config['recipients'])); + /** @var array $recipients */ + $recipients = preg_split('/[\s,]+/', $config['recipients']); - $mail->send(null, $recipients); + $mail->send(null, array_filter($recipients)); } public function initConfigForm(Form $form, Report $report) diff --git a/library/Reporting/Reports/SystemReport.php b/library/Reporting/Reports/SystemReport.php index 32f63b86..5c9a5445 100644 --- a/library/Reporting/Reports/SystemReport.php +++ b/library/Reporting/Reports/SystemReport.php @@ -20,6 +20,7 @@ public function getHtml(Timerange $timerange, array $config = null) { ob_start(); phpinfo(); + /** @var string $html */ $html = ob_get_clean(); if (! Icinga::app()->isCli()) { diff --git a/library/Reporting/Str.php b/library/Reporting/Str.php index 7c6a7c05..77eb65e8 100644 --- a/library/Reporting/Str.php +++ b/library/Reporting/Str.php @@ -8,6 +8,7 @@ class Str { public static function putcsv(array $data, $delimiter = ',', $enclosure = '"', $escape = '\\') { + /** @var resource $fp */ $fp = fopen('php://temp', 'r+b'); foreach ($data as $row) { @@ -16,6 +17,7 @@ public static function putcsv(array $data, $delimiter = ',', $enclosure = '"', $ rewind($fp); + /** @var string $csv */ $csv = stream_get_contents($fp); fclose($fp); diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 3e721e84..4799ad3f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -5,36 +5,11 @@ parameters: count: 1 path: application/clicommands/DownloadCommand.php - - - message: "#^Parameter \\#1 \\$filename of function file_put_contents expects string, mixed given\\.$#" - count: 1 - path: application/clicommands/DownloadCommand.php - - - - message: "#^Parameter \\#1 \\$filename of function is_dir expects string, mixed given\\.$#" - count: 1 - path: application/clicommands/DownloadCommand.php - - - - message: "#^Parameter \\#1 \\$string of function strtolower expects string, mixed given\\.$#" - count: 1 - path: application/clicommands/DownloadCommand.php - - message: "#^Parameter \\#2 \\$value of static method ipl\\\\Stdlib\\\\Filter\\:\\:equal\\(\\) expects array\\|bool\\|float\\|int\\|string, mixed given\\.$#" count: 1 path: application/clicommands/DownloadCommand.php - - - message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#" - count: 1 - path: application/clicommands/DownloadCommand.php - - - - message: "#^Part \\$output \\(mixed\\) of encapsed string cannot be cast to string\\.$#" - count: 1 - path: application/clicommands/DownloadCommand.php - - message: "#^Call to an undefined method object\\:\\:getName\\(\\)\\.$#" count: 1 @@ -65,11 +40,6 @@ parameters: count: 1 path: application/clicommands/ListCommand.php - - - message: "#^Parameter \\#1 \\$string of function strtolower expects string, mixed given\\.$#" - count: 1 - path: application/clicommands/ListCommand.php - - message: "#^Parameter \\#2 \\$direction of method ipl\\\\Orm\\\\Query\\:\\:orderBy\\(\\) expects int\\|string\\|null, mixed given\\.$#" count: 1 @@ -280,11 +250,6 @@ parameters: count: 1 path: library/Reporting/Actions/SendMail.php - - - message: "#^Parameter \\#1 \\$array of function array_filter expects array, array\\\\|false given\\.$#" - count: 1 - path: library/Reporting/Actions/SendMail.php - - message: "#^Parameter \\#1 \\$from of method Icinga\\\\Module\\\\Reporting\\\\Mail\\:\\:setFrom\\(\\) expects string, mixed given\\.$#" count: 1 @@ -695,16 +660,6 @@ parameters: count: 1 path: library/Reporting/Reports/SystemReport.php - - - message: "#^Parameter \\#1 \\$source of method DOMDocument\\:\\:loadHTML\\(\\) expects string, string\\|false given\\.$#" - count: 1 - path: library/Reporting/Reports/SystemReport.php - - - - message: "#^Parameter \\#1 \\$string of function nl2br expects string, string\\|false given\\.$#" - count: 1 - path: library/Reporting/Reports/SystemReport.php - - message: "#^Method Icinga\\\\Module\\\\Reporting\\\\RetryConnection\\:\\:prepexec\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#" count: 1 @@ -780,31 +735,6 @@ parameters: count: 1 path: library/Reporting/Str.php - - - message: "#^Parameter \\#1 \\$stream of function fclose expects resource, resource\\|false given\\.$#" - count: 1 - path: library/Reporting/Str.php - - - - message: "#^Parameter \\#1 \\$stream of function fputcsv expects resource, resource\\|false given\\.$#" - count: 1 - path: library/Reporting/Str.php - - - - message: "#^Parameter \\#1 \\$stream of function rewind expects resource, resource\\|false given\\.$#" - count: 1 - path: library/Reporting/Str.php - - - - message: "#^Parameter \\#1 \\$stream of function stream_get_contents expects resource, resource\\|false given\\.$#" - count: 1 - path: library/Reporting/Str.php - - - - message: "#^Parameter \\#1 \\$string of function rtrim expects string, string\\|false given\\.$#" - count: 1 - path: library/Reporting/Str.php - - message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Timeframe\\:\\:getTimerange\\(\\) has no return type specified\\.$#" count: 1 diff --git a/phpstan.neon b/phpstan.neon index 264c33dc..b540b892 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -13,7 +13,11 @@ parameters: - library scanDirectories: - - vendor + - /icingaweb2 + - /usr/share/icinga-php/ipl + - /usr/share/icinga-php/vendor + - /usr/share/icingaweb2-modules/icingadb + - /usr/share/icingaweb2-modules/pdfexport ignoreErrors: -