Skip to content

Commit

Permalink
Fix missing return type hints for Database::list{Timeframes,Templates}
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Sep 15, 2023
1 parent cec1e83 commit d656cb6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 169 deletions.
59 changes: 40 additions & 19 deletions library/Reporting/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,54 @@ protected function getDb(): RetryConnection
return new RetryConnection($config);
}

protected function listTimeframes()
/**
* List all reporting timeframes
*
* @return array<int, string>
*/
protected function listTimeframes(): array
{
$select = (new Sql\Select())
->from('timeframe')
->columns(['id', 'name']);

$timeframes = [];
/** @var stdClass $row */
foreach ($this->getDb()->select($select) as $row) {
$timeframes[$row->id] = $row->name;
}

return $timeframes;
return $this->list(
(new Sql\Select())
->from('timeframe')
->columns(['id', 'name'])
);
}

protected function listTemplates()
/**
* List all reporting templates
*
* @return array<int, string>
*/
protected function listTemplates(): array
{
$select = (new Sql\Select())
->from('template')
->columns(['id', 'name']);
return $this->list(
(new Sql\Select())
->from('template')
->columns(['id', 'name'])
);
}

$templates = [];
/**
* Helper method for list templates and timeframes
*
* @param Sql\Select $select
*
* @return array<int, string>
*/
private function list(Sql\Select $select): array
{
$result = [];
/** @var stdClass $row */
foreach ($this->getDb()->select($select) as $row) {
$templates[$row->id] = $row->name;
/** @var int $id */
$id = $row->id;
/** @var string $name */
$name = $row->name;

$result[$id] = $name;
}

return $templates;
return $result;
}
}
150 changes: 0 additions & 150 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,6 @@ parameters:
count: 1
path: application/controllers/ReportController.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\ReportController\\:\\:listTemplates\\(\\) has no return type specified\\.$#"
count: 1
path: application/controllers/ReportController.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\ReportController\\:\\:listTimeframes\\(\\) has no return type specified\\.$#"
count: 1
path: application/controllers/ReportController.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\ReportController\\:\\:scheduleAction\\(\\) has no return type specified\\.$#"
count: 1
Expand All @@ -170,16 +160,6 @@ parameters:
count: 1
path: application/controllers/ReportsController.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\ReportsController\\:\\:listTemplates\\(\\) has no return type specified\\.$#"
count: 1
path: application/controllers/ReportsController.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\ReportsController\\:\\:listTimeframes\\(\\) has no return type specified\\.$#"
count: 1
path: application/controllers/ReportsController.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\ReportsController\\:\\:newAction\\(\\) has no return type specified\\.$#"
count: 1
Expand All @@ -195,16 +175,6 @@ parameters:
count: 1
path: application/controllers/TemplateController.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\TemplateController\\:\\:listTemplates\\(\\) has no return type specified\\.$#"
count: 1
path: application/controllers/TemplateController.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\TemplateController\\:\\:listTimeframes\\(\\) has no return type specified\\.$#"
count: 1
path: application/controllers/TemplateController.php

-
message: "#^Parameter \\#2 \\$value of static method ipl\\\\Stdlib\\\\Filter\\:\\:equal\\(\\) expects array\\|bool\\|float\\|int\\|string, mixed given\\.$#"
count: 1
Expand All @@ -220,16 +190,6 @@ parameters:
count: 1
path: application/controllers/TemplatesController.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\TemplatesController\\:\\:listTemplates\\(\\) has no return type specified\\.$#"
count: 1
path: application/controllers/TemplatesController.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\TemplatesController\\:\\:listTimeframes\\(\\) has no return type specified\\.$#"
count: 1
path: application/controllers/TemplatesController.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\TemplatesController\\:\\:newAction\\(\\) has no return type specified\\.$#"
count: 1
Expand All @@ -240,16 +200,6 @@ parameters:
count: 1
path: application/controllers/TimeframeController.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\TimeframeController\\:\\:listTemplates\\(\\) has no return type specified\\.$#"
count: 1
path: application/controllers/TimeframeController.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\TimeframeController\\:\\:listTimeframes\\(\\) has no return type specified\\.$#"
count: 1
path: application/controllers/TimeframeController.php

-
message: "#^Parameter \\#2 \\$value of static method ipl\\\\Stdlib\\\\Filter\\:\\:equal\\(\\) expects array\\|bool\\|float\\|int\\|string, mixed given\\.$#"
count: 1
Expand Down Expand Up @@ -290,16 +240,6 @@ parameters:
count: 1
path: application/controllers/TimeframesController.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\TimeframesController\\:\\:listTemplates\\(\\) has no return type specified\\.$#"
count: 1
path: application/controllers/TimeframesController.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\TimeframesController\\:\\:listTimeframes\\(\\) has no return type specified\\.$#"
count: 1
path: application/controllers/TimeframesController.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\TimeframesController\\:\\:newAction\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -355,16 +295,6 @@ parameters:
count: 1
path: library/Reporting/Cli/Command.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Cli\\\\Command\\:\\:listTemplates\\(\\) has no return type specified\\.$#"
count: 1
path: library/Reporting/Cli/Command.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Cli\\\\Command\\:\\:listTimeframes\\(\\) has no return type specified\\.$#"
count: 1
path: library/Reporting/Cli/Command.php

