Skip to content

Commit

Permalink
Run phpstan for all supported PHP versions (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab authored Nov 20, 2023
2 parents 320501a + 7136892 commit 4934a08
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 83 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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() }}
Expand All @@ -49,4 +49,4 @@ jobs:

- name: PHPStan
if: ${{ ! cancelled() }}
uses: php-actions/phpstan@v3
run: ./vendor/bin/phpstan analyse
5 changes: 4 additions & 1 deletion application/clicommands/DownloadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion application/clicommands/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
5 changes: 3 additions & 2 deletions library/Reporting/Actions/SendMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ public function execute(Report $report, array $config)
throw new \InvalidArgumentException();
}

$recipients = array_filter(preg_split('/[\s,]+/', $config['recipients']));
/** @var array<int, string> $recipients */
$recipients = preg_split('/[\s,]+/', $config['recipients']);

$mail->send(null, $recipients);
$mail->send(null, array_filter($recipients));
}

public function initConfigForm(Form $form, Report $report)
Expand Down
1 change: 1 addition & 0 deletions library/Reporting/Reports/SystemReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
2 changes: 2 additions & 0 deletions library/Reporting/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -16,6 +17,7 @@ public static function putcsv(array $data, $delimiter = ',', $enclosure = '"', $

rewind($fp);

/** @var string $csv */
$csv = stream_get_contents($fp);

fclose($fp);
Expand Down
70 changes: 0 additions & 70 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -280,11 +250,6 @@ parameters:
count: 1
path: library/Reporting/Actions/SendMail.php

-
message: "#^Parameter \\#1 \\$array of function array_filter expects array, array\\<int, string\\>\\|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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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:
-
Expand Down

0 comments on commit 4934a08

Please sign in to comment.