Skip to content

Commit

Permalink
Add missing variable type hints
Browse files Browse the repository at this point in the history
These errors are the only difference between PHP 7.x and 8.x phpstan
error reports. Therefore, it doesn't make sense to maintain different
neon files just because of these errors.
  • Loading branch information
yhabteab committed Nov 20, 2023
1 parent 320501a commit 493048e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 74 deletions.
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

0 comments on commit 493048e

Please sign in to comment.