diff --git a/library/Reporting/Database.php b/library/Reporting/Database.php index 24b28fc..2e9d551 100644 --- a/library/Reporting/Database.php +++ b/library/Reporting/Database.php @@ -29,33 +29,54 @@ protected function getDb(): RetryConnection return new RetryConnection($config); } - protected function listTimeframes() + /** + * List all reporting timeframes + * + * @return array + */ + 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 + */ + 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 + */ + 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; } } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index fa9a09b..c971c03 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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