From c09e587948732cea0a33f2290e131018c1da3920 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Wed, 8 May 2024 08:07:47 +0200 Subject: [PATCH 1/3] Remove unused Controllers --- .../controllers/PlugController.php.disabled | 72 ---------- .../controllers/ReportController.php.modal | 126 ------------------ 2 files changed, 198 deletions(-) delete mode 100644 application/controllers/PlugController.php.disabled delete mode 100644 application/controllers/ReportController.php.modal diff --git a/application/controllers/PlugController.php.disabled b/application/controllers/PlugController.php.disabled deleted file mode 100644 index a2c64537..00000000 --- a/application/controllers/PlugController.php.disabled +++ /dev/null @@ -1,72 +0,0 @@ -params->get('module', 'reporting')); - - $reportsByModule = []; - - foreach (ReportHook::getReports() as $class => $report) { - $moduleName = $report->getModuleName(); - - if (! isset($reportsByModule[$moduleName])) { - $reportsByModule[$moduleName] = []; - } - - $reportsByModule[$moduleName][$class] = $report; - } - - $editor = Html::tag('div', ['class' => 'editor']); - - $nav = []; - - $cards = []; - - foreach ($reportsByModule as $moduleName => $reports) { - $link = Html::tag('a', ['href' => Url::fromRequest(['module' => $moduleName])], $moduleName); - - $nav[] = $link; - - if ($moduleName !== $moduleToShow) { - continue; - } - - $link->getAttributes()->add('class', 'active'); - - foreach ($reports as $report) { - $cards[] = Html::tag( - 'div', - ['class' => 'card'], - [ - Html::tag('div', ['class' => 'card-top'], $report->getPreview()), - Html::tag( - 'div', - ['class' => 'card-content'], - Html::tag('h5', ['class' => 'card-title'], $report->getName()), - Html::tag('p', ['class' => 'card-text'], $report->getDescription()) - ) - ] - ); - } - } - - $editor->add(Html::tag('div', ['class' => 'editor-nav'], $nav)); - $editor->add(Html::tag('div', ['class' => 'editor-content'], $cards)); - - $this->addContent($editor); - - $this->addContent(Html::tag('a', ['href' => 'plug', 'class' => 'modal-toggle', 'data-base-target' => 'modal-container'], 'Modal')); - } -} diff --git a/application/controllers/ReportController.php.modal b/application/controllers/ReportController.php.modal deleted file mode 100644 index 915bf2bf..00000000 --- a/application/controllers/ReportController.php.modal +++ /dev/null @@ -1,126 +0,0 @@ -report = Report::fromDb($this->params->getRequired('id')); - } - - public function indexAction() - { - $this->setTitle($this->report->getName()); - - $this->addControl($this->assembleActions()); - - $this->addContent($this->report->toHtml()); - } - - public function editAction() - { - $this->setTitle('Edit Report'); - - $values = [ - 'name' => $this->report->getName(), - 'timeframe' => $this->report->getTimeframe()->getId(), - ]; - - $reportlet = $this->report->getReportlets()[0]; - - $values['reportlet'] = $reportlet->getClass(); - - foreach ($reportlet->getConfig() as $name => $value) { - $values[$name] = $value; - } - - $form = new ReportForm(); - $form->setId($this->report->getId()); - $form->populate($values); - $form->handleRequest(ServerRequest::fromGlobals()); - - $this->redirectForm($form, 'reporting/reports'); - - $this->addContent($form); - } - - public function sendAction() - { - $this->setTitle('Send Report'); - - $form = new SendForm(); - $form - ->setReport($this->report) - ->handleRequest(ServerRequest::fromGlobals()); - - $this->redirectForm($form, "reporting/report?id={$this->report->getId()}"); - - $this->addContent(new Modal($form)); - } - - public function scheduleAction() - { - $this->setTitle('Schedule'); - - $form = new ScheduleForm(); - $form - ->setReport($this->report) - ->handleRequest(ServerRequest::fromGlobals()); - - $this->redirectForm($form, "reporting/report?id={$this->report->getId()}"); - - $this->addContent(new Modal($form)); - - $this->getResponse()->setHeader('X-Icinga-History', 'no', true); - } - - protected function assembleActions() - { - $reportId = $this->report->getId(); - - $download = (new DropdownLink('Download')) - ->addLink('PDF', Url::fromPath('reporting/report/download?type=pdf', ['id' => $reportId])); - - $send = (new DropdownLink('Send', 'forward')) - ->addLink('PDF', Url::fromPath('reporting/report/send?type=pdf', ['id' => $reportId])); - - if ($this->report->providesCsv()) { - $download->addLink('CSV', Url::fromPath('reporting/report/download?type=csv', ['id' => $reportId])); - $send->addLink('CSV', Url::fromPath('reporting/report/send?type=csv', ['id' => $reportId])); - } - - if ($this->report->providesJson()) { - $download->addLink('JSON', Url::fromPath('reporting/report/download?type=json', ['id' => $reportId])); - $send->addLink('JSON', Url::fromPath('reporting/report/send?type=json', ['id' => $reportId])); - } - - $actions = new ActionBar(); - - $actions - ->addLink('Modify', Url::fromPath('reporting/report/edit', ['id' => $reportId]), 'edit') - ->add(new ModalToggle('Schedule', Url::fromPath('reporting/report/schedule', ['id' => $reportId]), 'calendar-empty')) - ->add($download) - ->addLink('Send', Url::fromPath('reporting/report/send', ['id' => $reportId]), 'forward'); - - return $actions; - } -} From a574428f0e2b3befaf1d364eecdcbc600609ffc7 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Wed, 8 May 2024 08:12:32 +0200 Subject: [PATCH 2/3] Controller: Add return type to methods --- application/controllers/ConfigController.php | 6 +++--- application/controllers/ReportController.php | 16 ++++++++-------- application/controllers/ReportsController.php | 4 ++-- application/controllers/TemplateController.php | 6 +++--- application/controllers/TemplatesController.php | 4 ++-- application/controllers/TimeframeController.php | 4 ++-- application/controllers/TimeframesController.php | 4 ++-- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php index 7e73c3c0..583ad1ba 100644 --- a/application/controllers/ConfigController.php +++ b/application/controllers/ConfigController.php @@ -11,14 +11,14 @@ class ConfigController extends Controller { - public function init() + public function init(): void { $this->assertPermission('config/modules'); parent::init(); } - public function backendAction() + public function backendAction(): void { $form = (new SelectBackendForm()) ->setIniConfig(Config::module('reporting')); @@ -29,7 +29,7 @@ public function backendAction() $this->view->form = $form; } - public function mailAction() + public function mailAction(): void { $form = (new ConfigureMailForm()) ->setIniConfig(Config::module('reporting')); diff --git a/application/controllers/ReportController.php b/application/controllers/ReportController.php index 0a694f2e..cc9d9063 100644 --- a/application/controllers/ReportController.php +++ b/application/controllers/ReportController.php @@ -29,7 +29,7 @@ class ReportController extends Controller /** @var Report */ protected $report; - public function init() + public function init(): void { $reportId = $this->params->getRequired('id'); @@ -46,7 +46,7 @@ public function init() $this->report = Report::fromModel($report); } - public function indexAction() + public function indexAction(): void { $this->addTitleTab($this->report->getName()); @@ -89,7 +89,7 @@ public function contentAction(): void } } - public function cloneAction() + public function cloneAction(): void { $this->assertPermission('reporting/reports'); $this->addTitleTab($this->translate('Clone Report')); @@ -128,7 +128,7 @@ public function cloneAction() $this->addContent($form); } - public function editAction() + public function editAction(): void { $this->assertPermission('reporting/reports'); $this->addTitleTab($this->translate('Edit Report')); @@ -170,7 +170,7 @@ public function editAction() $this->addContent($form); } - public function sendAction() + public function sendAction(): void { $this->addTitleTab($this->translate('Send Report')); @@ -190,7 +190,7 @@ public function sendAction() $this->addContent($form); } - public function scheduleAction() + public function scheduleAction(): void { $this->assertPermission('reporting/schedules'); $this->addTitleTab($this->translate('Schedule')); @@ -227,7 +227,7 @@ public function scheduleAction() } } - public function downloadAction() + public function downloadAction(): void { $type = $this->params->getRequired('type'); @@ -274,7 +274,7 @@ public function downloadAction() } } - protected function assembleActions() + protected function assembleActions(): ActionBar { $reportId = $this->report->getId(); diff --git a/application/controllers/ReportsController.php b/application/controllers/ReportsController.php index f6aeedd6..c3c32283 100644 --- a/application/controllers/ReportsController.php +++ b/application/controllers/ReportsController.php @@ -20,7 +20,7 @@ class ReportsController extends Controller { use ReportsTimeframesAndTemplatesTabs; - public function indexAction() + public function indexAction(): void { $this->createTabs()->activate('reports'); @@ -95,7 +95,7 @@ public function indexAction() } } - public function newAction() + public function newAction(): void { $this->assertPermission('reporting/reports'); $this->addTitleTab($this->translate('New Report')); diff --git a/application/controllers/TemplateController.php b/application/controllers/TemplateController.php index 70cf9f0e..b2a3efcb 100644 --- a/application/controllers/TemplateController.php +++ b/application/controllers/TemplateController.php @@ -25,7 +25,7 @@ class TemplateController extends Controller /** @var Model\Template */ protected $template; - public function init() + public function init(): void { parent::init(); @@ -41,7 +41,7 @@ public function init() $this->template = $template; } - public function indexAction() + public function indexAction(): void { $this->addTitleTab($this->translate('Preview')); @@ -60,7 +60,7 @@ public function indexAction() $this->addContent($template); } - public function editAction() + public function editAction(): void { $this->assertPermission('reporting/templates'); $this->addTitleTab($this->translate('Edit Template')); diff --git a/application/controllers/TemplatesController.php b/application/controllers/TemplatesController.php index 99a5dcbf..9ab6db78 100644 --- a/application/controllers/TemplatesController.php +++ b/application/controllers/TemplatesController.php @@ -19,7 +19,7 @@ class TemplatesController extends Controller { use ReportsTimeframesAndTemplatesTabs; - public function indexAction() + public function indexAction(): void { $this->createTabs()->activate('templates'); @@ -92,7 +92,7 @@ public function indexAction() } } - public function newAction() + public function newAction(): void { $this->assertPermission('reporting/templates'); $this->addTitleTab($this->translate('New Template')); diff --git a/application/controllers/TimeframeController.php b/application/controllers/TimeframeController.php index 01395c2c..5b4e8739 100644 --- a/application/controllers/TimeframeController.php +++ b/application/controllers/TimeframeController.php @@ -20,7 +20,7 @@ class TimeframeController extends Controller /** @var Timeframe */ protected $timeframe; - public function init() + public function init(): void { /** @var Model\Timeframe $timeframe */ $timeframe = Model\Timeframe::on(Database::get()) @@ -34,7 +34,7 @@ public function init() $this->timeframe = Timeframe::fromModel($timeframe); } - public function editAction() + public function editAction(): void { $this->assertPermission('reporting/timeframes'); $this->addTitleTab($this->translate('Edit Time Frame')); diff --git a/application/controllers/TimeframesController.php b/application/controllers/TimeframesController.php index f38c6618..50c924c3 100644 --- a/application/controllers/TimeframesController.php +++ b/application/controllers/TimeframesController.php @@ -19,7 +19,7 @@ class TimeframesController extends Controller { use ReportsTimeframesAndTemplatesTabs; - public function indexAction() + public function indexAction(): void { $this->createTabs()->activate('timeframes'); @@ -102,7 +102,7 @@ public function indexAction() } } - public function newAction() + public function newAction(): void { $this->assertPermission('reporting/timeframes'); $this->addTitleTab($this->translate('New Timeframe')); From b04f85de0942bea6366e7f3ed797f8501d054963 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Wed, 8 May 2024 09:24:45 +0200 Subject: [PATCH 3/3] Phpstan: Cleanup baseline and remove superfluous type hints --- library/Reporting/Web/Forms/ReportForm.php | 2 - library/Reporting/Web/Forms/ScheduleForm.php | 2 - library/Reporting/Web/Forms/TemplateForm.php | 2 - library/Reporting/Web/Forms/TimeframeForm.php | 2 - phpstan-baseline.neon | 90 ------------------- 5 files changed, 98 deletions(-) diff --git a/library/Reporting/Web/Forms/ReportForm.php b/library/Reporting/Web/Forms/ReportForm.php index 40e376e7..83aa1792 100644 --- a/library/Reporting/Web/Forms/ReportForm.php +++ b/library/Reporting/Web/Forms/ReportForm.php @@ -7,7 +7,6 @@ use Icinga\Authentication\Auth; use Icinga\Module\Reporting\Database; use Icinga\Module\Reporting\ProvidedReports; -use ipl\Html\Contract\FormSubmitElement; use ipl\Html\Form; use ipl\Html\HtmlDocument; use ipl\Validator\CallbackValidator; @@ -167,7 +166,6 @@ protected function assemble() ]); if ($this->id !== null) { - /** @var FormSubmitElement $removeButton */ $removeButton = $this->createElement('submit', 'remove', [ 'label' => $this->translate('Remove Report'), 'class' => 'btn-remove', diff --git a/library/Reporting/Web/Forms/ScheduleForm.php b/library/Reporting/Web/Forms/ScheduleForm.php index 72c47670..4fc198ab 100644 --- a/library/Reporting/Web/Forms/ScheduleForm.php +++ b/library/Reporting/Web/Forms/ScheduleForm.php @@ -13,7 +13,6 @@ use Icinga\Module\Reporting\ProvidedActions; use Icinga\Module\Reporting\Report; use Icinga\Util\Json; -use ipl\Html\Contract\FormSubmitElement; use ipl\Html\Form; use ipl\Html\HtmlDocument; use ipl\Html\HtmlElement; @@ -130,7 +129,6 @@ protected function assemble() $wrapper = $this->getElement('submit')->getWrapper(); $wrapper->prepend($sendButton); - /** @var FormSubmitElement $removeButton */ $removeButton = $this->createElement('submit', 'remove', [ 'label' => $this->translate('Remove Schedule'), 'class' => 'btn-remove', diff --git a/library/Reporting/Web/Forms/TemplateForm.php b/library/Reporting/Web/Forms/TemplateForm.php index 4cd44a90..184dc805 100644 --- a/library/Reporting/Web/Forms/TemplateForm.php +++ b/library/Reporting/Web/Forms/TemplateForm.php @@ -9,7 +9,6 @@ use Icinga\Authentication\Auth; use Icinga\Module\Reporting\Database; use Icinga\Util\Json; -use ipl\Html\Contract\FormSubmitElement; use ipl\Html\Html; use ipl\Html\HtmlDocument; use ipl\Web\Compat\CompatForm; @@ -139,7 +138,6 @@ protected function assemble() ]); if ($this->template !== null) { - /** @var FormSubmitElement $removeButton */ $removeButton = $this->createElement('submit', 'remove', [ 'label' => $this->translate('Remove Template'), 'class' => 'btn-remove', diff --git a/library/Reporting/Web/Forms/TimeframeForm.php b/library/Reporting/Web/Forms/TimeframeForm.php index 37ea34f6..fe84152e 100644 --- a/library/Reporting/Web/Forms/TimeframeForm.php +++ b/library/Reporting/Web/Forms/TimeframeForm.php @@ -7,7 +7,6 @@ use DateTime; use Exception; use Icinga\Module\Reporting\Database; -use ipl\Html\Contract\FormSubmitElement; use ipl\Html\FormElement\LocalDateTimeElement; use ipl\Html\HtmlDocument; use ipl\Validator\CallbackValidator; @@ -166,7 +165,6 @@ protected function assemble() ]); if ($this->id !== null) { - /** @var FormSubmitElement $removeButton */ $removeButton = $this->createElement('submit', 'remove', [ 'label' => $this->translate('Remove Time Frame'), 'class' => 'btn-remove', diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 4799ad3f..36b87348 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -70,51 +70,6 @@ parameters: count: 1 path: application/clicommands/ScheduleCommand.php - - - message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\ConfigController\\:\\:backendAction\\(\\) has no return type specified\\.$#" - count: 1 - path: application/controllers/ConfigController.php - - - - message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\ConfigController\\:\\:mailAction\\(\\) has no return type specified\\.$#" - count: 1 - path: application/controllers/ConfigController.php - - - - message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\ReportController\\:\\:assembleActions\\(\\) has no return type specified\\.$#" - count: 1 - path: application/controllers/ReportController.php - - - - message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\ReportController\\:\\:cloneAction\\(\\) has no return type specified\\.$#" - count: 1 - path: application/controllers/ReportController.php - - - - message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\ReportController\\:\\:downloadAction\\(\\) has no return type specified\\.$#" - count: 1 - path: application/controllers/ReportController.php - - - - message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\ReportController\\:\\:editAction\\(\\) has no return type specified\\.$#" - count: 1 - path: application/controllers/ReportController.php - - - - message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\ReportController\\:\\:indexAction\\(\\) 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 - path: application/controllers/ReportController.php - - - - message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\ReportController\\:\\:sendAction\\(\\) has no return type specified\\.$#" - count: 1 - path: application/controllers/ReportController.php - - message: "#^Parameter \\#2 \\$value of static method ipl\\\\Stdlib\\\\Filter\\:\\:equal\\(\\) expects array\\|bool\\|float\\|int\\|string, mixed given\\.$#" count: 1 @@ -125,26 +80,6 @@ parameters: count: 1 path: application/controllers/ReportsController.php - - - message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\ReportsController\\:\\:indexAction\\(\\) 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 - path: application/controllers/ReportsController.php - - - - message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\TemplateController\\:\\:editAction\\(\\) has no return type specified\\.$#" - count: 1 - path: application/controllers/TemplateController.php - - - - message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\TemplateController\\:\\:indexAction\\(\\) 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 @@ -155,21 +90,6 @@ parameters: count: 2 path: application/controllers/TemplatesController.php - - - message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\TemplatesController\\:\\:indexAction\\(\\) 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 - path: application/controllers/TemplatesController.php - - - - message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\TimeframeController\\:\\:editAction\\(\\) 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 @@ -205,16 +125,6 @@ parameters: count: 1 path: application/controllers/TimeframesController.php - - - message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Controllers\\\\TimeframesController\\:\\:indexAction\\(\\) 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 - path: application/controllers/TimeframesController.php - - message: "#^Method Icinga\\\\Module\\\\Reporting\\\\Forms\\\\ConfigureMailForm\\:\\:createElements\\(\\) has no return type specified\\.$#" count: 1