-
message: "#^Property Icinga\\\\Module\\\\Reporting\\\\Cli\\\\Command\\:\\:\\$configs has no type specified\\.$#"
count: 1
Expand Down Expand Up @@ -580,16 +510,6 @@ parameters:
count: 2
path: library/Reporting/Report.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Report\\:\\:listTemplates\\(\\) has no return type specified\\.$#"
count: 1
path: library/Reporting/Report.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Report\\:\\:listTimeframes\\(\\) has no return type specified\\.$#"
count: 1
path: library/Reporting/Report.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Report\\:\\:providesData\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -890,16 +810,6 @@ parameters:
count: 1
path: library/Reporting/Timeframe.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Timeframe\\:\\:listTemplates\\(\\) has no return type specified\\.$#"
count: 1
path: library/Reporting/Timeframe.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Timeframe\\:\\:listTimeframes\\(\\) has no return type specified\\.$#"
count: 1
path: library/Reporting/Timeframe.php

-
message: "#^Property Icinga\\\\Module\\\\Reporting\\\\Timeframe\\:\\:\\$end \\(string\\) does not accept mixed\\.$#"
count: 1
Expand Down Expand Up @@ -945,16 +855,6 @@ parameters:
count: 1
path: library/Reporting/Web/Forms/ReportForm.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\ReportForm\\:\\:listTemplates\\(\\) has no return type specified\\.$#"
count: 1
path: library/Reporting/Web/Forms/ReportForm.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\ReportForm\\:\\:listTimeframes\\(\\) has no return type specified\\.$#"
count: 1
path: library/Reporting/Web/Forms/ReportForm.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\ReportForm\\:\\:onSuccess\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -990,16 +890,6 @@ parameters:
count: 1
path: library/Reporting/Web/Forms/ScheduleForm.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\ScheduleForm\\:\\:listTemplates\\(\\) has no return type specified\\.$#"
count: 1
path: library/Reporting/Web/Forms/ScheduleForm.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\ScheduleForm\\:\\:listTimeframes\\(\\) has no return type specified\\.$#"
count: 1
path: library/Reporting/Web/Forms/ScheduleForm.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\ScheduleForm\\:\\:onSuccess\\(\\) has no return type specified\\.$#"
count: 1
Expand All @@ -1020,16 +910,6 @@ parameters:
count: 1
path: library/Reporting/Web/Forms/SendForm.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\SendForm\\:\\:listTemplates\\(\\) has no return type specified\\.$#"
count: 1
path: library/Reporting/Web/Forms/SendForm.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\SendForm\\:\\:listTimeframes\\(\\) has no return type specified\\.$#"
count: 1
path: library/Reporting/Web/Forms/SendForm.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\SendForm\\:\\:onSuccess\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -1075,16 +955,6 @@ parameters:
count: 1
path: library/Reporting/Web/Forms/TemplateForm.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\TemplateForm\\:\\:listTemplates\\(\\) has no return type specified\\.$#"
count: 1
path: library/Reporting/Web/Forms/TemplateForm.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\TemplateForm\\:\\:listTimeframes\\(\\) has no return type specified\\.$#"
count: 1
path: library/Reporting/Web/Forms/TemplateForm.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\TemplateForm\\:\\:onSuccess\\(\\) has no return type specified\\.$#"
count: 1
Expand All @@ -1100,16 +970,6 @@ parameters:
count: 1
path: library/Reporting/Web/Forms/TimeframeForm.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\TimeframeForm\\:\\:listTemplates\\(\\) has no return type specified\\.$#"
count: 1
path: library/Reporting/Web/Forms/TimeframeForm.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\TimeframeForm\\:\\:listTimeframes\\(\\) has no return type specified\\.$#"
count: 1
path: library/Reporting/Web/Forms/TimeframeForm.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Forms\\\\TimeframeForm\\:\\:onSuccess\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -1285,16 +1145,6 @@ parameters:
count: 1
path: library/Reporting/Web/Widget/Template.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\Template\\:\\:listTemplates\\(\\) has no return type specified\\.$#"
count: 1
path: library/Reporting/Web/Widget/Template.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\Template\\:\\:listTimeframes\\(\\) has no return type specified\\.$#"
count: 1
path: library/Reporting/Web/Widget/Template.php

-
message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Web\\\\Widget\\\\Template\\:\\:resolveMacros\\(\\) has no return type specified\\.$#"
count: 1
Expand Down

0 comments on commit d656cb6

Please sign in to comment.