From aefd0e1f7dc75dbeff340e04471cf8edae94cf01 Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Wed, 22 Sep 2021 10:21:15 +0200 Subject: [PATCH] Add PHP 7 argument & return type declarations to all member methods --- application/controllers/CommentController.php | 2 +- application/controllers/ConfigController.php | 2 +- .../controllers/DowntimeController.php | 2 +- application/controllers/HostController.php | 9 +-- application/controllers/HostsController.php | 3 +- application/controllers/ServiceController.php | 6 +- .../controllers/ServicesController.php | 5 +- application/forms/Command/CommandForm.php | 2 +- .../Instance/ToggleInstanceFeaturesForm.php | 6 +- .../Command/Object/AcknowledgeProblemForm.php | 3 + .../forms/Command/Object/AddCommentForm.php | 3 + .../forms/Command/Object/CheckNowForm.php | 3 + .../Command/Object/DeleteCommentForm.php | 3 + .../Command/Object/DeleteDowntimeForm.php | 3 + .../Command/Object/ProcessCheckResultForm.php | 3 + .../Object/RemoveAcknowledgementForm.php | 3 + .../Command/Object/ScheduleCheckForm.php | 3 + .../Object/ScheduleHostDowntimeForm.php | 3 + .../Object/ScheduleServiceDowntimeForm.php | 3 + .../Object/SendCustomNotificationForm.php | 3 + .../Object/ToggleObjectFeaturesForm.php | 2 +- application/forms/Navigation/ActionForm.php | 3 - application/forms/RedisConfigForm.php | 6 +- .../Authentication/ObjectAuthorization.php | 8 +-- library/Icingadb/Command/IcingaApiCommand.php | 26 ++++++-- library/Icingadb/Command/IcingaCommand.php | 2 +- .../Instance/ToggleInstanceFeatureCommand.php | 16 +++-- .../Object/AcknowledgeProblemCommand.php | 24 +++---- .../Command/Object/AddCommentCommand.php | 6 +- .../Icingadb/Command/Object/CommandAuthor.php | 12 +++- .../Command/Object/DeleteCommentCommand.php | 10 ++- .../Command/Object/DeleteDowntimeCommand.php | 10 ++- .../Command/Object/GetObjectCommand.php | 8 +-- .../Icingadb/Command/Object/ObjectCommand.php | 10 ++- .../Object/ProcessCheckResultCommand.php | 24 ++++--- .../Object/PropagateHostDowntimeCommand.php | 6 +- .../Command/Object/ScheduleCheckCommand.php | 18 ++++-- .../Object/ScheduleHostDowntimeCommand.php | 6 +- .../Object/ScheduleServiceDowntimeCommand.php | 40 ++++++++---- .../Object/SendCustomNotificationCommand.php | 4 +- .../Object/ToggleObjectFeatureCommand.php | 18 ++++-- .../Command/Object/WithCommentCommand.php | 12 +++- .../Renderer/IcingaApiCommandRenderer.php | 32 +++++----- .../Command/Transport/ApiCommandTransport.php | 53 +++++++++++---- .../Command/Transport/CommandTransport.php | 8 ++- .../Transport/CommandTransportInterface.php | 2 +- library/Icingadb/Common/Auth.php | 15 +++-- library/Icingadb/Common/BaseFilter.php | 6 +- library/Icingadb/Common/BaseItemList.php | 4 +- library/Icingadb/Common/BaseListItem.php | 16 +++-- .../Icingadb/Common/BaseOrderedListItem.php | 10 ++- library/Icingadb/Common/BaseStatusBar.php | 4 +- library/Icingadb/Common/BaseTableRowItem.php | 9 ++- library/Icingadb/Common/CaptionDisabled.php | 4 +- library/Icingadb/Common/CommandActions.php | 8 ++- library/Icingadb/Common/Database.php | 2 +- library/Icingadb/Common/DetailActions.php | 14 ++-- library/Icingadb/Common/HostLink.php | 3 +- library/Icingadb/Common/HostLinks.php | 26 ++++---- library/Icingadb/Common/HostStates.php | 6 +- library/Icingadb/Common/IcingaRedis.php | 29 ++++++++- library/Icingadb/Common/Links.php | 50 +++++++-------- library/Icingadb/Common/LoadMore.php | 8 +-- library/Icingadb/Common/NoSubjectLink.php | 4 +- .../Common/ObjectInspectionDetail.php | 33 +++++++--- .../Icingadb/Common/ObjectLinkDisabled.php | 4 +- library/Icingadb/Common/ServiceLink.php | 3 +- library/Icingadb/Common/ServiceLinks.php | 24 +++---- library/Icingadb/Common/ServiceStates.php | 6 +- library/Icingadb/Common/StateBadges.php | 30 ++++++--- library/Icingadb/Common/ViewMode.php | 4 +- library/Icingadb/Compat/CompatObject.php | 15 +++-- library/Icingadb/Compat/CompatService.php | 2 +- library/Icingadb/Compat/UrlMigrator.php | 55 ++++++++++------ library/Icingadb/Data/PivotTable.php | 44 ++++++++----- library/Icingadb/Hook/TabHook/HookActions.php | 6 +- library/Icingadb/Model/Behavior/ReRoute.php | 2 +- library/Icingadb/Model/CustomvarFlat.php | 2 +- library/Icingadb/Model/HostState.php | 4 +- library/Icingadb/Model/ServiceState.php | 4 +- .../Icingadb/ProvidedHook/IcingaHealth.php | 6 +- library/Icingadb/ProvidedHook/RedisHealth.php | 2 +- library/Icingadb/ProvidedHook/X509/Sni.php | 3 +- library/Icingadb/Redis/VolatileState.php | 2 +- library/Icingadb/Setup/ApiTransportPage.php | 2 +- library/Icingadb/Setup/DbResourcePage.php | 2 +- library/Icingadb/Util/FeatureStatus.php | 4 +- library/Icingadb/Util/PerfData.php | 64 +++++++++---------- library/Icingadb/Util/PerfDataFormat.php | 26 ++++---- library/Icingadb/Util/PerfDataSet.php | 12 ++-- library/Icingadb/Util/PluginOutput.php | 2 +- library/Icingadb/Util/ThresholdRange.php | 12 ++-- .../Icingadb/Web/Control/ProblemToggle.php | 4 +- .../Control/SearchBar/ObjectSuggestions.php | 17 +++-- .../Icingadb/Web/Control/ViewModeSwitcher.php | 12 ++-- library/Icingadb/Web/Controller.php | 27 ++++---- library/Icingadb/Web/Navigation/Action.php | 2 +- .../Navigation/Renderer/HostProblemsBadge.php | 3 +- .../Web/Navigation/Renderer/ProblemsBadge.php | 22 +++++-- .../Renderer/ServiceProblemsBadge.php | 3 +- library/Icingadb/Widget/AttemptBall.php | 2 +- library/Icingadb/Widget/CheckAttempt.php | 2 +- .../Icingadb/Widget/Detail/CommentDetail.php | 7 +- .../Icingadb/Widget/Detail/DowntimeDetail.php | 4 +- library/Icingadb/Widget/Detail/HostDetail.php | 5 +- .../Icingadb/Widget/Detail/HostStatistics.php | 7 +- .../Widget/Detail/MultiselectQuickActions.php | 4 +- .../Icingadb/Widget/Detail/ObjectDetail.php | 22 +++---- .../Widget/Detail/ObjectStatistics.php | 7 +- .../Icingadb/Widget/Detail/ObjectsDetail.php | 25 ++++++-- .../Icingadb/Widget/Detail/PerfDataTable.php | 4 +- .../Icingadb/Widget/Detail/QuickActions.php | 2 +- .../Widget/Detail/ServiceStatistics.php | 7 +- library/Icingadb/Widget/Detail/UserDetail.php | 14 ++-- .../Widget/Detail/UsergroupDetail.php | 6 +- library/Icingadb/Widget/HostStateBadges.php | 7 +- library/Icingadb/Widget/HostStatusBar.php | 2 +- .../Widget/ItemList/BaseDowntimeListItem.php | 2 +- .../Widget/ItemList/BaseHistoryListItem.php | 2 +- .../Widget/ItemList/BaseHostListItem.php | 6 ++ .../ItemList/BaseNotificationListItem.php | 2 +- .../Widget/ItemList/CommandTransportList.php | 2 +- .../Icingadb/Widget/ItemList/CommentList.php | 2 +- .../Icingadb/Widget/ItemList/DowntimeList.php | 2 +- .../Icingadb/Widget/ItemList/HistoryList.php | 2 +- .../Widget/ItemList/HistoryListItem.php | 2 +- .../ItemList/HistoryListItemDetailed.php | 2 +- .../ItemList/HistoryListItemMinimal.php | 2 +- .../Widget/ItemList/HostDetailHeader.php | 2 +- library/Icingadb/Widget/ItemList/HostList.php | 2 +- .../Icingadb/Widget/ItemList/HostListItem.php | 2 +- .../Widget/ItemList/HostListItemDetailed.php | 2 +- .../Widget/ItemList/HostListItemMinimal.php | 2 +- .../Widget/ItemList/HostgroupList.php | 2 +- .../Widget/ItemList/NotificationList.php | 2 +- .../Widget/ItemList/NotificationListItem.php | 2 +- .../ItemList/NotificationListItemDetailed.php | 2 +- .../ItemList/NotificationListItemMinimal.php | 2 +- .../Widget/ItemList/PageSeparatorItem.php | 2 +- .../Widget/ItemList/ServiceDetailHeader.php | 2 +- .../Icingadb/Widget/ItemList/ServiceList.php | 2 +- .../Widget/ItemList/ServiceListItem.php | 2 +- .../ItemList/ServiceListItemDetailed.php | 2 +- .../ItemList/ServiceListItemMinimal.php | 2 +- .../Widget/ItemList/ServicegroupList.php | 2 +- .../Widget/ItemList/StateListItem.php | 2 +- library/Icingadb/Widget/ItemList/UserList.php | 2 +- .../Widget/ItemList/UsergroupList.php | 2 +- library/Icingadb/Widget/MarkdownLine.php | 2 +- library/Icingadb/Widget/MarkdownText.php | 2 +- .../Icingadb/Widget/ServiceStateBadges.php | 7 +- library/Icingadb/Widget/ServiceStatusBar.php | 2 +- library/Icingadb/Widget/ShowMore.php | 8 +-- library/Icingadb/Widget/StateBadge.php | 2 +- library/Icingadb/Widget/StateChange.php | 2 +- library/Icingadb/Widget/TagList.php | 4 +- 156 files changed, 821 insertions(+), 520 deletions(-) diff --git a/application/controllers/CommentController.php b/application/controllers/CommentController.php index 7c49a4ed..16ae5c6c 100644 --- a/application/controllers/CommentController.php +++ b/application/controllers/CommentController.php @@ -61,7 +61,7 @@ class CommentController extends Controller $this->setAutorefreshInterval(10); } - protected function fetchCommandTargets() + protected function fetchCommandTargets(): array { return [$this->comment]; } diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php index 9b6069da..0d64fbfe 100644 --- a/application/controllers/ConfigController.php +++ b/application/controllers/ConfigController.php @@ -51,7 +51,7 @@ class ConfigController extends Controller $this->addContent(new HtmlString($form->render())); } - protected function mergeTabs(Tabs $tabs) + protected function mergeTabs(Tabs $tabs): self { /** @var Tab $tab */ foreach ($tabs->getTabs() as $tab) { diff --git a/application/controllers/DowntimeController.php b/application/controllers/DowntimeController.php index e6fc2607..c9b69cf2 100644 --- a/application/controllers/DowntimeController.php +++ b/application/controllers/DowntimeController.php @@ -72,7 +72,7 @@ class DowntimeController extends Controller $this->setAutorefreshInterval(10); } - protected function fetchCommandTargets() + protected function fetchCommandTargets(): array { return [$this->downtime]; } diff --git a/application/controllers/HostController.php b/application/controllers/HostController.php index e3eedc16..535a98b6 100644 --- a/application/controllers/HostController.php +++ b/application/controllers/HostController.php @@ -25,6 +25,7 @@ use Icinga\Module\Icingadb\Widget\ItemList\HostList; use Icinga\Module\Icingadb\Widget\ItemList\HistoryList; use Icinga\Module\Icingadb\Widget\ItemList\ServiceList; use ipl\Web\Url; +use ipl\Web\Widget\Tabs; class HostController extends Controller { @@ -230,7 +231,7 @@ class HostController extends Controller $this->setAutorefreshInterval(10); } - protected function createTabs() + protected function createTabs(): Tabs { $tabs = $this->getTabs() ->add('index', [ @@ -260,7 +261,7 @@ class HostController extends Controller return $tabs; } - protected function setTitleTab($name) + protected function setTitleTab(string $name) { $tab = $this->createTabs()->get($name); @@ -271,7 +272,7 @@ class HostController extends Controller } } - protected function fetchCommandTargets() + protected function fetchCommandTargets(): array { return [$this->host]; } @@ -281,7 +282,7 @@ class HostController extends Controller return Links::host($this->host); } - protected function getDefaultTabControls() + protected function getDefaultTabControls(): array { return [(new HostList([$this->host]))->setDetailActionsDisabled()->setNoSubjectLink()]; } diff --git a/application/controllers/HostsController.php b/application/controllers/HostsController.php index 512d33cc..a7fdd6ca 100644 --- a/application/controllers/HostsController.php +++ b/application/controllers/HostsController.php @@ -19,6 +19,7 @@ use Icinga\Module\Icingadb\Widget\ItemList\HostList; use Icinga\Module\Icingadb\Widget\HostStatusBar; use Icinga\Module\Icingadb\Widget\ShowMore; use Icinga\Module\Icingadb\Web\Control\ViewModeSwitcher; +use ipl\Orm\Query; use ipl\Stdlib\Filter; use ipl\Web\Control\LimitControl; use ipl\Web\Control\SortControl; @@ -192,7 +193,7 @@ class HostsController extends Controller $this->setTitle(t('Adjust Filter')); } - protected function fetchCommandTargets() + protected function fetchCommandTargets(): Query { $db = $this->getDb(); diff --git a/application/controllers/ServiceController.php b/application/controllers/ServiceController.php index be6de10b..e681bf48 100644 --- a/application/controllers/ServiceController.php +++ b/application/controllers/ServiceController.php @@ -206,7 +206,7 @@ class ServiceController extends Controller return $tabs; } - protected function setTitleTab($name) + protected function setTitleTab(string $name) { $tab = $this->createTabs()->get($name); @@ -217,7 +217,7 @@ class ServiceController extends Controller } } - protected function fetchCommandTargets() + protected function fetchCommandTargets(): array { return [$this->service]; } @@ -227,7 +227,7 @@ class ServiceController extends Controller return Links::service($this->service, $this->service->host); } - protected function getDefaultTabControls() + protected function getDefaultTabControls(): array { return [(new ServiceList([$this->service]))->setDetailActionsDisabled()->setNoSubjectLink()]; } diff --git a/application/controllers/ServicesController.php b/application/controllers/ServicesController.php index cd0bda7b..228c6c76 100644 --- a/application/controllers/ServicesController.php +++ b/application/controllers/ServicesController.php @@ -22,6 +22,7 @@ use Icinga\Module\Icingadb\Widget\ServiceStatusBar; use Icinga\Module\Icingadb\Widget\ShowMore; use Icinga\Module\Icingadb\Web\Control\ViewModeSwitcher; use ipl\Html\HtmlString; +use ipl\Orm\Query; use ipl\Stdlib\Filter; use ipl\Web\Control\LimitControl; use ipl\Web\Control\SortControl; @@ -314,7 +315,7 @@ class ServicesController extends Controller $this->setAutorefreshInterval(30); } - protected function fetchCommandTargets() + protected function fetchCommandTargets(): Query { $db = $this->getDb(); @@ -351,7 +352,7 @@ class ServicesController extends Controller return new FeatureStatus('service', $summary->first()); } - public function createProblemToggle() + public function createProblemToggle(): ProblemToggle { $filter = $this->params->shift('problems'); diff --git a/application/forms/Command/CommandForm.php b/application/forms/Command/CommandForm.php index 4169493b..7fb79663 100644 --- a/application/forms/Command/CommandForm.php +++ b/application/forms/Command/CommandForm.php @@ -39,7 +39,7 @@ abstract class CommandForm extends Form * * @return $this */ - public function setObjects($objects) + public function setObjects($objects): self { $this->objects = $objects; diff --git a/application/forms/Command/Instance/ToggleInstanceFeaturesForm.php b/application/forms/Command/Instance/ToggleInstanceFeaturesForm.php index 55c9b5b0..eb270dab 100644 --- a/application/forms/Command/Instance/ToggleInstanceFeaturesForm.php +++ b/application/forms/Command/Instance/ToggleInstanceFeaturesForm.php @@ -26,7 +26,7 @@ class ToggleInstanceFeaturesForm extends CommandForm */ protected $submittedFeatures = []; - public function __construct($featureStatus) + public function __construct(array $featureStatus) { $this->featureStatus = $featureStatus; $this->features = [ @@ -136,7 +136,7 @@ class ToggleInstanceFeaturesForm extends CommandForm { } - protected function getCommand(Model $object) + protected function getCommand(Model $object): \Generator { foreach ($this->features as $feature => $spec) { $featureState = $this->getElement($feature)->isChecked(); @@ -147,7 +147,7 @@ class ToggleInstanceFeaturesForm extends CommandForm $command = new ToggleInstanceFeatureCommand(); $command->setFeature($feature); - $command->setEnabled((int) $featureState); + $command->setEnabled($featureState); $this->submittedFeatures[] = $command; diff --git a/application/forms/Command/Object/AcknowledgeProblemForm.php b/application/forms/Command/Object/AcknowledgeProblemForm.php index c5b9e21a..5ca70740 100644 --- a/application/forms/Command/Object/AcknowledgeProblemForm.php +++ b/application/forms/Command/Object/AcknowledgeProblemForm.php @@ -176,6 +176,9 @@ class AcknowledgeProblemForm extends CommandForm (new IcingaFormDecorator())->decorate($this->getElement('btn_submit')); } + /** + * @return ?AcknowledgeProblemCommand + */ protected function getCommand(Model $object) { if (! $this->isGrantedOn('icingadb/command/acknowledge-problem', $object)) { diff --git a/application/forms/Command/Object/AddCommentForm.php b/application/forms/Command/Object/AddCommentForm.php index 3d910342..af75f86e 100644 --- a/application/forms/Command/Object/AddCommentForm.php +++ b/application/forms/Command/Object/AddCommentForm.php @@ -130,6 +130,9 @@ class AddCommentForm extends CommandForm (new IcingaFormDecorator())->decorate($this->getElement('btn_submit')); } + /** + * @return ?AddCommentCommand + */ protected function getCommand(Model $object) { if (! $this->isGrantedOn('icingadb/command/comment/add', $object)) { diff --git a/application/forms/Command/Object/CheckNowForm.php b/application/forms/Command/Object/CheckNowForm.php index dbd76b1b..136b40ea 100644 --- a/application/forms/Command/Object/CheckNowForm.php +++ b/application/forms/Command/Object/CheckNowForm.php @@ -46,6 +46,9 @@ class CheckNowForm extends CommandForm ); } + /** + * @return ?ScheduleCheckCommand + */ protected function getCommand(Model $object) { if ( diff --git a/application/forms/Command/Object/DeleteCommentForm.php b/application/forms/Command/Object/DeleteCommentForm.php index 0abc9582..e4630a24 100644 --- a/application/forms/Command/Object/DeleteCommentForm.php +++ b/application/forms/Command/Object/DeleteCommentForm.php @@ -53,6 +53,9 @@ class DeleteCommentForm extends CommandForm ); } + /** + * @return ?DeleteCommentCommand + */ protected function getCommand(Model $object) { if (! $this->isGrantedOn('icingadb/command/comment/delete', $object->{$object->object_type})) { diff --git a/application/forms/Command/Object/DeleteDowntimeForm.php b/application/forms/Command/Object/DeleteDowntimeForm.php index 72c4d22f..c34c9a89 100644 --- a/application/forms/Command/Object/DeleteDowntimeForm.php +++ b/application/forms/Command/Object/DeleteDowntimeForm.php @@ -67,6 +67,9 @@ class DeleteDowntimeForm extends CommandForm ); } + /** + * @return ?DeleteDowntimeCommand + */ protected function getCommand(Model $object) { if ( diff --git a/application/forms/Command/Object/ProcessCheckResultForm.php b/application/forms/Command/Object/ProcessCheckResultForm.php index d9d6608d..e7e23e79 100644 --- a/application/forms/Command/Object/ProcessCheckResultForm.php +++ b/application/forms/Command/Object/ProcessCheckResultForm.php @@ -136,6 +136,9 @@ class ProcessCheckResultForm extends CommandForm (new IcingaFormDecorator())->decorate($this->getElement('btn_submit')); } + /** + * @return ?ProcessCheckResultCommand + */ protected function getCommand(Model $object) { if ( diff --git a/application/forms/Command/Object/RemoveAcknowledgementForm.php b/application/forms/Command/Object/RemoveAcknowledgementForm.php index 16488b4c..a69706a7 100644 --- a/application/forms/Command/Object/RemoveAcknowledgementForm.php +++ b/application/forms/Command/Object/RemoveAcknowledgementForm.php @@ -63,6 +63,9 @@ class RemoveAcknowledgementForm extends CommandForm ); } + /** + * @return ?RemoveAcknowledgementCommand + */ protected function getCommand(Model $object) { if (! $this->isGrantedOn('icingadb/command/remove-acknowledgement', $object)) { diff --git a/application/forms/Command/Object/ScheduleCheckForm.php b/application/forms/Command/Object/ScheduleCheckForm.php index 4354ef9a..853516f2 100644 --- a/application/forms/Command/Object/ScheduleCheckForm.php +++ b/application/forms/Command/Object/ScheduleCheckForm.php @@ -109,6 +109,9 @@ class ScheduleCheckForm extends CommandForm (new IcingaFormDecorator())->decorate($this->getElement('btn_submit')); } + /** + * @return ?ScheduleCheckCommand + */ protected function getCommand(Model $object) { if ( diff --git a/application/forms/Command/Object/ScheduleHostDowntimeForm.php b/application/forms/Command/Object/ScheduleHostDowntimeForm.php index 7ab1176f..081316b8 100644 --- a/application/forms/Command/Object/ScheduleHostDowntimeForm.php +++ b/application/forms/Command/Object/ScheduleHostDowntimeForm.php @@ -87,6 +87,9 @@ class ScheduleHostDowntimeForm extends ScheduleServiceDowntimeForm $decorator->decorate($this->getElement('child_options')); } + /** + * @return ?PropagateHostDowntimeCommand|ScheduleHostDowntimeCommand + */ protected function getCommand(Model $object) { if (! $this->isGrantedOn('icingadb/command/downtime/schedule', $object)) { diff --git a/application/forms/Command/Object/ScheduleServiceDowntimeForm.php b/application/forms/Command/Object/ScheduleServiceDowntimeForm.php index 67e161bf..05453e24 100644 --- a/application/forms/Command/Object/ScheduleServiceDowntimeForm.php +++ b/application/forms/Command/Object/ScheduleServiceDowntimeForm.php @@ -227,6 +227,9 @@ class ScheduleServiceDowntimeForm extends CommandForm (new IcingaFormDecorator())->decorate($this->getElement('btn_submit')); } + /** + * @return ?ScheduleServiceDowntimeCommand + */ protected function getCommand(Model $object) { if (! $this->isGrantedOn('icingadb/command/downtime/schedule', $object)) { diff --git a/application/forms/Command/Object/SendCustomNotificationForm.php b/application/forms/Command/Object/SendCustomNotificationForm.php index 052f80a3..9813def1 100644 --- a/application/forms/Command/Object/SendCustomNotificationForm.php +++ b/application/forms/Command/Object/SendCustomNotificationForm.php @@ -109,6 +109,9 @@ class SendCustomNotificationForm extends CommandForm (new IcingaFormDecorator())->decorate($this->getElement('btn_submit')); } + /** + * @return ?SendCustomNotificationCommand + */ protected function getCommand(Model $object) { if (! $this->isGrantedOn('icingadb/command/send-custom-notification', $object)) { diff --git a/application/forms/Command/Object/ToggleObjectFeaturesForm.php b/application/forms/Command/Object/ToggleObjectFeaturesForm.php index e60234a3..faaeeaf4 100644 --- a/application/forms/Command/Object/ToggleObjectFeaturesForm.php +++ b/application/forms/Command/Object/ToggleObjectFeaturesForm.php @@ -148,7 +148,7 @@ class ToggleObjectFeaturesForm extends CommandForm { } - protected function getCommand(Model $object) + protected function getCommand(Model $object): \Generator { foreach ($this->features as $feature => $spec) { $featureState = $this->getElement($feature)->isChecked(); diff --git a/application/forms/Navigation/ActionForm.php b/application/forms/Navigation/ActionForm.php index 86a6d082..08cba3f8 100644 --- a/application/forms/Navigation/ActionForm.php +++ b/application/forms/Navigation/ActionForm.php @@ -19,9 +19,6 @@ class ActionForm extends NavigationItemForm */ protected $restriction; - /** - * {@inheritdoc} - */ public function createElements(array $formData) { parent::createElements($formData); diff --git a/application/forms/RedisConfigForm.php b/application/forms/RedisConfigForm.php index 1786c03d..ec217956 100644 --- a/application/forms/RedisConfigForm.php +++ b/application/forms/RedisConfigForm.php @@ -194,7 +194,7 @@ class RedisConfigForm extends ConfigForm ); } - public static function addSkipValidationCheckbox($form) + public static function addSkipValidationCheckbox(Form $form) { $form->addElement( 'checkbox', @@ -435,7 +435,7 @@ class RedisConfigForm extends ConfigForm return $this; } - public static function checkRedis(Form $form) + public static function checkRedis(Form $form): bool { $sections = []; @@ -520,7 +520,7 @@ class RedisConfigForm extends ConfigForm * * @return array Callback validator */ - private function wrapIplValidator($cls, $element, Closure $additionalValidator = null) + private function wrapIplValidator(string $cls, string $element, Closure $additionalValidator = null): array { return [ 'Callback', diff --git a/library/Icingadb/Authentication/ObjectAuthorization.php b/library/Icingadb/Authentication/ObjectAuthorization.php index e2b14cf5..5cbbd672 100644 --- a/library/Icingadb/Authentication/ObjectAuthorization.php +++ b/library/Icingadb/Authentication/ObjectAuthorization.php @@ -38,7 +38,7 @@ class ObjectAuthorization * * @return bool */ - public static function grantsOn($permission, Model $for) + public static function grantsOn(string $permission, Model $for): bool { $self = new static(); @@ -72,7 +72,7 @@ class ObjectAuthorization * * @return bool */ - public static function grantsOnType($permission, $type, Filter\Rule $filter, $cache = true) + public static function grantsOnType(string $permission, string $type, Filter\Rule $filter, bool $cache = true): bool { switch ($type) { case 'host': @@ -142,7 +142,7 @@ class ObjectAuthorization * * @return void */ - protected function loadGrants($model, Filter\Rule $filter, $cacheKey, $cache = true) + protected function loadGrants(string $model, Filter\Rule $filter, string $cacheKey, bool $cache = true) { /** @var Model $model */ $query = $model::on($this->getDb()); @@ -234,7 +234,7 @@ class ObjectAuthorization * * @return bool */ - protected function checkGrants($permission, $roles) + protected function checkGrants(string $permission, array $roles): bool { if (empty($roles)) { return false; diff --git a/library/Icingadb/Command/IcingaApiCommand.php b/library/Icingadb/Command/IcingaApiCommand.php index abfba29f..f3f0c335 100644 --- a/library/Icingadb/Command/IcingaApiCommand.php +++ b/library/Icingadb/Command/IcingaApiCommand.php @@ -35,7 +35,7 @@ class IcingaApiCommand * * @return static */ - public static function create($endpoint, array $data) + public static function create(string $endpoint, array $data): self { return (new static()) ->setEndpoint($endpoint) @@ -47,8 +47,14 @@ class IcingaApiCommand * * @return array */ - public function getData() + public function getData(): array { + if ($this->data === null) { + throw new \LogicException( + 'You are accessing an unset property. Please make sure to set it beforehand.' + ); + } + return $this->data; } @@ -59,7 +65,7 @@ class IcingaApiCommand * * @return $this */ - public function setData($data) + public function setData(array $data): self { $this->data = $data; @@ -71,8 +77,14 @@ class IcingaApiCommand * * @return string */ - public function getEndpoint() + public function getEndpoint(): string { + if ($this->endpoint === null) { + throw new \LogicException( + 'You are accessing an unset property. Please make sure to set it beforehand.' + ); + } + return $this->endpoint; } @@ -83,7 +95,7 @@ class IcingaApiCommand * * @return $this */ - public function setEndpoint($endpoint) + public function setEndpoint(string $endpoint): self { $this->endpoint = $endpoint; @@ -95,7 +107,7 @@ class IcingaApiCommand * * @return string */ - public function getMethod() + public function getMethod(): string { return $this->method; } @@ -107,7 +119,7 @@ class IcingaApiCommand * * @return $this */ - public function setMethod($method) + public function setMethod(string $method): self { $this->method = $method; diff --git a/library/Icingadb/Command/IcingaCommand.php b/library/Icingadb/Command/IcingaCommand.php index 08a48729..7b5c5cff 100644 --- a/library/Icingadb/Command/IcingaCommand.php +++ b/library/Icingadb/Command/IcingaCommand.php @@ -14,7 +14,7 @@ abstract class IcingaCommand * * @return string */ - public function getName() + public function getName(): string { $nsParts = explode('\\', get_called_class()); return substr_replace(end($nsParts), '', -7); // Remove 'Command' Suffix diff --git a/library/Icingadb/Command/Instance/ToggleInstanceFeatureCommand.php b/library/Icingadb/Command/Instance/ToggleInstanceFeatureCommand.php index 581f1c9f..d275d9b3 100644 --- a/library/Icingadb/Command/Instance/ToggleInstanceFeatureCommand.php +++ b/library/Icingadb/Command/Instance/ToggleInstanceFeatureCommand.php @@ -62,9 +62,9 @@ class ToggleInstanceFeatureCommand extends IcingaCommand * * @return $this */ - public function setFeature($feature) + public function setFeature(string $feature): self { - $this->feature = (string) $feature; + $this->feature = $feature; return $this; } @@ -74,8 +74,12 @@ class ToggleInstanceFeatureCommand extends IcingaCommand * * @return string */ - public function getFeature() + public function getFeature(): string { + if ($this->feature === null) { + throw new \LogicException('You have to set the feature first before getting it.'); + } + return $this->feature; } @@ -86,9 +90,9 @@ class ToggleInstanceFeatureCommand extends IcingaCommand * * @return $this */ - public function setEnabled($enabled = true) + public function setEnabled(bool $enabled = true): self { - $this->enabled = (bool) $enabled; + $this->enabled = $enabled; return $this; } @@ -96,7 +100,7 @@ class ToggleInstanceFeatureCommand extends IcingaCommand /** * Get whether the feature should be enabled or disabled * - * @return bool + * @return ?bool */ public function getEnabled() { diff --git a/library/Icingadb/Command/Object/AcknowledgeProblemCommand.php b/library/Icingadb/Command/Object/AcknowledgeProblemCommand.php index aaff0394..baae24c7 100644 --- a/library/Icingadb/Command/Object/AcknowledgeProblemCommand.php +++ b/library/Icingadb/Command/Object/AcknowledgeProblemCommand.php @@ -49,9 +49,9 @@ class AcknowledgeProblemCommand extends WithCommentCommand * * @return $this */ - public function setSticky($sticky = true) + public function setSticky(bool $sticky = true): self { - $this->sticky = (bool) $sticky; + $this->sticky = $sticky; return $this; } @@ -61,7 +61,7 @@ class AcknowledgeProblemCommand extends WithCommentCommand * * @return bool */ - public function getSticky() + public function getSticky(): bool { return $this->sticky; } @@ -73,9 +73,9 @@ class AcknowledgeProblemCommand extends WithCommentCommand * * @return $this */ - public function setNotify($notify = true) + public function setNotify(bool $notify = true): self { - $this->notify = (bool) $notify; + $this->notify = $notify; return $this; } @@ -85,7 +85,7 @@ class AcknowledgeProblemCommand extends WithCommentCommand * * @return bool */ - public function getNotify() + public function getNotify(): bool { return $this->notify; } @@ -97,9 +97,9 @@ class AcknowledgeProblemCommand extends WithCommentCommand * * @return $this */ - public function setPersistent($persistent = true) + public function setPersistent(bool $persistent = true): self { - $this->persistent = (bool) $persistent; + $this->persistent = $persistent; return $this; } @@ -109,7 +109,7 @@ class AcknowledgeProblemCommand extends WithCommentCommand * * @return bool */ - public function getPersistent() + public function getPersistent(): bool { return $this->persistent; } @@ -121,9 +121,9 @@ class AcknowledgeProblemCommand extends WithCommentCommand * * @return $this */ - public function setExpireTime($expireTime) + public function setExpireTime(int $expireTime): self { - $this->expireTime = (int) $expireTime; + $this->expireTime = $expireTime; return $this; } @@ -131,7 +131,7 @@ class AcknowledgeProblemCommand extends WithCommentCommand /** * Get the time when the acknowledgement should expire * - * @return int + * @return ?int */ public function getExpireTime() { diff --git a/library/Icingadb/Command/Object/AddCommentCommand.php b/library/Icingadb/Command/Object/AddCommentCommand.php index d8171337..c853b257 100644 --- a/library/Icingadb/Command/Object/AddCommentCommand.php +++ b/library/Icingadb/Command/Object/AddCommentCommand.php @@ -23,9 +23,9 @@ class AddCommentCommand extends WithCommentCommand * * @return $this */ - public function setExpireTime($expireTime) + public function setExpireTime(int $expireTime): self { - $this->expireTime = (int) $expireTime; + $this->expireTime = $expireTime; return $this; } @@ -33,7 +33,7 @@ class AddCommentCommand extends WithCommentCommand /** * Get the time when the acknowledgement should expire * - * @return int + * @return ?int */ public function getExpireTime() { diff --git a/library/Icingadb/Command/Object/CommandAuthor.php b/library/Icingadb/Command/Object/CommandAuthor.php index fc8596ec..f323b633 100644 --- a/library/Icingadb/Command/Object/CommandAuthor.php +++ b/library/Icingadb/Command/Object/CommandAuthor.php @@ -20,9 +20,9 @@ trait CommandAuthor * * @return $this */ - public function setAuthor($author) + public function setAuthor(string $author): self { - $this->author = (string) $author; + $this->author = $author; return $this; } @@ -32,8 +32,14 @@ trait CommandAuthor * * @return string */ - public function getAuthor() + public function getAuthor(): string { + if ($this->author === null) { + throw new \LogicException( + 'You are accessing an unset property. Please make sure to set it beforehand.' + ); + } + return $this->author; } } diff --git a/library/Icingadb/Command/Object/DeleteCommentCommand.php b/library/Icingadb/Command/Object/DeleteCommentCommand.php index c30802e3..8bfc2a37 100644 --- a/library/Icingadb/Command/Object/DeleteCommentCommand.php +++ b/library/Icingadb/Command/Object/DeleteCommentCommand.php @@ -25,8 +25,14 @@ class DeleteCommentCommand extends IcingaCommand * * @return string */ - public function getCommentName() + public function getCommentName(): string { + if ($this->commentName === null) { + throw new \LogicException( + 'You are accessing an unset property. Please make sure to set it beforehand.' + ); + } + return $this->commentName; } @@ -37,7 +43,7 @@ class DeleteCommentCommand extends IcingaCommand * * @return $this */ - public function setCommentName($commentName) + public function setCommentName(string $commentName): self { $this->commentName = $commentName; diff --git a/library/Icingadb/Command/Object/DeleteDowntimeCommand.php b/library/Icingadb/Command/Object/DeleteDowntimeCommand.php index 6cb1b8d3..a0867fa9 100644 --- a/library/Icingadb/Command/Object/DeleteDowntimeCommand.php +++ b/library/Icingadb/Command/Object/DeleteDowntimeCommand.php @@ -29,8 +29,14 @@ class DeleteDowntimeCommand extends IcingaCommand * * @return string */ - public function getDowntimeName() + public function getDowntimeName(): string { + if ($this->downtimeName === null) { + throw new \LogicException( + 'You are accessing an unset property. Please make sure to set it beforehand.' + ); + } + return $this->downtimeName; } @@ -43,7 +49,7 @@ class DeleteDowntimeCommand extends IcingaCommand * * @return $this */ - public function setDowntimeName($downtimeName) + public function setDowntimeName(string $downtimeName): self { $this->downtimeName = $downtimeName; diff --git a/library/Icingadb/Command/Object/GetObjectCommand.php b/library/Icingadb/Command/Object/GetObjectCommand.php index a9a2fe87..372a555b 100644 --- a/library/Icingadb/Command/Object/GetObjectCommand.php +++ b/library/Icingadb/Command/Object/GetObjectCommand.php @@ -18,7 +18,7 @@ class GetObjectCommand extends ObjectCommand * * @return string */ - public function getObjectName() + public function getObjectName(): string { switch (true) { case $this->object instanceof Service: @@ -33,7 +33,7 @@ class GetObjectCommand extends ObjectCommand * * @return string */ - public function getObjectPluralType() + public function getObjectPluralType(): string { switch (true) { case $this->object instanceof Host: @@ -48,7 +48,7 @@ class GetObjectCommand extends ObjectCommand /** * Get the attributes to query * - * @return array + * @return ?array */ public function getAttributes() { @@ -62,7 +62,7 @@ class GetObjectCommand extends ObjectCommand * * @return $this */ - public function setAttributes(array $attributes) + public function setAttributes(array $attributes): self { $this->attributes = $attributes; diff --git a/library/Icingadb/Command/Object/ObjectCommand.php b/library/Icingadb/Command/Object/ObjectCommand.php index dd252480..7dae7997 100644 --- a/library/Icingadb/Command/Object/ObjectCommand.php +++ b/library/Icingadb/Command/Object/ObjectCommand.php @@ -26,7 +26,7 @@ abstract class ObjectCommand extends IcingaCommand * * @return $this */ - public function setObject(Model $object) + public function setObject(Model $object): self { $this->object = $object; @@ -38,8 +38,14 @@ abstract class ObjectCommand extends IcingaCommand * * @return Model */ - public function getObject() + public function getObject(): Model { + if ($this->object === null) { + throw new \LogicException( + 'You are accessing an unset property. Please make sure to set it beforehand.' + ); + } + return $this->object; } } diff --git a/library/Icingadb/Command/Object/ProcessCheckResultCommand.php b/library/Icingadb/Command/Object/ProcessCheckResultCommand.php index 532b77be..24eb5dd0 100644 --- a/library/Icingadb/Command/Object/ProcessCheckResultCommand.php +++ b/library/Icingadb/Command/Object/ProcessCheckResultCommand.php @@ -67,9 +67,9 @@ class ProcessCheckResultCommand extends ObjectCommand * * @return $this */ - public function setStatus($status) + public function setStatus(int $status): self { - $this->status = (int) $status; + $this->status = $status; return $this; } @@ -79,8 +79,14 @@ class ProcessCheckResultCommand extends ObjectCommand * * @return int */ - public function getStatus() + public function getStatus(): int { + if ($this->status === null) { + throw new \LogicException( + 'You are accessing an unset property. Please make sure to set it beforehand.' + ); + } + return $this->status; } @@ -91,9 +97,9 @@ class ProcessCheckResultCommand extends ObjectCommand * * @return $this */ - public function setOutput($output) + public function setOutput(string $output): self { - $this->output = (string) $output; + $this->output = $output; return $this; } @@ -101,7 +107,7 @@ class ProcessCheckResultCommand extends ObjectCommand /** * Get the text output of the host or service check result * - * @return string + * @return ?string */ public function getOutput() { @@ -115,9 +121,9 @@ class ProcessCheckResultCommand extends ObjectCommand * * @return $this */ - public function setPerformanceData($performanceData) + public function setPerformanceData(string $performanceData): self { - $this->performanceData = (string) $performanceData; + $this->performanceData = $performanceData; return $this; } @@ -125,7 +131,7 @@ class ProcessCheckResultCommand extends ObjectCommand /** * Get the performance data of the host or service check result * - * @return string + * @return ?string */ public function getPerformanceData() { diff --git a/library/Icingadb/Command/Object/PropagateHostDowntimeCommand.php b/library/Icingadb/Command/Object/PropagateHostDowntimeCommand.php index 0b009760..88964fba 100644 --- a/library/Icingadb/Command/Object/PropagateHostDowntimeCommand.php +++ b/library/Icingadb/Command/Object/PropagateHostDowntimeCommand.php @@ -23,9 +23,9 @@ class PropagateHostDowntimeCommand extends ScheduleHostDowntimeCommand * * @return $this */ - public function setTriggered($triggered = true) + public function setTriggered(bool $triggered = true): self { - $this->triggered = (bool) $triggered; + $this->triggered = $triggered; return $this; } @@ -35,7 +35,7 @@ class PropagateHostDowntimeCommand extends ScheduleHostDowntimeCommand * * @return bool */ - public function getTriggered() + public function getTriggered(): bool { return $this->triggered; } diff --git a/library/Icingadb/Command/Object/ScheduleCheckCommand.php b/library/Icingadb/Command/Object/ScheduleCheckCommand.php index fafc9683..c3f20973 100644 --- a/library/Icingadb/Command/Object/ScheduleCheckCommand.php +++ b/library/Icingadb/Command/Object/ScheduleCheckCommand.php @@ -37,9 +37,9 @@ class ScheduleCheckCommand extends ObjectCommand * * @return $this */ - public function setCheckTime($checkTime) + public function setCheckTime(int $checkTime): self { - $this->checkTime = (int) $checkTime; + $this->checkTime = $checkTime; return $this; } @@ -49,8 +49,14 @@ class ScheduleCheckCommand extends ObjectCommand * * @return int Unix timestamp */ - public function getCheckTime() + public function getCheckTime(): int { + if ($this->checkTime === null) { + throw new \LogicException( + 'You are accessing an unset property. Please make sure to set it beforehand.' + ); + } + return $this->checkTime; } @@ -61,9 +67,9 @@ class ScheduleCheckCommand extends ObjectCommand * * @return $this */ - public function setForced($forced = true) + public function setForced(bool $forced = true): self { - $this->forced = (bool) $forced; + $this->forced = $forced; return $this; } @@ -73,7 +79,7 @@ class ScheduleCheckCommand extends ObjectCommand * * @return bool */ - public function getForced() + public function getForced(): bool { return $this->forced; } diff --git a/library/Icingadb/Command/Object/ScheduleHostDowntimeCommand.php b/library/Icingadb/Command/Object/ScheduleHostDowntimeCommand.php index d6aafa56..0e4d84fa 100644 --- a/library/Icingadb/Command/Object/ScheduleHostDowntimeCommand.php +++ b/library/Icingadb/Command/Object/ScheduleHostDowntimeCommand.php @@ -23,9 +23,9 @@ class ScheduleHostDowntimeCommand extends ScheduleServiceDowntimeCommand * * @return $this */ - public function setForAllServices($forAllServices = true) + public function setForAllServices(bool $forAllServices = true): self { - $this->forAllServices = (bool) $forAllServices; + $this->forAllServices = $forAllServices; return $this; } @@ -35,7 +35,7 @@ class ScheduleHostDowntimeCommand extends ScheduleServiceDowntimeCommand * * @return bool */ - public function getForAllServices() + public function getForAllServices(): bool { return $this->forAllServices; } diff --git a/library/Icingadb/Command/Object/ScheduleServiceDowntimeCommand.php b/library/Icingadb/Command/Object/ScheduleServiceDowntimeCommand.php index 51d0a655..3bad28ef 100644 --- a/library/Icingadb/Command/Object/ScheduleServiceDowntimeCommand.php +++ b/library/Icingadb/Command/Object/ScheduleServiceDowntimeCommand.php @@ -64,9 +64,9 @@ class ScheduleServiceDowntimeCommand extends AddCommentCommand * * @return $this */ - public function setStart($start) + public function setStart(int $start): self { - $this->start = (int) $start; + $this->start = $start; return $this; } @@ -76,8 +76,14 @@ class ScheduleServiceDowntimeCommand extends AddCommentCommand * * @return int Unix timestamp */ - public function getStart() + public function getStart(): int { + if ($this->start === null) { + throw new \LogicException( + 'You are accessing an unset property. Please make sure to set it beforehand.' + ); + } + return $this->start; } @@ -88,9 +94,9 @@ class ScheduleServiceDowntimeCommand extends AddCommentCommand * * @return $this */ - public function setEnd($end) + public function setEnd(int $end): self { - $this->end = (int) $end; + $this->end = $end; return $this; } @@ -100,8 +106,14 @@ class ScheduleServiceDowntimeCommand extends AddCommentCommand * * @return int Unix timestamp */ - public function getEnd() + public function getEnd(): int { + if ($this->start === null) { + throw new \LogicException( + 'You are accessing an unset property. Please make sure to set it beforehand.' + ); + } + return $this->end; } @@ -112,9 +124,9 @@ class ScheduleServiceDowntimeCommand extends AddCommentCommand * * @return $this */ - public function setFixed($fixed = true) + public function setFixed(bool $fixed = true): self { - $this->fixed = (bool) $fixed; + $this->fixed = $fixed; return $this; } @@ -124,7 +136,7 @@ class ScheduleServiceDowntimeCommand extends AddCommentCommand * * @return boolean */ - public function getFixed() + public function getFixed(): bool { return $this->fixed; } @@ -136,9 +148,9 @@ class ScheduleServiceDowntimeCommand extends AddCommentCommand * * @return $this */ - public function setTriggerId($triggerId) + public function setTriggerId(int $triggerId): self { - $this->triggerId = (int) $triggerId; + $this->triggerId = $triggerId; return $this; } @@ -160,9 +172,9 @@ class ScheduleServiceDowntimeCommand extends AddCommentCommand * * @return $this */ - public function setDuration($duration) + public function setDuration(int $duration): self { - $this->duration = (int) $duration; + $this->duration = $duration; return $this; } @@ -177,7 +189,7 @@ class ScheduleServiceDowntimeCommand extends AddCommentCommand return $this->duration; } - public function getName() + public function getName(): string { return 'ScheduleDowntime'; } diff --git a/library/Icingadb/Command/Object/SendCustomNotificationCommand.php b/library/Icingadb/Command/Object/SendCustomNotificationCommand.php index af225939..de90620f 100644 --- a/library/Icingadb/Command/Object/SendCustomNotificationCommand.php +++ b/library/Icingadb/Command/Object/SendCustomNotificationCommand.php @@ -21,7 +21,7 @@ class SendCustomNotificationCommand extends WithCommentCommand /** * Get whether to force the notification * - * @return bool + * @return ?bool */ public function getForced() { @@ -35,7 +35,7 @@ class SendCustomNotificationCommand extends WithCommentCommand * * @return $this */ - public function setForced($forced = true) + public function setForced(bool $forced = true): self { $this->forced = $forced; diff --git a/library/Icingadb/Command/Object/ToggleObjectFeatureCommand.php b/library/Icingadb/Command/Object/ToggleObjectFeatureCommand.php index e54dbdb5..699a1133 100644 --- a/library/Icingadb/Command/Object/ToggleObjectFeatureCommand.php +++ b/library/Icingadb/Command/Object/ToggleObjectFeatureCommand.php @@ -59,9 +59,9 @@ class ToggleObjectFeatureCommand extends ObjectCommand * * @return $this */ - public function setFeature($feature) + public function setFeature(string $feature): self { - $this->feature = (string) $feature; + $this->feature = $feature; return $this; } @@ -71,8 +71,14 @@ class ToggleObjectFeatureCommand extends ObjectCommand * * @return string */ - public function getFeature() + public function getFeature(): string { + if ($this->feature === null) { + throw new \LogicException( + 'You are accessing an unset property. Please make sure to set it beforehand.' + ); + } + return $this->feature; } @@ -83,9 +89,9 @@ class ToggleObjectFeatureCommand extends ObjectCommand * * @return $this */ - public function setEnabled($enabled = true) + public function setEnabled(bool $enabled = true): self { - $this->enabled = (bool) $enabled; + $this->enabled = $enabled; return $this; } @@ -93,7 +99,7 @@ class ToggleObjectFeatureCommand extends ObjectCommand /** * Get whether the feature should be enabled or disabled * - * @return bool + * @return ?bool */ public function getEnabled() { diff --git a/library/Icingadb/Command/Object/WithCommentCommand.php b/library/Icingadb/Command/Object/WithCommentCommand.php index fbc4a0dc..299c998f 100644 --- a/library/Icingadb/Command/Object/WithCommentCommand.php +++ b/library/Icingadb/Command/Object/WithCommentCommand.php @@ -25,9 +25,9 @@ abstract class WithCommentCommand extends ObjectCommand * * @return $this */ - public function setComment($comment) + public function setComment(string $comment): self { - $this->comment = (string) $comment; + $this->comment = $comment; return $this; } @@ -37,8 +37,14 @@ abstract class WithCommentCommand extends ObjectCommand * * @return string */ - public function getComment() + public function getComment(): string { + if ($this->comment === null) { + throw new \LogicException( + 'You are accessing an unset property. Please make sure to set it beforehand.' + ); + } + return $this->comment; } } diff --git a/library/Icingadb/Command/Renderer/IcingaApiCommandRenderer.php b/library/Icingadb/Command/Renderer/IcingaApiCommandRenderer.php index eedbf639..aa1cdbee 100644 --- a/library/Icingadb/Command/Renderer/IcingaApiCommandRenderer.php +++ b/library/Icingadb/Command/Renderer/IcingaApiCommandRenderer.php @@ -42,7 +42,7 @@ class IcingaApiCommandRenderer implements IcingaCommandRendererInterface * * @return string */ - public function getApp() + public function getApp(): string { return $this->app; } @@ -54,7 +54,7 @@ class IcingaApiCommandRenderer implements IcingaCommandRendererInterface * * @return $this */ - public function setApp($app) + public function setApp(string $app): self { $this->app = $app; @@ -67,7 +67,7 @@ class IcingaApiCommandRenderer implements IcingaCommandRendererInterface * @param array $data * @param Model $object * - * @return array + * @return void */ protected function applyFilter(array &$data, Model $object) { @@ -86,7 +86,7 @@ class IcingaApiCommandRenderer implements IcingaCommandRendererInterface * * @return IcingaApiCommand */ - public function render(IcingaCommand $command) + public function render(IcingaCommand $command): IcingaApiCommand { $renderMethod = 'render' . $command->getName(); if (! method_exists($this, $renderMethod)) { @@ -98,7 +98,7 @@ class IcingaApiCommandRenderer implements IcingaCommandRendererInterface return $this->$renderMethod($command); } - public function renderGetObject(GetObjectCommand $command) + public function renderGetObject(GetObjectCommand $command): IcingaApiCommand { $endpoint = sprintf( 'objects/%s/%s', @@ -114,7 +114,7 @@ class IcingaApiCommandRenderer implements IcingaCommandRendererInterface return IcingaApiCommand::create($endpoint, $data)->setMethod('GET'); } - public function renderAddComment(AddCommentCommand $command) + public function renderAddComment(AddCommentCommand $command): IcingaApiCommand { $endpoint = 'actions/add-comment'; $data = [ @@ -130,7 +130,7 @@ class IcingaApiCommandRenderer implements IcingaCommandRendererInterface return IcingaApiCommand::create($endpoint, $data); } - public function renderSendCustomNotification(SendCustomNotificationCommand $command) + public function renderSendCustomNotification(SendCustomNotificationCommand $command): IcingaApiCommand { $endpoint = 'actions/send-custom-notification'; $data = [ @@ -143,7 +143,7 @@ class IcingaApiCommandRenderer implements IcingaCommandRendererInterface return IcingaApiCommand::create($endpoint, $data); } - public function renderProcessCheckResult(ProcessCheckResultCommand $command) + public function renderProcessCheckResult(ProcessCheckResultCommand $command): IcingaApiCommand { $endpoint = 'actions/process-check-result'; $data = [ @@ -156,7 +156,7 @@ class IcingaApiCommandRenderer implements IcingaCommandRendererInterface return IcingaApiCommand::create($endpoint, $data); } - public function renderScheduleCheck(ScheduleCheckCommand $command) + public function renderScheduleCheck(ScheduleCheckCommand $command): IcingaApiCommand { $endpoint = 'actions/reschedule-check'; $data = [ @@ -168,7 +168,7 @@ class IcingaApiCommandRenderer implements IcingaCommandRendererInterface return IcingaApiCommand::create($endpoint, $data); } - public function renderScheduleDowntime(ScheduleServiceDowntimeCommand $command) + public function renderScheduleDowntime(ScheduleServiceDowntimeCommand $command): IcingaApiCommand { $endpoint = 'actions/schedule-downtime'; $data = [ @@ -193,7 +193,7 @@ class IcingaApiCommandRenderer implements IcingaCommandRendererInterface return IcingaApiCommand::create($endpoint, $data); } - public function renderAcknowledgeProblem(AcknowledgeProblemCommand $command) + public function renderAcknowledgeProblem(AcknowledgeProblemCommand $command): IcingaApiCommand { $endpoint = 'actions/acknowledge-problem'; $data = [ @@ -212,7 +212,7 @@ class IcingaApiCommandRenderer implements IcingaCommandRendererInterface return IcingaApiCommand::create($endpoint, $data); } - public function renderToggleObjectFeature(ToggleObjectFeatureCommand $command) + public function renderToggleObjectFeature(ToggleObjectFeatureCommand $command): IcingaApiCommand { switch ($command->getFeature()) { case ToggleObjectFeatureCommand::FEATURE_ACTIVE_CHECKS: @@ -253,7 +253,7 @@ class IcingaApiCommandRenderer implements IcingaCommandRendererInterface return IcingaApiCommand::create($endpoint, $data); } - public function renderDeleteComment(DeleteCommentCommand $command) + public function renderDeleteComment(DeleteCommentCommand $command): IcingaApiCommand { $endpoint = 'actions/remove-comment'; $data = [ @@ -264,7 +264,7 @@ class IcingaApiCommandRenderer implements IcingaCommandRendererInterface return IcingaApiCommand::create($endpoint, $data); } - public function renderDeleteDowntime(DeleteDowntimeCommand $command) + public function renderDeleteDowntime(DeleteDowntimeCommand $command): IcingaApiCommand { $endpoint = 'actions/remove-downtime'; $data = [ @@ -275,7 +275,7 @@ class IcingaApiCommandRenderer implements IcingaCommandRendererInterface return IcingaApiCommand::create($endpoint, $data); } - public function renderRemoveAcknowledgement(RemoveAcknowledgementCommand $command) + public function renderRemoveAcknowledgement(RemoveAcknowledgementCommand $command): IcingaApiCommand { $endpoint = 'actions/remove-acknowledgement'; $data = ['author' => $command->getAuthor()]; @@ -284,7 +284,7 @@ class IcingaApiCommandRenderer implements IcingaCommandRendererInterface return IcingaApiCommand::create($endpoint, $data); } - public function renderToggleInstanceFeature(ToggleInstanceFeatureCommand $command) + public function renderToggleInstanceFeature(ToggleInstanceFeatureCommand $command): IcingaApiCommand { $endpoint = 'objects/icingaapplications/' . $this->getApp(); diff --git a/library/Icingadb/Command/Transport/ApiCommandTransport.php b/library/Icingadb/Command/Transport/ApiCommandTransport.php index 52123a46..7838ad7b 100644 --- a/library/Icingadb/Command/Transport/ApiCommandTransport.php +++ b/library/Icingadb/Command/Transport/ApiCommandTransport.php @@ -74,7 +74,7 @@ class ApiCommandTransport implements CommandTransportInterface * * @return $this */ - public function setApp($app) + public function setApp(string $app): self { $this->renderer->setApp($app); @@ -86,8 +86,14 @@ class ApiCommandTransport implements CommandTransportInterface * * @return string */ - public function getHost() + public function getHost(): string { + if ($this->host === null) { + throw new \LogicException( + 'You are accessing an unset property. Please make sure to set it beforehand.' + ); + } + return $this->host; } @@ -98,7 +104,7 @@ class ApiCommandTransport implements CommandTransportInterface * * @return $this */ - public function setHost($host) + public function setHost(string $host): self { $this->host = $host; @@ -110,8 +116,14 @@ class ApiCommandTransport implements CommandTransportInterface * * @return string */ - public function getPassword() + public function getPassword(): string { + if ($this->password === null) { + throw new \LogicException( + 'You are accessing an unset property. Please make sure to set it beforehand.' + ); + } + return $this->password; } @@ -122,7 +134,7 @@ class ApiCommandTransport implements CommandTransportInterface * * @return $this */ - public function setPassword($password) + public function setPassword(string $password): self { $this->password = $password; @@ -134,7 +146,7 @@ class ApiCommandTransport implements CommandTransportInterface * * @return int */ - public function getPort() + public function getPort(): int { return $this->port; } @@ -146,9 +158,9 @@ class ApiCommandTransport implements CommandTransportInterface * * @return $this */ - public function setPort($port) + public function setPort(int $port): self { - $this->port = (int) $port; + $this->port = $port; return $this; } @@ -158,8 +170,14 @@ class ApiCommandTransport implements CommandTransportInterface * * @return string */ - public function getUsername() + public function getUsername(): string { + if ($this->username === null) { + throw new \LogicException( + 'You are accessing an unset property. Please make sure to set it beforehand.' + ); + } + return $this->username; } @@ -170,7 +188,7 @@ class ApiCommandTransport implements CommandTransportInterface * * @return $this */ - public function setUsername($username) + public function setUsername(string $username): self { $this->username = $username; @@ -184,11 +202,18 @@ class ApiCommandTransport implements CommandTransportInterface * * @return string */ - protected function getUriFor($endpoint) + protected function getUriFor(string $endpoint): string { return sprintf('https://%s:%u/v1/%s', $this->getHost(), $this->getPort(), $endpoint); } + /** + * Send the given command to the icinga2's REST API + * + * @param IcingaApiCommand $command + * + * @return mixed + */ protected function sendCommand(IcingaApiCommand $command) { Logger::debug( @@ -268,8 +293,10 @@ class ApiCommandTransport implements CommandTransportInterface * @param int|null $now * * @throws CommandTransportException + * + * @return void */ - public function send(IcingaCommand $command, $now = null) + public function send(IcingaCommand $command, int $now = null) { return $this->sendCommand($this->renderer->render($command)); } @@ -277,6 +304,8 @@ class ApiCommandTransport implements CommandTransportInterface /** * Try to connect to the API * + * @return void + * * @throws CommandTransportException In case the connection was not successful */ public function probe() diff --git a/library/Icingadb/Command/Transport/CommandTransport.php b/library/Icingadb/Command/Transport/CommandTransport.php index b9cd1470..9b2e9860 100644 --- a/library/Icingadb/Command/Transport/CommandTransport.php +++ b/library/Icingadb/Command/Transport/CommandTransport.php @@ -30,7 +30,7 @@ class CommandTransport implements CommandTransportInterface * * @throws ConfigurationError */ - public static function getConfig() + public static function getConfig(): Config { if (static::$config === null) { $config = Config::module('icingadb', 'commandtransports'); @@ -56,7 +56,7 @@ class CommandTransport implements CommandTransportInterface * * @throws ConfigurationError */ - public static function createTransport(ConfigObject $config) + public static function createTransport(ConfigObject $config): ApiCommandTransport { $config = clone $config; switch (strtolower($config->transport)) { @@ -97,8 +97,10 @@ class CommandTransport implements CommandTransportInterface * @param int|null $now Timestamp of the command or null for now * * @throws CommandTransportException If sending the Icinga command failed + * + * @return void */ - public function send(IcingaCommand $command, $now = null) + public function send(IcingaCommand $command, int $now = null) { $errors = []; diff --git a/library/Icingadb/Command/Transport/CommandTransportInterface.php b/library/Icingadb/Command/Transport/CommandTransportInterface.php index 567275ae..ad07cb90 100644 --- a/library/Icingadb/Command/Transport/CommandTransportInterface.php +++ b/library/Icingadb/Command/Transport/CommandTransportInterface.php @@ -19,5 +19,5 @@ interface CommandTransportInterface * * @throws CommandTransportException If sending the Icinga command failed */ - public function send(IcingaCommand $command, $now = null); + public function send(IcingaCommand $command, int $now = null); } diff --git a/library/Icingadb/Common/Auth.php b/library/Icingadb/Common/Auth.php index 1ffcde64..e61a962b 100644 --- a/library/Icingadb/Common/Auth.php +++ b/library/Icingadb/Common/Auth.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Icingadb\Common; +use Icinga\Authentication\Auth as IcingaAuth; use Icinga\Exception\ConfigurationError; use Icinga\Module\Icingadb\Authentication\ObjectAuthorization; use Icinga\Util\StringHelper; @@ -17,9 +18,9 @@ use ipl\Web\Filter\QueryString; trait Auth { - public function getAuth() + public function getAuth(): IcingaAuth { - return \Icinga\Authentication\Auth::getInstance(); + return IcingaAuth::getInstance(); } /** @@ -29,7 +30,7 @@ trait Auth * * @return bool */ - public function isPermittedRoute($name) + public function isPermittedRoute(string $name): bool { if ($this->getAuth()->getUser()->isUnrestricted()) { return true; @@ -51,7 +52,7 @@ trait Auth * * @return bool */ - public function isGrantedOn($permission, Model $object) + public function isGrantedOn(string $permission, Model $object): bool { if ($this->getAuth()->getUser()->isUnrestricted()) { return $this->getAuth()->hasPermission($permission); @@ -76,7 +77,7 @@ trait Auth * * @return bool */ - public function isGrantedOnType($permission, $type, Filter\Rule $filter, $cache = true) + public function isGrantedOnType(string $permission, string $type, Filter\Rule $filter, bool $cache = true): bool { if ($this->getAuth()->getUser()->isUnrestricted()) { return $this->getAuth()->hasPermission($permission); @@ -247,7 +248,7 @@ trait Auth * * @return Filter\Rule */ - protected function parseRestriction($queryString, $restriction) + protected function parseRestriction(string $queryString, string $restriction): Filter\Rule { $allowedColumns = [ 'host.name', @@ -311,7 +312,7 @@ trait Auth * * @return Filter\None */ - protected function parseBlacklist($blacklist, $column) + protected function parseBlacklist(string $blacklist, string $column): Filter\None { $filter = Filter::none(); foreach (explode(',', $blacklist) as $value) { diff --git a/library/Icingadb/Common/BaseFilter.php b/library/Icingadb/Common/BaseFilter.php index b1080d2a..a4f69837 100644 --- a/library/Icingadb/Common/BaseFilter.php +++ b/library/Icingadb/Common/BaseFilter.php @@ -16,7 +16,7 @@ trait BaseFilter * * @return bool */ - public function hasBaseFilter() + public function hasBaseFilter(): bool { return $this->baseFilter !== null; } @@ -24,7 +24,7 @@ trait BaseFilter /** * Get the base filter * - * @return Rule + * @return ?Rule */ public function getBaseFilter() { @@ -38,7 +38,7 @@ trait BaseFilter * * @return $this */ - public function setBaseFilter(Rule $baseFilter = null) + public function setBaseFilter(Rule $baseFilter = null): self { $this->baseFilter = $baseFilter; diff --git a/library/Icingadb/Common/BaseItemList.php b/library/Icingadb/Common/BaseItemList.php index 5e29dcbe..7eacb28e 100644 --- a/library/Icingadb/Common/BaseItemList.php +++ b/library/Icingadb/Common/BaseItemList.php @@ -49,14 +49,14 @@ abstract class BaseItemList extends BaseHtmlElement $this->init(); } - abstract protected function getItemClass(); + abstract protected function getItemClass(): string; /** * Get whether the list contains at least one item with an icon_image * * @return bool */ - public function hasIconImages() + public function hasIconImages(): bool { return $this->hasIconImages; } diff --git a/library/Icingadb/Common/BaseListItem.php b/library/Icingadb/Common/BaseListItem.php index 02eb4900..c552bb64 100644 --- a/library/Icingadb/Common/BaseListItem.php +++ b/library/Icingadb/Common/BaseListItem.php @@ -66,7 +66,7 @@ abstract class BaseListItem extends BaseHtmlElement { } - protected function createCaption() + protected function createCaption(): BaseHtmlElement { $caption = Html::tag('section', ['class' => 'caption']); @@ -75,7 +75,7 @@ abstract class BaseListItem extends BaseHtmlElement return $caption; } - protected function createHeader() + protected function createHeader(): BaseHtmlElement { $header = Html::tag('header'); @@ -84,7 +84,7 @@ abstract class BaseListItem extends BaseHtmlElement return $header; } - protected function createMain() + protected function createMain(): BaseHtmlElement { $main = Html::tag('div', ['class' => 'main']); @@ -93,7 +93,7 @@ abstract class BaseListItem extends BaseHtmlElement return $main; } - protected function createFooter() + protected function createFooter(): BaseHtmlElement { $footer = new HtmlElement('footer'); @@ -102,6 +102,9 @@ abstract class BaseListItem extends BaseHtmlElement return $footer; } + /** + * @return ?BaseHtmlElement + */ protected function createIconImage() { if (! $this->list->hasIconImages()) { @@ -121,7 +124,7 @@ abstract class BaseListItem extends BaseHtmlElement { } - protected function createTitle() + protected function createTitle(): BaseHtmlElement { $title = HTML::tag('div', ['class' => 'title']); @@ -130,6 +133,9 @@ abstract class BaseListItem extends BaseHtmlElement return $title; } + /** + * @return ?BaseHtmlElement + */ protected function createVisual() { $visual = Html::tag('div', ['class' => 'visual']); diff --git a/library/Icingadb/Common/BaseOrderedListItem.php b/library/Icingadb/Common/BaseOrderedListItem.php index 22357901..bf0f2b2a 100644 --- a/library/Icingadb/Common/BaseOrderedListItem.php +++ b/library/Icingadb/Common/BaseOrderedListItem.php @@ -16,9 +16,9 @@ abstract class BaseOrderedListItem extends BaseListItem * * @return $this */ - public function setOrder($order) + public function setOrder(int $order): self { - $this->order = (int) $order; + $this->order = $order; return $this; } @@ -30,6 +30,12 @@ abstract class BaseOrderedListItem extends BaseListItem */ public function getOrder() { + if ($this->order === null) { + throw new \LogicException( + 'You are accessing an unset property. Please make sure to set it beforehand.' + ); + } + return $this->order; } } diff --git a/library/Icingadb/Common/BaseStatusBar.php b/library/Icingadb/Common/BaseStatusBar.php index 9f3b23b7..7339eb20 100644 --- a/library/Icingadb/Common/BaseStatusBar.php +++ b/library/Icingadb/Common/BaseStatusBar.php @@ -24,9 +24,9 @@ abstract class BaseStatusBar extends BaseHtmlElement abstract protected function assembleTotal(BaseHtmlElement $total); - abstract protected function createStateBadges(); + abstract protected function createStateBadges(): BaseHtmlElement; - protected function createCount() + protected function createCount(): BaseHtmlElement { $total = Html::tag('span', ['class' => 'item-count']); diff --git a/library/Icingadb/Common/BaseTableRowItem.php b/library/Icingadb/Common/BaseTableRowItem.php index 642cf290..d3e00366 100644 --- a/library/Icingadb/Common/BaseTableRowItem.php +++ b/library/Icingadb/Common/BaseTableRowItem.php @@ -47,12 +47,12 @@ abstract class BaseTableRowItem extends BaseHtmlElement { } - protected function createColumn($content = null) + protected function createColumn($content = null): BaseHtmlElement { return Html::tag('div', ['class' => 'col'], $content); } - protected function createColumns() + protected function createColumns(): HtmlDocument { $columns = new HtmlDocument(); @@ -61,7 +61,7 @@ abstract class BaseTableRowItem extends BaseHtmlElement return $columns; } - protected function createTitle() + protected function createTitle(): BaseHtmlElement { $title = $this->createColumn()->addAttributes(['class' => 'title']); @@ -70,6 +70,9 @@ abstract class BaseTableRowItem extends BaseHtmlElement return $title; } + /** + * @return ?BaseHtmlElement + */ protected function createVisual() { $visual = new HtmlElement('div', Attributes::create(['class' => 'visual'])); diff --git a/library/Icingadb/Common/CaptionDisabled.php b/library/Icingadb/Common/CaptionDisabled.php index 7f5c8adc..26344c51 100644 --- a/library/Icingadb/Common/CaptionDisabled.php +++ b/library/Icingadb/Common/CaptionDisabled.php @@ -11,7 +11,7 @@ trait CaptionDisabled /** * @return bool */ - public function isCaptionDisabled() + public function isCaptionDisabled(): bool { return $this->captionDisabled; } @@ -21,7 +21,7 @@ trait CaptionDisabled * * @return $this */ - public function setCaptionDisabled($captionDisabled = true) + public function setCaptionDisabled(bool $captionDisabled = true): self { $this->captionDisabled = $captionDisabled; diff --git a/library/Icingadb/Common/CommandActions.php b/library/Icingadb/Common/CommandActions.php index 2086db97..3283964b 100644 --- a/library/Icingadb/Common/CommandActions.php +++ b/library/Icingadb/Common/CommandActions.php @@ -74,7 +74,7 @@ trait CommandActions * * @return Model */ - protected function getCommandTargetModel() + protected function getCommandTargetModel(): Model { if (! isset($this->commandTargetModel)) { $commandTargets = $this->getCommandTargets(); @@ -95,7 +95,7 @@ trait CommandActions * * @return bool */ - protected function isGrantedOnCommandTargets($permission) + protected function isGrantedOnCommandTargets(string $permission): bool { $commandTargets = $this->getCommandTargets(); if (is_array($commandTargets)) { @@ -122,7 +122,7 @@ trait CommandActions * * @throws SecurityException */ - protected function assertIsGrantedOnCommandTargets($permission) + protected function assertIsGrantedOnCommandTargets(string $permission) { if (! $this->isGrantedOnCommandTargets($permission)) { throw new SecurityException('No permission for %s', $permission); @@ -133,6 +133,8 @@ trait CommandActions * Handle and register the given command form * * @param string|CommandForm $form + * + * @return void */ protected function handleCommandForm($form) { diff --git a/library/Icingadb/Common/Database.php b/library/Icingadb/Common/Database.php index d4c7479d..f7097ba7 100644 --- a/library/Icingadb/Common/Database.php +++ b/library/Icingadb/Common/Database.php @@ -23,7 +23,7 @@ trait Database * * @throws ConfigurationError If the related resource configuration does not exist */ - public function getDb() + public function getDb(): Connection { if ($this->db === null) { $config = new SqlConfig(ResourceFactory::getResourceConfig( diff --git a/library/Icingadb/Common/DetailActions.php b/library/Icingadb/Common/DetailActions.php index 6e1b4a03..e92c80d6 100644 --- a/library/Icingadb/Common/DetailActions.php +++ b/library/Icingadb/Common/DetailActions.php @@ -21,7 +21,7 @@ trait DetailActions * * @return $this */ - public function setDetailActionsDisabled($state = true) + public function setDetailActionsDisabled(bool $state = true): self { $this->detailActionsDisabled = $state; @@ -33,7 +33,7 @@ trait DetailActions * * @return bool */ - public function getDetailActionsDisabled() + public function getDetailActionsDisabled(): bool { return $this->detailActionsDisabled; } @@ -43,7 +43,7 @@ trait DetailActions * * @return $this */ - public function initializeDetailActions() + public function initializeDetailActions(): self { $this->getAttributes() ->registerAttributeCallback('class', function () { @@ -63,7 +63,7 @@ trait DetailActions * * @return $this */ - protected function setMultiselectUrl(Url $url) + protected function setMultiselectUrl(Url $url): self { /** @var BaseHtmlElement $this */ $this->getAttributes() @@ -81,7 +81,7 @@ trait DetailActions * * @return $this */ - protected function setDetailUrl(Url $url) + protected function setDetailUrl(Url $url): self { /** @var BaseHtmlElement $this */ $this->getAttributes() @@ -100,7 +100,7 @@ trait DetailActions * * @return $this */ - public function addMultiselectFilterAttribute(BaseHtmlElement $element, Filter\Rule $filter) + public function addMultiselectFilterAttribute(BaseHtmlElement $element, Filter\Rule $filter): self { $element->getAttributes() ->registerAttributeCallback('data-icinga-multiselect-filter', function () use ($filter) { @@ -118,7 +118,7 @@ trait DetailActions * * @return $this */ - public function addDetailFilterAttribute(BaseHtmlElement $element, Filter\Rule $filter) + public function addDetailFilterAttribute(BaseHtmlElement $element, Filter\Rule $filter): self { $element->getAttributes() ->registerAttributeCallback('data-icinga-detail-filter', function () use ($filter) { diff --git a/library/Icingadb/Common/HostLink.php b/library/Icingadb/Common/HostLink.php index 081c485e..51386bf5 100644 --- a/library/Icingadb/Common/HostLink.php +++ b/library/Icingadb/Common/HostLink.php @@ -5,12 +5,13 @@ namespace Icinga\Module\Icingadb\Common; use Icinga\Module\Icingadb\Model\Host; +use ipl\Html\BaseHtmlElement; use ipl\Html\Html; use ipl\Web\Widget\StateBall; trait HostLink { - protected function createHostLink(Host $host, $withStateBall = false) + protected function createHostLink(Host $host, bool $withStateBall = false): BaseHtmlElement { $content = []; diff --git a/library/Icingadb/Common/HostLinks.php b/library/Icingadb/Common/HostLinks.php index 1a044606..e8f28800 100644 --- a/library/Icingadb/Common/HostLinks.php +++ b/library/Icingadb/Common/HostLinks.php @@ -9,67 +9,67 @@ use ipl\Web\Url; abstract class HostLinks { - public static function acknowledge(Host $host) + public static function acknowledge(Host $host): Url { return Url::fromPath('icingadb/host/acknowledge', ['name' => $host->name]); } - public static function addComment(Host $host) + public static function addComment(Host $host): Url { return Url::fromPath('icingadb/host/add-comment', ['name' => $host->name]); } - public static function checkNow(Host $host) + public static function checkNow(Host $host): Url { return Url::fromPath('icingadb/host/check-now', ['name' => $host->name]); } - public static function scheduleCheck(Host $host) + public static function scheduleCheck(Host $host): Url { return Url::fromPath('icingadb/host/schedule-check', ['name' => $host->name]); } - public static function comments(Host $host) + public static function comments(Host $host): Url { return Url::fromPath('icingadb/comments', ['host.name' => $host->name]); } - public static function downtimes(Host $host) + public static function downtimes(Host $host): Url { return Url::fromPath('icingadb/downtimes', ['host.name' => $host->name]); } - public static function history(Host $host) + public static function history(Host $host): Url { return Url::fromPath('icingadb/host/history', ['name' => $host->name]); } - public static function removeAcknowledgement(Host $host) + public static function removeAcknowledgement(Host $host): Url { return Url::fromPath('icingadb/host/remove-acknowledgement', ['name' => $host->name]); } - public static function scheduleDowntime(Host $host) + public static function scheduleDowntime(Host $host): Url { return Url::fromPath('icingadb/host/schedule-downtime', ['name' => $host->name]); } - public static function sendCustomNotification(Host $host) + public static function sendCustomNotification(Host $host): Url { return Url::fromPath('icingadb/host/send-custom-notification', ['name' => $host->name]); } - public static function processCheckresult(Host $host) + public static function processCheckresult(Host $host): Url { return Url::fromPath('icingadb/host/process-checkresult', ['name' => $host->name]); } - public static function toggleFeatures(Host $host) + public static function toggleFeatures(Host $host): Url { return Url::fromPath('icingadb/host/toggle-features', ['name' => $host->name]); } - public static function services(Host $host) + public static function services(Host $host): Url { return Url::fromPath('icingadb/host/services', ['name' => $host->name]); } diff --git a/library/Icingadb/Common/HostStates.php b/library/Icingadb/Common/HostStates.php index b74d17bd..ab461ba0 100644 --- a/library/Icingadb/Common/HostStates.php +++ b/library/Icingadb/Common/HostStates.php @@ -26,7 +26,7 @@ class HostStates * * @throws \InvalidArgumentException If the given host state is invalid, i.e. not known */ - public static function int($state) + public static function int(string $state): int { switch (strtolower($state)) { case 'up': @@ -57,7 +57,7 @@ class HostStates * * @throws \InvalidArgumentException If the given host state is invalid, i.e. not known */ - public static function text($state) + public static function text(int $state): string { switch (true) { case $state === self::UP: @@ -91,7 +91,7 @@ class HostStates * * @throws \InvalidArgumentException If the given host state is invalid, i.e. not known */ - public static function translated($state) + public static function translated(int $state): string { switch (true) { case $state === self::UP: diff --git a/library/Icingadb/Common/IcingaRedis.php b/library/Icingadb/Common/IcingaRedis.php index 3a9be148..071c45d8 100644 --- a/library/Icingadb/Common/IcingaRedis.php +++ b/library/Icingadb/Common/IcingaRedis.php @@ -41,7 +41,7 @@ class IcingaRedis * * @throws Exception */ - public function getConnection() + public function getConnection(): Redis { if ($this->redisUnavailable) { throw new Exception('Redis is still not available'); @@ -95,6 +95,13 @@ class IcingaRedis return $this->redis; } + /** + * Get the last icinga heartbeat from redis + * + * @param Redis|null $redis + * + * @return ?float|int + */ public static function getLastIcingaHeartbeat(Redis $redis = null) { if ($redis === null) { @@ -126,7 +133,15 @@ class IcingaRedis return null; } - public static function getPrimaryRedis(Config $moduleConfig = null, Config $redisConfig = null) + /** + * Get the primary redis instance + * + * @param Config|null $moduleConfig + * @param Config|null $redisConfig + * + * @return Redis + */ + public static function getPrimaryRedis(Config $moduleConfig = null, Config $redisConfig = null): Redis { if ($moduleConfig === null) { $moduleConfig = Config::module('icingadb'); @@ -149,6 +164,14 @@ class IcingaRedis return $redis; } + /** + * Get the secondary redis instance if exists + * + * @param Config|null $moduleConfig + * @param Config|null $redisConfig + * + * @return ?Redis + */ public static function getSecondaryRedis(Config $moduleConfig = null, Config $redisConfig = null) { if ($moduleConfig === null) { @@ -177,7 +200,7 @@ class IcingaRedis return $redis; } - private static function getTlsParams(Config $config) + private static function getTlsParams(Config $config): array { $config = $config->getSection('redis'); diff --git a/library/Icingadb/Common/Links.php b/library/Icingadb/Common/Links.php index 628b1ee6..5968e5fb 100644 --- a/library/Icingadb/Common/Links.php +++ b/library/Icingadb/Common/Links.php @@ -16,127 +16,127 @@ use ipl\Web\Url; abstract class Links { - public static function comment(Comment $comment) + public static function comment(Comment $comment): Url { return Url::fromPath('icingadb/comment', ['name' => $comment->name]); } - public static function comments() + public static function comments(): Url { return Url::fromPath('icingadb/comments'); } - public static function commentsDelete() + public static function commentsDelete(): Url { return Url::fromPath('icingadb/comments/delete'); } - public static function commentsDetails() + public static function commentsDetails(): Url { return Url::fromPath('icingadb/comments/details'); } - public static function downtime(Downtime $downtime) + public static function downtime(Downtime $downtime): Url { return Url::fromPath('icingadb/downtime', ['name' => $downtime->name]); } - public static function downtimes() + public static function downtimes(): Url { return Url::fromPath('icingadb/downtimes'); } - public static function downtimesDelete() + public static function downtimesDelete(): Url { return Url::fromPath('icingadb/downtimes/delete'); } - public static function downtimesDetails() + public static function downtimesDetails(): Url { return Url::fromPath('icingadb/downtimes/details'); } - public static function host(Host $host) + public static function host(Host $host): Url { return Url::fromPath('icingadb/host', ['name' => $host->name]); } - public static function hostSource(Host $host) + public static function hostSource(Host $host): Url { return Url::fromPath('icingadb/host/source', ['name' => $host->name]); } - public static function hostsDetails() + public static function hostsDetails(): Url { return Url::fromPath('icingadb/hosts/details'); } - public static function hostgroup($hostgroup) + public static function hostgroup($hostgroup): Url { return Url::fromPath('icingadb/hostgroup', ['name' => $hostgroup->name]); } - public static function hosts() + public static function hosts(): Url { return Url::fromPath('icingadb/hosts'); } - public static function service(Service $service, Host $host) + public static function service(Service $service, Host $host): Url { return Url::fromPath('icingadb/service', ['name' => $service->name, 'host.name' => $host->name]); } - public static function serviceSource(Service $service, Host $host) + public static function serviceSource(Service $service, Host $host): Url { return Url::fromPath('icingadb/service/source', ['name' => $service->name, 'host.name' => $host->name]); } - public static function servicesDetails() + public static function servicesDetails(): Url { return Url::fromPath('icingadb/services/details'); } - public static function servicegroup($servicegroup) + public static function servicegroup($servicegroup): Url { return Url::fromPath('icingadb/servicegroup', ['name' => $servicegroup->name]); } - public static function services() + public static function services(): Url { return Url::fromPath('icingadb/services'); } - public static function toggleHostsFeatures() + public static function toggleHostsFeatures(): Url { return Url::fromPath('icingadb/hosts/toggle-features'); } - public static function toggleServicesFeatures() + public static function toggleServicesFeatures(): Url { return Url::fromPath('icingadb/services/toggle-features'); } - public static function user(User $user) + public static function user(User $user): Url { return Url::fromPath('icingadb/user', ['name' => $user->name]); } - public static function usergroup(Usergroup $usergroup) + public static function usergroup(Usergroup $usergroup): Url { return Url::fromPath('icingadb/usergroup', ['name' => $usergroup->name]); } - public static function users() + public static function users(): Url { return Url::fromPath('icingadb/users'); } - public static function usergroups() + public static function usergroups(): Url { return Url::fromPath('icingadb/usergroups'); } - public static function event(History $event) + public static function event(History $event): Url { return Url::fromPath('icingadb/event', ['id' => bin2hex($event->id)]); } diff --git a/library/Icingadb/Common/LoadMore.php b/library/Icingadb/Common/LoadMore.php index 18c9ac23..c9ef0a26 100644 --- a/library/Icingadb/Common/LoadMore.php +++ b/library/Icingadb/Common/LoadMore.php @@ -28,7 +28,7 @@ trait LoadMore * * @return $this */ - public function setPageSize($size) + public function setPageSize(int $size): self { $this->pageSize = $size; @@ -42,7 +42,7 @@ trait LoadMore * * @return $this */ - public function setPageNumber($number) + public function setPageNumber(int $number): self { $this->pageNumber = $number; @@ -56,7 +56,7 @@ trait LoadMore * * @return $this */ - public function setLoadMoreUrl(Url $url) + public function setLoadMoreUrl(Url $url): self { $this->loadMoreUrl = $url; @@ -72,7 +72,7 @@ trait LoadMore * * @return Generator */ - protected function getIterator(ResultSet $result) + protected function getIterator(ResultSet $result): Generator { $count = 0; $pageNumber = $this->pageNumber ?: 1; diff --git a/library/Icingadb/Common/NoSubjectLink.php b/library/Icingadb/Common/NoSubjectLink.php index eebb88cb..76c9a84d 100644 --- a/library/Icingadb/Common/NoSubjectLink.php +++ b/library/Icingadb/Common/NoSubjectLink.php @@ -16,7 +16,7 @@ trait NoSubjectLink * * @return $this */ - public function setNoSubjectLink($state = true) + public function setNoSubjectLink(bool $state = true): self { $this->noSubjectLink = $state; @@ -28,7 +28,7 @@ trait NoSubjectLink * * @return bool */ - public function getNoSubjectLink() + public function getNoSubjectLink(): bool { return $this->noSubjectLink; } diff --git a/library/Icingadb/Common/ObjectInspectionDetail.php b/library/Icingadb/Common/ObjectInspectionDetail.php index 2273bc4d..00258ea4 100644 --- a/library/Icingadb/Common/ObjectInspectionDetail.php +++ b/library/Icingadb/Common/ObjectInspectionDetail.php @@ -42,6 +42,11 @@ abstract class ObjectInspectionDetail extends BaseHtmlElement $this->joins = $apiResult['joins']; } + /** + * Render the object source location + * + * @return ?array + */ protected function createSourceLocation() { if (! isset($this->attrs['source_location'])) { @@ -58,6 +63,11 @@ abstract class ObjectInspectionDetail extends BaseHtmlElement ]; } + /** + * Render object's last check result + * + * @return ?array + */ protected function createLastCheckResult() { if (! isset($this->attrs['last_check_result'])) { @@ -94,7 +104,7 @@ abstract class ObjectInspectionDetail extends BaseHtmlElement ]; } - protected function createRedisInfo() + protected function createRedisInfo(): array { $title = new HtmlElement('h2', null, Text::create(t('Volatile State Details'))); @@ -138,7 +148,7 @@ abstract class ObjectInspectionDetail extends BaseHtmlElement )]; } - protected function createAttributes() + protected function createAttributes(): array { $blacklist = [ 'name', @@ -188,6 +198,13 @@ abstract class ObjectInspectionDetail extends BaseHtmlElement ]; } + /** + * Format the given value as a json + * + * @param mixed $json + * + * @return BaseHtmlElement|string + */ private function formatJson($json) { if (is_scalar($json)) { @@ -201,7 +218,7 @@ abstract class ObjectInspectionDetail extends BaseHtmlElement ); } - private function formatTimestamp($ts) + private function formatTimestamp($ts): string { if (empty($ts)) { return new EmptyState(t('n. a.')); @@ -217,22 +234,22 @@ abstract class ObjectInspectionDetail extends BaseHtmlElement ->format('Y-m-d\TH:i:s.vP'); } - private function formatMillisecondTimestamp($ms) + private function formatMillisecondTimestamp($ms): string { return $this->formatTimestamp($ms / 1000.0); } - private function formatSeconds($s) + private function formatSeconds($s): string { return Format::seconds($s); } - private function formatMilliseconds($ms) + private function formatMilliseconds($ms): string { return Format::seconds($ms / 1000.0); } - private function formatState($state) + private function formatState(int $state): string { switch (true) { case $this->object instanceof Host: @@ -244,7 +261,7 @@ abstract class ObjectInspectionDetail extends BaseHtmlElement } } - private function createNameValueTable(array $data, array $formatters) + private function createNameValueTable(array $data, array $formatters): Table { $table = new Table(); $table->addAttributes(['class' => 'name-value-table']); diff --git a/library/Icingadb/Common/ObjectLinkDisabled.php b/library/Icingadb/Common/ObjectLinkDisabled.php index da28e8d3..ca8283f5 100644 --- a/library/Icingadb/Common/ObjectLinkDisabled.php +++ b/library/Icingadb/Common/ObjectLinkDisabled.php @@ -16,7 +16,7 @@ trait ObjectLinkDisabled * * @return $this */ - public function setObjectLinkDisabled($state = true) + public function setObjectLinkDisabled(bool $state = true): self { $this->objectLinkDisabled = $state; @@ -28,7 +28,7 @@ trait ObjectLinkDisabled * * @return bool */ - public function getObjectLinkDisabled() + public function getObjectLinkDisabled(): bool { return $this->objectLinkDisabled; } diff --git a/library/Icingadb/Common/ServiceLink.php b/library/Icingadb/Common/ServiceLink.php index 9aa72987..ce83a296 100644 --- a/library/Icingadb/Common/ServiceLink.php +++ b/library/Icingadb/Common/ServiceLink.php @@ -6,12 +6,13 @@ namespace Icinga\Module\Icingadb\Common; use Icinga\Module\Icingadb\Model\Host; use Icinga\Module\Icingadb\Model\Service; +use ipl\Html\FormattedString; use ipl\Html\Html; use ipl\Web\Widget\StateBall; trait ServiceLink { - protected function createServiceLink(Service $service, Host $host, $withStateBall = false) + protected function createServiceLink(Service $service, Host $host, bool $withStateBall = false): FormattedString { $content = []; diff --git a/library/Icingadb/Common/ServiceLinks.php b/library/Icingadb/Common/ServiceLinks.php index 751796f1..368be48b 100644 --- a/library/Icingadb/Common/ServiceLinks.php +++ b/library/Icingadb/Common/ServiceLinks.php @@ -10,7 +10,7 @@ use ipl\Web\Url; abstract class ServiceLinks { - public static function acknowledge(Service $service, Host $host) + public static function acknowledge(Service $service, Host $host): Url { return Url::fromPath( 'icingadb/service/acknowledge', @@ -18,7 +18,7 @@ abstract class ServiceLinks ); } - public static function addComment(Service $service, Host $host) + public static function addComment(Service $service, Host $host): Url { return Url::fromPath( 'icingadb/service/add-comment', @@ -26,7 +26,7 @@ abstract class ServiceLinks ); } - public static function checkNow(Service $service, Host $host) + public static function checkNow(Service $service, Host $host): Url { return Url::fromPath( 'icingadb/service/check-now', @@ -34,7 +34,7 @@ abstract class ServiceLinks ); } - public static function scheduleCheck(Service $service, Host $host) + public static function scheduleCheck(Service $service, Host $host): Url { return Url::fromPath( 'icingadb/service/schedule-check', @@ -42,7 +42,7 @@ abstract class ServiceLinks ); } - public static function comments(Service $service, Host $host) + public static function comments(Service $service, Host $host): Url { return Url::fromPath( 'icingadb/comments', @@ -50,7 +50,7 @@ abstract class ServiceLinks ); } - public static function downtimes(Service $service, Host $host) + public static function downtimes(Service $service, Host $host): Url { return Url::fromPath( 'icingadb/downtimes', @@ -58,7 +58,7 @@ abstract class ServiceLinks ); } - public static function history(Service $service, Host $host) + public static function history(Service $service, Host $host): Url { return Url::fromPath( 'icingadb/service/history', @@ -66,7 +66,7 @@ abstract class ServiceLinks ); } - public static function removeAcknowledgement(Service $service, Host $host) + public static function removeAcknowledgement(Service $service, Host $host): Url { return Url::fromPath( 'icingadb/service/remove-acknowledgement', @@ -74,7 +74,7 @@ abstract class ServiceLinks ); } - public static function scheduleDowntime(Service $service, Host $host) + public static function scheduleDowntime(Service $service, Host $host): Url { return Url::fromPath( 'icingadb/service/schedule-downtime', @@ -82,7 +82,7 @@ abstract class ServiceLinks ); } - public static function sendCustomNotification(Service $service, Host $host) + public static function sendCustomNotification(Service $service, Host $host): Url { return Url::fromPath( 'icingadb/service/send-custom-notification', @@ -90,7 +90,7 @@ abstract class ServiceLinks ); } - public static function processCheckresult(Service $service, Host $host) + public static function processCheckresult(Service $service, Host $host): Url { return Url::fromPath( 'icingadb/service/process-checkresult', @@ -98,7 +98,7 @@ abstract class ServiceLinks ); } - public static function toggleFeatures(Service $service, Host $host) + public static function toggleFeatures(Service $service, Host $host): Url { return Url::fromPath( 'icingadb/service/toggle-features', diff --git a/library/Icingadb/Common/ServiceStates.php b/library/Icingadb/Common/ServiceStates.php index c815c1c0..f902eaa5 100644 --- a/library/Icingadb/Common/ServiceStates.php +++ b/library/Icingadb/Common/ServiceStates.php @@ -28,7 +28,7 @@ class ServiceStates * * @throws \InvalidArgumentException If the given service state is invalid, i.e. not known */ - public static function int($state) + public static function int(string $state): int { switch (strtolower($state)) { case 'ok': @@ -62,7 +62,7 @@ class ServiceStates * * @throws \InvalidArgumentException If the given service state is invalid, i.e. not known */ - public static function text($state) + public static function text(int $state): string { switch (true) { case $state === self::OK: @@ -99,7 +99,7 @@ class ServiceStates * * @throws \InvalidArgumentException If the given service state is invalid, i.e. not known */ - public static function translated($state) + public static function translated(int $state): string { switch (true) { case $state === self::OK: diff --git a/library/Icingadb/Common/StateBadges.php b/library/Icingadb/Common/StateBadges.php index a06a38d8..1d6832ad 100644 --- a/library/Icingadb/Common/StateBadges.php +++ b/library/Icingadb/Common/StateBadges.php @@ -46,14 +46,14 @@ abstract class StateBadges extends BaseHtmlElement * * @return Url */ - abstract protected function getBaseUrl(); + abstract protected function getBaseUrl(): Url; /** * Get the prefix for accessing state information * * @return string */ - abstract protected function getPrefix(); + abstract protected function getPrefix(): string; /** * Get the integer of the given state text @@ -62,14 +62,14 @@ abstract class StateBadges extends BaseHtmlElement * * @return int */ - abstract protected function getStateInt($state); + abstract protected function getStateInt(string $state): int; /** * Get the badge URL * * @return Url */ - public function getUrl() + public function getUrl(): Url { return $this->url; } @@ -81,7 +81,7 @@ abstract class StateBadges extends BaseHtmlElement * * @return $this */ - public function setUrl($url) + public function setUrl(Url $url): self { $this->url = $url; @@ -96,7 +96,7 @@ abstract class StateBadges extends BaseHtmlElement * * @return Link */ - public function createLink($content, array $params = null) + public function createLink($content, array $params = null): Link { $url = clone $this->getUrl(); @@ -111,7 +111,14 @@ abstract class StateBadges extends BaseHtmlElement return new Link($content, $url); } - protected function createBadge($state) + /** + * Create a state bade + * + * @param string $state + * + * @return ?BaseHtmlElement + */ + protected function createBadge(string $state) { $key = $this->prefix . "_{$state}"; @@ -125,7 +132,14 @@ abstract class StateBadges extends BaseHtmlElement return null; } - protected function createGroup($state) + /** + * Create a state group + * + * @param string $state + * + * @return ?BaseHtmlElement + */ + protected function createGroup(string $state) { $content = []; $handledKey = $this->prefix . "_{$state}_handled"; diff --git a/library/Icingadb/Common/ViewMode.php b/library/Icingadb/Common/ViewMode.php index 744ad9be..841f28b1 100644 --- a/library/Icingadb/Common/ViewMode.php +++ b/library/Icingadb/Common/ViewMode.php @@ -12,7 +12,7 @@ trait ViewMode /** * Get the view mode * - * @return string + * @return ?string */ public function getViewMode() { @@ -26,7 +26,7 @@ trait ViewMode * * @return $this */ - public function setViewMode($viewMode) + public function setViewMode(string $viewMode): self { $this->viewMode = $viewMode; diff --git a/library/Icingadb/Compat/CompatObject.php b/library/Icingadb/Compat/CompatObject.php index f01fce82..f7ef06e5 100644 --- a/library/Icingadb/Compat/CompatObject.php +++ b/library/Icingadb/Compat/CompatObject.php @@ -51,17 +51,17 @@ trait CompatObject * * @return string */ - public function getName() + public function getName(): string { return $this->object->name; } - public function fetch() + public function fetch(): bool { return true; } - protected function fetchRawCustomvars() + protected function fetchRawCustomvars(): self { if ($this->rawCustomvars !== null) { return $this; @@ -79,7 +79,7 @@ trait CompatObject return $this; } - public function fetchCustomvars() + public function fetchCustomvars(): self { if ($this->customvars !== null) { return $this; @@ -181,6 +181,13 @@ trait CompatObject throw new NotImplementedError('getDataView() is not supported'); } + /** + * Get the bool type of the given value as an int + * + * @param bool|string $value + * + * @return ?int + */ private function getBoolType($value) { switch ($value) { diff --git a/library/Icingadb/Compat/CompatService.php b/library/Icingadb/Compat/CompatService.php index 8045b604..cb5f15ee 100644 --- a/library/Icingadb/Compat/CompatService.php +++ b/library/Icingadb/Compat/CompatService.php @@ -143,7 +143,7 @@ class CompatService extends Service * * @return CompatHost */ - public function getHost() + public function getHost(): CompatHost { if ($this->host === null) { $this->host = new CompatHost($this->object->host); diff --git a/library/Icingadb/Compat/UrlMigrator.php b/library/Icingadb/Compat/UrlMigrator.php index cc58cc8d..4b06ef86 100644 --- a/library/Icingadb/Compat/UrlMigrator.php +++ b/library/Icingadb/Compat/UrlMigrator.php @@ -39,18 +39,18 @@ class UrlMigrator 'monitoring/tactical' => ['services', 'icingadb/tactical'] ]; - public static function isSupportedUrl(Url $url) + public static function isSupportedUrl(Url $url): bool { $supportedPaths = self::SUPPORTED_PATHS; return isset($supportedPaths[$url->getPath()]); } - public static function hasQueryTransformer($name) + public static function hasQueryTransformer(string $name): bool { return method_exists(new self(), $name . 'Columns'); } - public static function transformUrl(Url $url) + public static function transformUrl(Url $url): Url { if (! self::isSupportedUrl($url)) { throw new InvalidArgumentException(sprintf('Url path "%s" is not supported', $url->getPath())); @@ -70,7 +70,15 @@ class UrlMigrator return $url; } - public static function transformFilter(Filter\Rule $filter, $queryTransformer = null) + /** + * Transform the given legacy filter + * + * @param Filter\Rule $filter + * @param string|null $queryTransformer + * + * @return Filter\Rule|false + */ + public static function transformFilter(Filter\Rule $filter, string $queryTransformer = null) { $transformer = new self(); @@ -87,6 +95,15 @@ class UrlMigrator return $rewritten === false ? false : ($rewritten instanceof Filter\Rule ? $rewritten : $filter); } + /** + * Rewrite the given filter and legacy columns + * + * @param Filter\Rule $filter + * @param array $legacyColumns + * @param Filter\Chain|null $parent + * + * @return ?mixed + */ protected function rewrite(Filter\Rule $filter, array $legacyColumns, Filter\Chain $parent = null) { $rewritten = null; @@ -174,7 +191,7 @@ class UrlMigrator return $rewritten; } - protected static function commonColumns() + protected static function commonColumns(): array { return [ @@ -222,7 +239,7 @@ class UrlMigrator ]; } - protected static function hostsColumns() + protected static function hostsColumns(): array { return [ @@ -402,7 +419,7 @@ class UrlMigrator ]; } - protected static function multipleHostsColumns() + protected static function multipleHostsColumns(): array { return array_merge( static::hostsColumns(), @@ -414,7 +431,7 @@ class UrlMigrator ); } - protected static function hostColumns() + protected static function hostColumns(): array { return [ 'host' => [ @@ -423,7 +440,7 @@ class UrlMigrator ]; } - protected static function servicesColumns() + protected static function servicesColumns(): array { return [ @@ -723,7 +740,7 @@ class UrlMigrator ]; } - protected static function multipleServicesColumns() + protected static function multipleServicesColumns(): array { return array_merge( static::servicesColumns(), @@ -738,7 +755,7 @@ class UrlMigrator ); } - protected static function serviceColumns() + protected static function serviceColumns(): array { return [ 'host' => [ @@ -750,7 +767,7 @@ class UrlMigrator ]; } - protected static function hostgroupsColumns() + protected static function hostgroupsColumns(): array { return [ @@ -772,7 +789,7 @@ class UrlMigrator ]; } - protected static function servicegroupsColumns() + protected static function servicegroupsColumns(): array { return [ @@ -799,7 +816,7 @@ class UrlMigrator ]; } - protected static function contactgroupsColumns() + protected static function contactgroupsColumns(): array { return [ @@ -819,7 +836,7 @@ class UrlMigrator ]; } - protected static function contactsColumns() + protected static function contactsColumns(): array { $receivesStateNotifications = function ($state, $type = null) { return function ($filter) use ($state, $type) { @@ -939,7 +956,7 @@ class UrlMigrator ]; } - protected static function commentsColumns() + protected static function commentsColumns(): array { return [ @@ -986,7 +1003,7 @@ class UrlMigrator ]; } - protected static function downtimesColumns() + protected static function downtimesColumns(): array { return [ @@ -1054,7 +1071,7 @@ class UrlMigrator ]; } - protected static function historyColumns() + protected static function historyColumns(): array { return [ @@ -1117,7 +1134,7 @@ class UrlMigrator ]; } - protected static function notificationHistoryColumns() + protected static function notificationHistoryColumns(): array { return [ diff --git a/library/Icingadb/Data/PivotTable.php b/library/Icingadb/Data/PivotTable.php index 28320080..31ccd4e7 100644 --- a/library/Icingadb/Data/PivotTable.php +++ b/library/Icingadb/Data/PivotTable.php @@ -98,7 +98,7 @@ class PivotTable * @param string $yAxisColumn Y-axis pivot column * @param array $gridcols Grid columns */ - public function __construct(Query $query, $xAxisColumn, $yAxisColumn, $gridcols) + public function __construct(Query $query, string $xAxisColumn, string $yAxisColumn, array $gridcols) { foreach ($query->getOrderBy() as $sort) { $this->order[$sort[0]] = $sort[1]; @@ -118,7 +118,7 @@ class PivotTable * * @return $this */ - public function setXAxisFilter(Filter\Rule $filter = null) + public function setXAxisFilter(Filter\Rule $filter = null): self { $this->xAxisFilter = $filter; return $this; @@ -127,11 +127,11 @@ class PivotTable /** * Set the filter to apply on the query for the y-axis * - * @param Filter $filter + * @param Filter\Rule $filter * * @return $this */ - public function setYAxisFilter(Filter\Rule $filter = null) + public function setYAxisFilter(Filter\Rule $filter = null): self { $this->yAxisFilter = $filter; return $this; @@ -144,8 +144,14 @@ class PivotTable * * @return string */ - public function getXAxisHeader() + public function getXAxisHeader(): string { + if ($this->xAxisHeader === null && $this->xAxisColumn === null) { + throw new \LogicException( + 'You are accessing an unset property. Please make sure to set it beforehand.' + ); + } + return $this->xAxisHeader !== null ? $this->xAxisHeader : $this->xAxisColumn; } @@ -156,9 +162,9 @@ class PivotTable * * @return $this */ - public function setXAxisHeader($xAxisHeader) + public function setXAxisHeader(string $xAxisHeader): self { - $this->xAxisHeader = (string) $xAxisHeader; + $this->xAxisHeader = $xAxisHeader; return $this; } @@ -169,8 +175,14 @@ class PivotTable * * @return string */ - public function getYAxisHeader() + public function getYAxisHeader(): string { + if ($this->yAxisHeader === null && $this->yAxisColumn === null) { + throw new \LogicException( + 'You are accessing an unset property. Please make sure to set it beforehand.' + ); + } + return $this->yAxisHeader !== null ? $this->yAxisHeader : $this->yAxisColumn; } @@ -181,9 +193,9 @@ class PivotTable * * @return $this */ - public function setYAxisHeader($yAxisHeader) + public function setYAxisHeader(string $yAxisHeader): self { - $this->yAxisHeader = (string) $yAxisHeader; + $this->yAxisHeader = $yAxisHeader; return $this; } @@ -196,7 +208,7 @@ class PivotTable * * @return int */ - protected function getPaginationParameter($axis, $param, $default = null) + protected function getPaginationParameter(string $axis, string $param, int $default = null): int { $request = Icinga::app()->getRequest(); @@ -214,7 +226,7 @@ class PivotTable * * @return Query */ - protected function queryXAxis() + protected function queryXAxis(): Query { if ($this->xAxisQuery === null) { $this->xAxisQuery = clone $this->baseQuery; @@ -263,7 +275,7 @@ class PivotTable * * @return Query */ - protected function queryYAxis() + protected function queryYAxis(): Query { if ($this->yAxisQuery === null) { $this->yAxisQuery = clone $this->baseQuery; @@ -317,7 +329,7 @@ class PivotTable * * @return Paginatable */ - public function paginateXAxis($limit = null, $page = null) + public function paginateXAxis(int $limit = null, int $page = null): Paginatable { if ($limit === null || $page === null) { if ($limit === null) { @@ -348,7 +360,7 @@ class PivotTable * * @return Paginatable */ - public function paginateYAxis($limit = null, $page = null) + public function paginateYAxis(int $limit = null, int $page = null): Paginatable { if ($limit === null || $page === null) { if ($limit === null) { @@ -372,7 +384,7 @@ class PivotTable * * @return array */ - public function toArray() + public function toArray(): array { if ( ($this->xAxisFilter === null && $this->yAxisFilter === null) diff --git a/library/Icingadb/Hook/TabHook/HookActions.php b/library/Icingadb/Hook/TabHook/HookActions.php index e7c40bf4..c407657e 100644 --- a/library/Icingadb/Hook/TabHook/HookActions.php +++ b/library/Icingadb/Hook/TabHook/HookActions.php @@ -29,7 +29,7 @@ trait HookActions * * @return ValidHtml[] */ - abstract protected function getDefaultTabControls(); + abstract protected function getDefaultTabControls(): array; public function __call($methodName, $args) { @@ -50,6 +50,8 @@ trait HookActions * Register the object for which to load additional tabs * * @param Model $object + * + * @return void */ protected function loadTabsForObject(Model $object) { @@ -103,6 +105,8 @@ trait HookActions * Render the given tab hook * * @param TabHook $hook + * + * @return void */ protected function showTabHook(TabHook $hook) { diff --git a/library/Icingadb/Model/Behavior/ReRoute.php b/library/Icingadb/Model/Behavior/ReRoute.php index 0961fd64..197b06cf 100644 --- a/library/Icingadb/Model/Behavior/ReRoute.php +++ b/library/Icingadb/Model/Behavior/ReRoute.php @@ -16,7 +16,7 @@ class ReRoute implements RewriteBehavior $this->routes = $routes; } - public function getRoutes() + public function getRoutes(): array { return $this->routes; } diff --git a/library/Icingadb/Model/CustomvarFlat.php b/library/Icingadb/Model/CustomvarFlat.php index 43fab0b3..e63f9581 100644 --- a/library/Icingadb/Model/CustomvarFlat.php +++ b/library/Icingadb/Model/CustomvarFlat.php @@ -85,7 +85,7 @@ class CustomvarFlat extends Model * * @return array */ - public function unFlattenVars(Traversable $flattenedVars) + public function unFlattenVars(Traversable $flattenedVars): array { $registerValue = function (&$data, $path, $value) use (&$registerValue) { $step = array_shift($path); diff --git a/library/Icingadb/Model/HostState.php b/library/Icingadb/Model/HostState.php index 11e25533..2da7d779 100644 --- a/library/Icingadb/Model/HostState.php +++ b/library/Icingadb/Model/HostState.php @@ -71,7 +71,7 @@ class HostState extends State * * @return string */ - public function getStateText() + public function getStateText(): string { return HostStates::text($this->soft_state); } @@ -81,7 +81,7 @@ class HostState extends State * * @return string */ - public function getStateTextTranslated() + public function getStateTextTranslated(): string { return HostStates::text($this->soft_state); } diff --git a/library/Icingadb/Model/ServiceState.php b/library/Icingadb/Model/ServiceState.php index 0124fa82..48bb9ec0 100644 --- a/library/Icingadb/Model/ServiceState.php +++ b/library/Icingadb/Model/ServiceState.php @@ -68,7 +68,7 @@ class ServiceState extends State * * @return string */ - public function getStateText() + public function getStateText(): string { return ServiceStates::text($this->soft_state); } @@ -78,7 +78,7 @@ class ServiceState extends State * * @return string */ - public function getStateTextTranslated() + public function getStateTextTranslated(): string { return ServiceStates::text($this->soft_state); } diff --git a/library/Icingadb/ProvidedHook/IcingaHealth.php b/library/Icingadb/ProvidedHook/IcingaHealth.php index ab85a37f..bb584d46 100644 --- a/library/Icingadb/ProvidedHook/IcingaHealth.php +++ b/library/Icingadb/ProvidedHook/IcingaHealth.php @@ -16,12 +16,12 @@ class IcingaHealth extends HealthHook /** @var Instance */ protected $instance; - public function getName() + public function getName(): string { return 'Icinga DB'; } - public function getUrl() + public function getUrl(): Url { return Url::fromPath('icingadb/health'); } @@ -57,7 +57,7 @@ class IcingaHealth extends HealthHook } } - protected function getInstance() + protected function getInstance(): Instance { if ($this->instance === null) { $this->instance = Instance::on($this->getDb()) diff --git a/library/Icingadb/ProvidedHook/RedisHealth.php b/library/Icingadb/ProvidedHook/RedisHealth.php index ad8f8f59..0c9fc9fd 100644 --- a/library/Icingadb/ProvidedHook/RedisHealth.php +++ b/library/Icingadb/ProvidedHook/RedisHealth.php @@ -14,7 +14,7 @@ class RedisHealth extends HealthHook { use Database; - public function getName() + public function getName(): string { return 'Icinga Redis'; } diff --git a/library/Icingadb/ProvidedHook/X509/Sni.php b/library/Icingadb/ProvidedHook/X509/Sni.php index 51d6493f..d6e1415b 100644 --- a/library/Icingadb/ProvidedHook/X509/Sni.php +++ b/library/Icingadb/ProvidedHook/X509/Sni.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Icingadb\ProvidedHook\X509; +use Generator; use Icinga\Data\Filter\Filter; use Icinga\Module\Icingadb\Common\Auth; use Icinga\Module\Icingadb\Common\Database; @@ -19,7 +20,7 @@ class Sni extends SniHook /** * @inheritDoc */ - public function getHosts(Filter $filter = null) + public function getHosts(Filter $filter = null): Generator { $queryHost = Host::on($this->getDb()); diff --git a/library/Icingadb/Redis/VolatileState.php b/library/Icingadb/Redis/VolatileState.php index 055f36b1..d15b00a3 100644 --- a/library/Icingadb/Redis/VolatileState.php +++ b/library/Icingadb/Redis/VolatileState.php @@ -48,7 +48,7 @@ class VolatileState * * @return $this */ - public function fetch(State $state) + public function fetch(State $state): self { $type = substr($state->getTableName(), 0, -6); diff --git a/library/Icingadb/Setup/ApiTransportPage.php b/library/Icingadb/Setup/ApiTransportPage.php index 236c30a6..310933ae 100644 --- a/library/Icingadb/Setup/ApiTransportPage.php +++ b/library/Icingadb/Setup/ApiTransportPage.php @@ -96,7 +96,7 @@ class ApiTransportPage extends Form return true; } - protected function validateConfiguration() + protected function validateConfiguration(): bool { try { CommandTransport::createTransport(new ConfigObject($this->getValues()))->probe(); diff --git a/library/Icingadb/Setup/DbResourcePage.php b/library/Icingadb/Setup/DbResourcePage.php index fee7619a..8836c6fc 100644 --- a/library/Icingadb/Setup/DbResourcePage.php +++ b/library/Icingadb/Setup/DbResourcePage.php @@ -95,7 +95,7 @@ class DbResourcePage extends Form return true; } - protected function validateConfiguration($showLog = false) + protected function validateConfiguration(bool $showLog = false): bool { $inspection = ResourceConfigForm::inspectResource($this); if ($inspection !== null) { diff --git a/library/Icingadb/Util/FeatureStatus.php b/library/Icingadb/Util/FeatureStatus.php index 7e22860a..94bf6d47 100644 --- a/library/Icingadb/Util/FeatureStatus.php +++ b/library/Icingadb/Util/FeatureStatus.php @@ -9,7 +9,7 @@ use Icinga\Module\Icingadb\Command\Object\ToggleObjectFeatureCommand; class FeatureStatus extends ArrayObject { - public function __construct($type, $summary) + public function __construct(string $type, $summary) { $prefix = "{$type}s"; @@ -29,7 +29,7 @@ class FeatureStatus extends ArrayObject parent::__construct($featureStatus, ArrayObject::ARRAY_AS_PROPS); } - protected function getFeatureStatus($feature, $prefix, $summary) + protected function getFeatureStatus(string $feature, string $prefix, $summary): int { $key = "{$prefix}_{$feature}"; $value = (int) $summary->$key; diff --git a/library/Icingadb/Util/PerfData.php b/library/Icingadb/Util/PerfData.php index 8f456e34..6a6f6591 100644 --- a/library/Icingadb/Util/PerfData.php +++ b/library/Icingadb/Util/PerfData.php @@ -77,7 +77,7 @@ class PerfData * @param string $label The perfdata label * @param string $value The perfdata value */ - public function __construct($label, $value) + public function __construct(string $label, string $value) { $this->perfdataValue = $value; $this->label = $label; @@ -111,7 +111,7 @@ class PerfData * * @throws InvalidArgumentException In case the given performance data has no content or a invalid format */ - public static function fromString($perfdata) + public static function fromString(string $perfdata): self { if (empty($perfdata)) { throw new InvalidArgumentException('PerfData::fromString expects a string with content'); @@ -130,7 +130,7 @@ class PerfData * * @return bool True in case it's a number, otherwise False */ - public function isNumber() + public function isNumber(): bool { return $this->unit === null; } @@ -140,7 +140,7 @@ class PerfData * * @return bool True in case it's seconds, otherwise False */ - public function isSeconds() + public function isSeconds(): bool { return $this->unit === 's'; } @@ -150,7 +150,7 @@ class PerfData * * @return bool True in case it's temperature, otherwise False */ - public function isTemperature() + public function isTemperature(): bool { return in_array($this->unit, array('C', 'F', 'K')); } @@ -160,7 +160,7 @@ class PerfData * * @return bool True in case it's in percentage, otherwise False */ - public function isPercentage() + public function isPercentage(): bool { return $this->unit === '%'; } @@ -170,7 +170,7 @@ class PerfData * * @return bool True in case it's in packets */ - public function isPackets() + public function isPackets(): bool { return $this->unit === 'packets'; } @@ -180,7 +180,7 @@ class PerfData * * @return bool */ - public function isLumens() + public function isLumens(): bool { return $this->unit === 'lm'; } @@ -190,7 +190,7 @@ class PerfData * * @return bool */ - public function isDecibelMilliWatts() + public function isDecibelMilliWatts(): bool { return $this->unit === 'dBm'; } @@ -200,7 +200,7 @@ class PerfData * * @return bool */ - public function isBits() + public function isBits(): bool { return $this->unit === 'b'; } @@ -210,7 +210,7 @@ class PerfData * * @return bool True in case it's in bytes, otherwise False */ - public function isBytes() + public function isBytes(): bool { return $this->unit === 'B'; } @@ -220,7 +220,7 @@ class PerfData * * @return bool */ - public function isWattHours() + public function isWattHours(): bool { return $this->unit === 'Wh'; } @@ -230,7 +230,7 @@ class PerfData * * @return bool */ - public function isWatts() + public function isWatts(): bool { return $this->unit === 'W'; } @@ -240,7 +240,7 @@ class PerfData * * @return bool */ - public function isAmperes() + public function isAmperes(): bool { return $this->unit === 'A'; } @@ -250,7 +250,7 @@ class PerfData * * @return bool */ - public function isAmpSeconds() + public function isAmpSeconds(): bool { return $this->unit === 'As'; } @@ -260,7 +260,7 @@ class PerfData * * @return bool */ - public function isVolts() + public function isVolts(): bool { return $this->unit === 'V'; } @@ -270,7 +270,7 @@ class PerfData * * @return bool */ - public function isOhms() + public function isOhms(): bool { return $this->unit === 'O'; } @@ -280,7 +280,7 @@ class PerfData * * @return bool */ - public function isGrams() + public function isGrams(): bool { return $this->unit === 'g'; } @@ -290,7 +290,7 @@ class PerfData * * @return bool */ - public function isLiters() + public function isLiters(): bool { return $this->unit === 'l'; } @@ -300,7 +300,7 @@ class PerfData * * @return bool True in case it's a counter, otherwise False */ - public function isCounter() + public function isCounter(): bool { return $this->unit === 'c'; } @@ -310,7 +310,7 @@ class PerfData * * @return bool True when the perfdata is visualizable */ - public function isVisualizable() + public function isVisualizable(): bool { return isset($this->minValue) && isset($this->maxValue) && isset($this->value); } @@ -318,7 +318,7 @@ class PerfData /** * Return this perfomance data's label */ - public function getLabel() + public function getLabel(): string { return $this->label; } @@ -336,7 +336,7 @@ class PerfData /** * Return the unit as a string * - * @return string + * @return ?string */ public function getUnit() { @@ -371,7 +371,7 @@ class PerfData * * @return ThresholdRange */ - public function getWarningThreshold() + public function getWarningThreshold(): ThresholdRange { return $this->warningThreshold; } @@ -381,7 +381,7 @@ class PerfData * * @return ThresholdRange */ - public function getCriticalThreshold() + public function getCriticalThreshold(): ThresholdRange { return $this->criticalThreshold; } @@ -389,7 +389,7 @@ class PerfData /** * Return the minimum value or null if it is not available * - * @return null|string + * @return ?float */ public function getMinimumValue() { @@ -460,7 +460,7 @@ class PerfData } } - protected function calculatePieChartData() + protected function calculatePieChartData(): array { $rawValue = $this->getValue(); $minValue = $this->getMinimumValue() !== null ? $this->getMinimumValue() : 0; @@ -482,7 +482,7 @@ class PerfData } - public function asInlinePie() + public function asInlinePie(): InlinePie { if (! $this->isVisualizable()) { throw new LogicException('Cannot calculate piechart data for unvisualizable perfdata entry.'); @@ -560,7 +560,7 @@ class PerfData * * @return string */ - public function formatLabel($html = false) + public function formatLabel(bool $html = false): string { return sprintf( $html ? '%s %s (%s%%)' : '%s %s (%s%%)', @@ -570,7 +570,7 @@ class PerfData ); } - public function toArray() + public function toArray(): array { return array( 'label' => $this->getLabel(), @@ -591,7 +591,7 @@ class PerfData * * @return int */ - public function getState() + public function getState(): int { if ($this->value === null) { return ServiceStates::UNKNOWN; @@ -617,7 +617,7 @@ class PerfData * * @return bool */ - public function worseThan(PerfData $rhs) + public function worseThan(PerfData $rhs): bool { if (($state = $this->getState()) === ($rhsState = $rhs->getState())) { return $this->getPercentage() > $rhs->getPercentage(); diff --git a/library/Icingadb/Util/PerfDataFormat.php b/library/Icingadb/Util/PerfDataFormat.php index 4789dd53..5ff11fa5 100644 --- a/library/Icingadb/Util/PerfDataFormat.php +++ b/library/Icingadb/Util/PerfDataFormat.php @@ -56,7 +56,7 @@ class PerfDataFormat protected static $secondPrefix = [-3 => 'ns', -2 => 'µs', -1 => 'ms', 's']; - public static function getInstance() + public static function getInstance(): self { if (self::$instance === null) { self::$instance = new PerfDataFormat(); @@ -65,57 +65,57 @@ class PerfDataFormat return self::$instance; } - public static function bits($value) + public static function bits($value): string { return self::formatForUnits($value, self::$bitPrefix, self::$generalBase); } - public static function bytes($value) + public static function bytes($value): string { return self::formatForUnits($value, self::$bytePrefix, self::$generalBase); } - public static function wattHours($value) + public static function wattHours($value): string { return self::formatForUnits($value, self::$wattHourPrefix, self::$generalBase); } - public static function watts($value) + public static function watts($value): string { return self::formatForUnits($value, self::$wattPrefix, self::$generalBase); } - public static function amperes($value) + public static function amperes($value): string { return self::formatForUnits($value, self::$amperePrefix, self::$generalBase); } - public static function ampereSeconds($value) + public static function ampereSeconds($value): string { return self::formatForUnits($value, self::$ampSecondPrefix, self::$generalBase); } - public static function volts($value) + public static function volts($value): string { return self::formatForUnits($value, self::$voltPrefix, self::$generalBase); } - public static function ohms($value) + public static function ohms($value): string { return self::formatForUnits($value, self::$ohmPrefix, self::$generalBase); } - public static function grams($value) + public static function grams($value): string { return self::formatForUnits($value, self::$gramPrefix, self::$generalBase); } - public static function liters($value) + public static function liters($value): string { return self::formatForUnits($value, self::$literPrefix, self::$generalBase); } - public static function seconds($value) + public static function seconds($value): string { $absValue = abs($value); @@ -130,7 +130,7 @@ class PerfDataFormat return sprintf('%0.2f d', $value / 86400); } - protected static function formatForUnits($value, &$units, $base) + protected static function formatForUnits($value, array &$units, int $base): string { $sign = ''; if ($value < 0) { diff --git a/library/Icingadb/Util/PerfDataSet.php b/library/Icingadb/Util/PerfDataSet.php index 63a73cb3..921bb56e 100644 --- a/library/Icingadb/Util/PerfDataSet.php +++ b/library/Icingadb/Util/PerfDataSet.php @@ -35,7 +35,7 @@ class PerfDataSet implements IteratorAggregate * * @param string $perfdataStr A space separated list of label/value pairs */ - protected function __construct($perfdataStr) + protected function __construct(string $perfdataStr) { if (($perfdataStr = trim($perfdataStr)) !== '') { $this->perfdataStr = $perfdataStr; @@ -48,7 +48,7 @@ class PerfDataSet implements IteratorAggregate * * @return ArrayIterator */ - public function getIterator() + public function getIterator(): ArrayIterator { return new ArrayIterator($this->asArray()); } @@ -60,7 +60,7 @@ class PerfDataSet implements IteratorAggregate * * @return PerfDataSet */ - public static function fromString($perfdataStr) + public static function fromString(string $perfdataStr): self { return new static($perfdataStr); } @@ -70,7 +70,7 @@ class PerfDataSet implements IteratorAggregate * * @return array */ - public function asArray() + public function asArray(): array { return $this->perfdata; } @@ -95,7 +95,7 @@ class PerfDataSet implements IteratorAggregate * * @return string The label found */ - protected function readLabel() + protected function readLabel(): string { $this->skipSpaces(); if (in_array($this->perfdataStr[$this->parserPos], array('"', "'"))) { @@ -122,7 +122,7 @@ class PerfDataSet implements IteratorAggregate * * @return string */ - protected function readUntil($stopChar) + protected function readUntil(string $stopChar): string { $start = $this->parserPos; while ($this->parserPos < strlen($this->perfdataStr) && $this->perfdataStr[$this->parserPos] !== $stopChar) { diff --git a/library/Icingadb/Util/PluginOutput.php b/library/Icingadb/Util/PluginOutput.php index 4d822636..8b1f82d0 100644 --- a/library/Icingadb/Util/PluginOutput.php +++ b/library/Icingadb/Util/PluginOutput.php @@ -193,7 +193,7 @@ class PluginOutput extends HtmlString * @todo Do we really need to create a DOM here? Or is a preg_replace like we do it for text also feasible? * @return string */ - protected function processHtml($html) + protected function processHtml(string $html): string { $pattern = '/[([](OK|WARNING|CRITICAL|UNKNOWN|UP|DOWN)[)\]]/'; $doc = new DOMDocument(); diff --git a/library/Icingadb/Util/ThresholdRange.php b/library/Icingadb/Util/ThresholdRange.php index ed7d1c12..c92842d0 100644 --- a/library/Icingadb/Util/ThresholdRange.php +++ b/library/Icingadb/Util/ThresholdRange.php @@ -44,7 +44,7 @@ class ThresholdRange * * @return ThresholdRange */ - public static function fromString($rawRange) + public static function fromString(string $rawRange): self { $range = new static(); $range->raw = $rawRange; @@ -92,7 +92,7 @@ class ThresholdRange * * @return $this */ - public function setMin($min) + public function setMin(float $min): self { $this->min = $min; return $this; @@ -115,7 +115,7 @@ class ThresholdRange * * @return $this */ - public function setMax($max) + public function setMax(float $max): self { $this->max = $max; return $this; @@ -138,7 +138,7 @@ class ThresholdRange * * @return $this */ - public function setInverted($inverted = true) + public function setInverted(bool $inverted = true): self { $this->inverted = $inverted; return $this; @@ -149,7 +149,7 @@ class ThresholdRange * * @return bool */ - public function isInverted() + public function isInverted(): bool { return $this->inverted; } @@ -161,7 +161,7 @@ class ThresholdRange * * @return bool */ - public function contains($value) + public function contains(float $value): bool { return (bool) ($this->inverted ^ ( ($this->min === null || $this->min <= $value) && ($this->max === null || $this->max >= $value) diff --git a/library/Icingadb/Web/Control/ProblemToggle.php b/library/Icingadb/Web/Control/ProblemToggle.php index 9c564d68..c5aed82d 100644 --- a/library/Icingadb/Web/Control/ProblemToggle.php +++ b/library/Icingadb/Web/Control/ProblemToggle.php @@ -32,7 +32,7 @@ class ProblemToggle extends CompatForm * * @return $this */ - public function setIdProtector($protector) + public function setIdProtector(callable $protector): self { $this->protector = $protector; @@ -44,7 +44,7 @@ class ProblemToggle extends CompatForm * * @return bool */ - public function isChecked() + public function isChecked(): bool { $this->ensureAssembled(); diff --git a/library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php b/library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php index 22be30dd..741c04c7 100644 --- a/library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php +++ b/library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Icingadb\Web\Control\SearchBar; +use Generator; use Icinga\Module\Icingadb\Common\Auth; use Icinga\Module\Icingadb\Common\Database; use Icinga\Module\Icingadb\Model\Behavior\ReRoute; @@ -61,7 +62,7 @@ class ObjectSuggestions extends Suggestions * * @return $this */ - public function setModel($model) + public function setModel($model): self { if (is_string($model)) { $model = new $model(); @@ -77,8 +78,14 @@ class ObjectSuggestions extends Suggestions * * @return Model */ - public function getModel() + public function getModel(): Model { + if ($this->model === null) { + throw new \LogicException( + 'You are accessing an unset property. Please make sure to set it beforehand.' + ); + } + return $this->model; } @@ -216,7 +223,7 @@ class ObjectSuggestions extends Suggestions * * @return Select */ - protected function queryCustomvarConfig($searchTerm) + protected function queryCustomvarConfig(string $searchTerm): Select { $customVars = CustomvarFlat::on($this->getDb()); $tableName = $customVars->getModel()->getTableName(); @@ -260,9 +267,9 @@ class ObjectSuggestions extends Suggestions * @param Model $model * @param Resolver $resolver * - * @return \Generator + * @return Generator */ - public static function collectFilterColumns(Model $model, Resolver $resolver = null) + public static function collectFilterColumns(Model $model, Resolver $resolver = null): Generator { if ($resolver === null) { $resolver = new Resolver(); diff --git a/library/Icingadb/Web/Control/ViewModeSwitcher.php b/library/Icingadb/Web/Control/ViewModeSwitcher.php index 54b4ad06..1ff30a7a 100644 --- a/library/Icingadb/Web/Control/ViewModeSwitcher.php +++ b/library/Icingadb/Web/Control/ViewModeSwitcher.php @@ -51,7 +51,7 @@ class ViewModeSwitcher extends Form * * @return string */ - public function getDefaultViewMode() + public function getDefaultViewMode(): string { return $this->defaultViewMode ?: static::DEFAULT_VIEW_MODE; } @@ -63,7 +63,7 @@ class ViewModeSwitcher extends Form * * @return $this */ - public function setDefaultViewMode($defaultViewMode) + public function setDefaultViewMode(string $defaultViewMode): self { $this->defaultViewMode = $defaultViewMode; @@ -75,7 +75,7 @@ class ViewModeSwitcher extends Form * * @return string */ - public function getViewModeParam() + public function getViewModeParam(): string { return $this->viewModeParam; } @@ -87,7 +87,7 @@ class ViewModeSwitcher extends Form * * @return $this */ - public function setViewModeParam($viewModeParam) + public function setViewModeParam(string $viewModeParam): self { $this->viewModeParam = $viewModeParam; @@ -99,7 +99,7 @@ class ViewModeSwitcher extends Form * * @return string */ - public function getViewMode() + public function getViewMode(): string { return $this->getValue($this->getViewModeParam(), $this->getDefaultViewMode()); } @@ -111,7 +111,7 @@ class ViewModeSwitcher extends Form * * @return $this */ - public function setIdProtector($protector) + public function setIdProtector(callable $protector): self { $this->protector = $protector; diff --git a/library/Icingadb/Web/Controller.php b/library/Icingadb/Web/Controller.php index aee01874..26fa950c 100644 --- a/library/Icingadb/Web/Controller.php +++ b/library/Icingadb/Web/Controller.php @@ -50,7 +50,7 @@ class Controller extends CompatController use Auth; use Database; - /** @var Filter Filter from query string parameters */ + /** @var Filter\Rule Filter from query string parameters */ private $filter; /** @var string|null */ @@ -64,7 +64,7 @@ class Controller extends CompatController * * @return Filter\Rule */ - public function getFilter() + public function getFilter(): Filter\Rule { if ($this->filter === null) { $this->filter = QueryString::parse((string) $this->params); @@ -80,7 +80,7 @@ class Controller extends CompatController * * @return LimitControl */ - public function createLimitControl() + public function createLimitControl(): LimitControl { $limitControl = new LimitControl(Url::fromRequest()); $limitControl->setDefaultLimit($this->getPageSize(null)); @@ -97,7 +97,7 @@ class Controller extends CompatController * * @return PaginationControl */ - public function createPaginationControl(Paginatable $paginatable) + public function createPaginationControl(Paginatable $paginatable): PaginationControl { $paginationControl = new PaginationControl($paginatable, Url::fromRequest()); $paginationControl->setDefaultPageSize($this->getPageSize(null)); @@ -119,7 +119,7 @@ class Controller extends CompatController * * @return SortControl */ - public function createSortControl(Query $query, array $columns) + public function createSortControl(Query $query, array $columns): SortControl { $default = (array) $query->getModel()->getDefaultSort(); $normalized = []; @@ -152,7 +152,7 @@ class Controller extends CompatController * * @return SearchBar */ - public function createSearchBar(Query $query, array $preserveParams = null) + public function createSearchBar(Query $query, array $preserveParams = null): SearchBar { $requestUrl = Url::fromRequest(); $redirectUrl = $preserveParams !== null @@ -253,7 +253,7 @@ class Controller extends CompatController * * @return SearchEditor */ - public function createSearchEditor(Query $query, array $preserveParams = null) + public function createSearchEditor(Query $query, array $preserveParams = null): SearchEditor { $requestUrl = Url::fromRequest(); $redirectUrl = Url::fromPath('icingadb/' . $this->getRequest()->getControllerName()); @@ -333,7 +333,7 @@ class Controller extends CompatController * * @return ContinueWith */ - public function createContinueWith(Url $detailsUrl, SearchBar $searchBar) + public function createContinueWith(Url $detailsUrl, SearchBar $searchBar): ContinueWith { $continueWith = new ContinueWith($detailsUrl, [$searchBar, 'getFilter']); $continueWith->setTitle(t('Show bulk processing actions for all filtered results')); @@ -353,14 +353,15 @@ class Controller extends CompatController * * @param PaginationControl $paginationControl * @param LimitControl $limitControl + * @param bool $verticalPagination * * @return ViewModeSwitcher */ public function createViewModeSwitcher( PaginationControl $paginationControl, LimitControl $limitControl, - $verticalPagination = false - ) { + bool $verticalPagination = false + ): ViewModeSwitcher { $viewModeSwitcher = new ViewModeSwitcher(); $viewModeSwitcher->setIdProtector([$this->getRequest(), 'protectId']); @@ -488,6 +489,8 @@ class Controller extends CompatController * Process a search request * * @param Query $query + * + * @return void */ public function handleSearchRequest(Query $query) { @@ -519,7 +522,7 @@ class Controller extends CompatController * * @throws SecurityException */ - public function assertRouteAccess($name = null) + public function assertRouteAccess(string $name = null) { if (! $name) { $name = $this->getRequest()->getControllerName(); @@ -786,7 +789,7 @@ class Controller extends CompatController return parent::addContent($content); } - public function filter(Query $query, Filter\Rule $filter = null) + public function filter(Query $query, Filter\Rule $filter = null): self { if ($this->format !== 'sql' || $this->hasPermission('config/authentication/roles/show')) { $this->applyRestrictions($query); diff --git a/library/Icingadb/Web/Navigation/Action.php b/library/Icingadb/Web/Navigation/Action.php index 2922550c..b23bdbf6 100644 --- a/library/Icingadb/Web/Navigation/Action.php +++ b/library/Icingadb/Web/Navigation/Action.php @@ -85,7 +85,7 @@ class Action extends NavigationItem /** * Get the filter to use when being asked whether to render this action * - * @return string + * @return ?string */ public function getFilter() { diff --git a/library/Icingadb/Web/Navigation/Renderer/HostProblemsBadge.php b/library/Icingadb/Web/Navigation/Renderer/HostProblemsBadge.php index be062c60..07a77c88 100644 --- a/library/Icingadb/Web/Navigation/Renderer/HostProblemsBadge.php +++ b/library/Icingadb/Web/Navigation/Renderer/HostProblemsBadge.php @@ -7,6 +7,7 @@ namespace Icinga\Module\Icingadb\Web\Navigation\Renderer; use Icinga\Module\Icingadb\Common\Auth; use Icinga\Module\Icingadb\Common\Links; use Icinga\Module\Icingadb\Model\HoststateSummary; +use ipl\Web\Url; class HostProblemsBadge extends ProblemsBadge { @@ -20,7 +21,7 @@ class HostProblemsBadge extends ProblemsBadge return $summary->first()->hosts_down_unhandled; } - protected function getUrl() + protected function getUrl(): Url { return Links::hosts()->setParams(['host.state.is_problem' => 'y', 'sort' => 'host.state.severity desc']); } diff --git a/library/Icingadb/Web/Navigation/Renderer/ProblemsBadge.php b/library/Icingadb/Web/Navigation/Renderer/ProblemsBadge.php index 228adf26..b7386c03 100644 --- a/library/Icingadb/Web/Navigation/Renderer/ProblemsBadge.php +++ b/library/Icingadb/Web/Navigation/Renderer/ProblemsBadge.php @@ -67,7 +67,7 @@ abstract class ProblemsBadge extends NavigationItemRenderer * * @return $this */ - public function setState($state) + public function setState(string $state): self { $this->state = $state; @@ -79,8 +79,14 @@ abstract class ProblemsBadge extends NavigationItemRenderer * * @return string */ - public function getState() + public function getState(): string { + if ($this->state === null) { + throw new \LogicException( + 'You are accessing an unset property. Please make sure to set it beforehand.' + ); + } + return $this->state; } @@ -91,7 +97,7 @@ abstract class ProblemsBadge extends NavigationItemRenderer * * @return $this */ - public function setTitle($title) + public function setTitle(string $title): self { $this->title = $title; @@ -103,12 +109,18 @@ abstract class ProblemsBadge extends NavigationItemRenderer * * @return string */ - public function getTitle() + public function getTitle(): string { + if ($this->title === null) { + throw new \LogicException( + 'You are accessing an unset property. Please make sure to set it beforehand.' + ); + } + return $this->title; } - public function render(NavigationItem $item = null) + public function render(NavigationItem $item = null): string { if ($item === null) { $item = $this->getItem(); diff --git a/library/Icingadb/Web/Navigation/Renderer/ServiceProblemsBadge.php b/library/Icingadb/Web/Navigation/Renderer/ServiceProblemsBadge.php index 8006e2e0..3460885e 100644 --- a/library/Icingadb/Web/Navigation/Renderer/ServiceProblemsBadge.php +++ b/library/Icingadb/Web/Navigation/Renderer/ServiceProblemsBadge.php @@ -7,6 +7,7 @@ namespace Icinga\Module\Icingadb\Web\Navigation\Renderer; use Icinga\Module\Icingadb\Common\Auth; use Icinga\Module\Icingadb\Common\Links; use Icinga\Module\Icingadb\Model\ServicestateSummary; +use ipl\Web\Url; class ServiceProblemsBadge extends ProblemsBadge { @@ -20,7 +21,7 @@ class ServiceProblemsBadge extends ProblemsBadge return $summary->first()->services_critical_unhandled; } - protected function getUrl() + protected function getUrl(): Url { return Links::services() ->setParams(['service.state.is_problem' => 'y', 'sort' => 'service.state.severity desc']); diff --git a/library/Icingadb/Widget/AttemptBall.php b/library/Icingadb/Widget/AttemptBall.php index fce7ac97..e57c59c7 100644 --- a/library/Icingadb/Widget/AttemptBall.php +++ b/library/Icingadb/Widget/AttemptBall.php @@ -20,7 +20,7 @@ class AttemptBall extends BaseHtmlElement * * @param bool $taken Whether the attempt was taken */ - public function __construct($taken = false) + public function __construct(bool $taken = false) { if ($taken) { $this->addAttributes(['class' => 'ball-size-s taken']); diff --git a/library/Icingadb/Widget/CheckAttempt.php b/library/Icingadb/Widget/CheckAttempt.php index 80fddd9b..cf12de34 100644 --- a/library/Icingadb/Widget/CheckAttempt.php +++ b/library/Icingadb/Widget/CheckAttempt.php @@ -28,7 +28,7 @@ class CheckAttempt extends BaseHtmlElement * @param int $attempt Current check attempt * @param int $maxAttempts Max check attempts */ - public function __construct($attempt, $maxAttempts) + public function __construct(int $attempt, int $maxAttempts) { $this->attempt = $attempt; $this->maxAttempts = $maxAttempts; diff --git a/library/Icingadb/Widget/Detail/CommentDetail.php b/library/Icingadb/Widget/Detail/CommentDetail.php index e406b7cc..3ca19e62 100644 --- a/library/Icingadb/Widget/Detail/CommentDetail.php +++ b/library/Icingadb/Widget/Detail/CommentDetail.php @@ -6,6 +6,7 @@ namespace Icinga\Module\Icingadb\Widget\Detail; use Icinga\Module\Icingadb\Common\Auth; use Icinga\Module\Icingadb\Common\Links; +use Icinga\Module\Icingadb\Model\Comment; use Icinga\Module\Icingadb\Widget\MarkdownText; use Icinga\Module\Icingadb\Forms\Command\Object\DeleteCommentForm; use ipl\Web\Widget\TimeUntil; @@ -22,12 +23,12 @@ class CommentDetail extends BaseHtmlElement protected $tag = 'div'; - public function __construct($comment) + public function __construct(Comment $comment) { $this->comment = $comment; } - protected function createComment() + protected function createComment(): array { return [ Html::tag('h2', t('Comment')), @@ -35,7 +36,7 @@ class CommentDetail extends BaseHtmlElement ]; } - protected function createDetails() + protected function createDetails(): array { $details = []; diff --git a/library/Icingadb/Widget/Detail/DowntimeDetail.php b/library/Icingadb/Widget/Detail/DowntimeDetail.php index b22d909c..f751e806 100644 --- a/library/Icingadb/Widget/Detail/DowntimeDetail.php +++ b/library/Icingadb/Widget/Detail/DowntimeDetail.php @@ -57,7 +57,7 @@ class DowntimeDetail extends BaseHtmlElement protected $tag = 'div'; - public function __construct($downtime) + public function __construct(Downtime $downtime) { $this->downtime = $downtime; @@ -90,7 +90,7 @@ class DowntimeDetail extends BaseHtmlElement ->setAction($action->getAbsoluteUrl()); } - protected function createTimeline() + protected function createTimeline(): DowntimeCard { return new DowntimeCard($this->downtime); } diff --git a/library/Icingadb/Widget/Detail/HostDetail.php b/library/Icingadb/Widget/Detail/HostDetail.php index 1404afe9..b412069b 100644 --- a/library/Icingadb/Widget/Detail/HostDetail.php +++ b/library/Icingadb/Widget/Detail/HostDetail.php @@ -5,6 +5,7 @@ namespace Icinga\Module\Icingadb\Widget\Detail; use Icinga\Module\Icingadb\Hook\ExtensionHook\ObjectDetailExtensionHook; +use Icinga\Module\Icingadb\Model\ServicestateSummary; use Icinga\Module\Icingadb\Widget\EmptyState; use ipl\Html\Html; use ipl\Stdlib\Filter; @@ -13,14 +14,14 @@ class HostDetail extends ObjectDetail { protected $serviceSummary; - public function __construct($object, $serviceSummary) + public function __construct($object, ServicestateSummary $serviceSummary) { parent::__construct($object); $this->serviceSummary = $serviceSummary; } - protected function createServiceStatistics() + protected function createServiceStatistics(): array { if ($this->serviceSummary->services_total > 0) { $services = new ServiceStatistics($this->serviceSummary); diff --git a/library/Icingadb/Widget/Detail/HostStatistics.php b/library/Icingadb/Widget/Detail/HostStatistics.php index d46bca15..53423bef 100644 --- a/library/Icingadb/Widget/Detail/HostStatistics.php +++ b/library/Icingadb/Widget/Detail/HostStatistics.php @@ -8,6 +8,7 @@ use Icinga\Chart\Donut; use Icinga\Data\Filter\Filter; use Icinga\Module\Icingadb\Common\Links; use Icinga\Module\Icingadb\Widget\HostStateBadges; +use ipl\Html\ValidHtml; use ipl\Web\Widget\VerticalKeyValue; use ipl\Html\HtmlString; use ipl\Web\Filter\QueryString; @@ -22,7 +23,7 @@ class HostStatistics extends ObjectStatistics $this->summary = $summary; } - protected function createDonut() + protected function createDonut(): ValidHtml { $donut = (new Donut()) ->addSlice($this->summary->hosts_up, ['class' => 'slice-state-ok']) @@ -33,7 +34,7 @@ class HostStatistics extends ObjectStatistics return HtmlString::create($donut->render()); } - protected function createTotal() + protected function createTotal(): ValidHtml { $url = Links::hosts(); if ($this->hasBaseFilter()) { @@ -49,7 +50,7 @@ class HostStatistics extends ObjectStatistics ); } - protected function createBadges() + protected function createBadges(): ValidHtml { $badges = new HostStateBadges($this->summary); if ($this->hasBaseFilter()) { diff --git a/library/Icingadb/Widget/Detail/MultiselectQuickActions.php b/library/Icingadb/Widget/Detail/MultiselectQuickActions.php index 692f33ed..b945cc00 100644 --- a/library/Icingadb/Widget/Detail/MultiselectQuickActions.php +++ b/library/Icingadb/Widget/Detail/MultiselectQuickActions.php @@ -165,7 +165,7 @@ class MultiselectQuickActions extends BaseHtmlElement } } - protected function assembleAction($action, $label, $icon, $title) + protected function assembleAction(string $action, string $label, string $icon, string $title) { $link = Html::tag( 'a', @@ -185,7 +185,7 @@ class MultiselectQuickActions extends BaseHtmlElement $this->add(Html::tag('li', $link)); } - protected function getLink($action) + protected function getLink(string $action): string { return Url::fromPath("icingadb/{$this->type}s/$action") ->setQueryString(QueryString::render($this->getBaseFilter())) diff --git a/library/Icingadb/Widget/Detail/ObjectDetail.php b/library/Icingadb/Widget/Detail/ObjectDetail.php index 34a3511e..8ec5d879 100644 --- a/library/Icingadb/Widget/Detail/ObjectDetail.php +++ b/library/Icingadb/Widget/Detail/ObjectDetail.php @@ -138,7 +138,7 @@ class ObjectDetail extends BaseHtmlElement ]; } - protected function createCheckStatistics() + protected function createCheckStatistics(): array { return [ Html::tag('h2', t('Check Statistics')), @@ -146,7 +146,7 @@ class ObjectDetail extends BaseHtmlElement ]; } - protected function createComments() + protected function createComments(): array { if ($this->objectType === 'host') { $link = HostLinks::comments($this->object); @@ -178,7 +178,7 @@ class ObjectDetail extends BaseHtmlElement return $content; } - protected function createCustomVars() + protected function createCustomVars(): array { $content = [Html::tag('h2', t('Custom Variables'))]; @@ -195,7 +195,7 @@ class ObjectDetail extends BaseHtmlElement return $content; } - protected function createDowntimes() + protected function createDowntimes(): array { if ($this->objectType === 'host') { $link = HostLinks::downtimes($this->object); @@ -227,7 +227,7 @@ class ObjectDetail extends BaseHtmlElement return $content; } - protected function createGroups() + protected function createGroups(): array { $groups = [Html::tag('h2', t('Groups'))]; @@ -314,7 +314,7 @@ class ObjectDetail extends BaseHtmlElement return $content; } - protected function createNotifications() + protected function createNotifications(): array { list($users, $usergroups) = $this->getUsersAndUsergroups(); @@ -347,7 +347,7 @@ class ObjectDetail extends BaseHtmlElement ]; } - protected function createPerformanceData() + protected function createPerformanceData(): array { $content[] = Html::tag('h2', t('Performance Data')); @@ -364,7 +364,7 @@ class ObjectDetail extends BaseHtmlElement return $content; } - protected function createPluginOutput() + protected function createPluginOutput(): array { if (empty($this->object->state->output) && empty($this->object->state->long_output)) { $pluginOutput = new EmptyState(t('Output unavailable.')); @@ -386,7 +386,7 @@ class ObjectDetail extends BaseHtmlElement ]; } - protected function createExtensions() + protected function createExtensions(): array { $extensions = ObjectDetailExtensionHook::loadExtensions($this->object); @@ -457,7 +457,7 @@ class ObjectDetail extends BaseHtmlElement return $extensions; } - protected function createFeatureToggles() + protected function createFeatureToggles(): array { $form = new ToggleObjectFeaturesForm($this->object); @@ -473,7 +473,7 @@ class ObjectDetail extends BaseHtmlElement ]; } - protected function getUsersAndUsergroups() + protected function getUsersAndUsergroups(): array { $users = []; $usergroups = []; diff --git a/library/Icingadb/Widget/Detail/ObjectStatistics.php b/library/Icingadb/Widget/Detail/ObjectStatistics.php index 34eb8e1b..2142c8b6 100644 --- a/library/Icingadb/Widget/Detail/ObjectStatistics.php +++ b/library/Icingadb/Widget/Detail/ObjectStatistics.php @@ -7,6 +7,7 @@ namespace Icinga\Module\Icingadb\Widget\Detail; use Icinga\Module\Icingadb\Common\BaseFilter; use ipl\Html\BaseHtmlElement; use ipl\Html\Html; +use ipl\Html\ValidHtml; abstract class ObjectStatistics extends BaseHtmlElement { @@ -16,11 +17,11 @@ abstract class ObjectStatistics extends BaseHtmlElement protected $defaultAttributes = ['class' => 'object-statistics']; - abstract protected function createDonut(); + abstract protected function createDonut(): ValidHtml; - abstract protected function createTotal(); + abstract protected function createTotal(): ValidHtml; - abstract protected function createBadges(); + abstract protected function createBadges(): ValidHtml; protected function assemble() { diff --git a/library/Icingadb/Widget/Detail/ObjectsDetail.php b/library/Icingadb/Widget/Detail/ObjectsDetail.php index f978a1e0..18b55667 100644 --- a/library/Icingadb/Widget/Detail/ObjectsDetail.php +++ b/library/Icingadb/Widget/Detail/ObjectsDetail.php @@ -9,10 +9,14 @@ use Icinga\Module\Icingadb\Common\BaseFilter; use Icinga\Module\Icingadb\Common\Links; use Icinga\Module\Icingadb\Forms\Command\Object\ToggleObjectFeaturesForm; use Icinga\Module\Icingadb\Hook\ExtensionHook\ObjectsDetailExtensionHook; +use Icinga\Module\Icingadb\Model\HoststateSummary; +use Icinga\Module\Icingadb\Model\ServicestateSummary; use Icinga\Module\Icingadb\Util\FeatureStatus; use Icinga\Module\Icingadb\Widget\EmptyState; use Icinga\Module\Icingadb\Widget\HostStateBadges; use Icinga\Module\Icingadb\Widget\ServiceStateBadges; +use ipl\Html\HtmlElement; +use ipl\Orm\Query; use ipl\Web\Widget\VerticalKeyValue; use ipl\Html\BaseHtmlElement; use ipl\Html\Html; @@ -34,14 +38,21 @@ class ObjectsDetail extends BaseHtmlElement protected $tag = 'div'; - public function __construct($type, $summary, $query) + /** + * Construct an object detail summary widget + * + * @param string $type + * @param HoststateSummary|ServicestateSummary $summary + * @param Query $query + */ + public function __construct(string $type, $summary, Query $query) { $this->summary = $summary; $this->query = $query; $this->type = $type; } - protected function createChart() + protected function createChart(): BaseHtmlElement { $content = Html::tag('div', ['class' => 'multiselect-summary']); @@ -90,7 +101,7 @@ class ObjectsDetail extends BaseHtmlElement return $content; } - protected function createComments() + protected function createComments(): array { $content = [Html::tag('h2', t('Comments'))]; @@ -109,7 +120,7 @@ class ObjectsDetail extends BaseHtmlElement return $content; } - protected function createDowntimes() + protected function createDowntimes(): array { $content = [Html::tag('h2', t('Downtimes'))]; @@ -128,7 +139,7 @@ class ObjectsDetail extends BaseHtmlElement return $content; } - protected function createFeatureToggles() + protected function createFeatureToggles(): array { $form = new ToggleObjectFeaturesForm(new FeatureStatus($this->type, $this->summary)); @@ -152,7 +163,7 @@ class ObjectsDetail extends BaseHtmlElement ]; } - protected function createExtensions() + protected function createExtensions(): array { return ObjectsDetailExtensionHook::loadExtensions( $this->type, @@ -161,7 +172,7 @@ class ObjectsDetail extends BaseHtmlElement ); } - protected function createSummary() + protected function createSummary(): array { return [ Html::tag('h2', t('Summary')), diff --git a/library/Icingadb/Widget/Detail/PerfDataTable.php b/library/Icingadb/Widget/Detail/PerfDataTable.php index a554fb53..639fb6b9 100644 --- a/library/Icingadb/Widget/Detail/PerfDataTable.php +++ b/library/Icingadb/Widget/Detail/PerfDataTable.php @@ -38,10 +38,8 @@ class PerfDataTable extends Table * @param string $perfdataStr The perfdata string * @param int $limit Max labels to show; 0 for no limit * @param string $color The color indicating the perfdata state - * - * @return string */ - public function __construct($perfdataStr, $limit = 0, $color = PerfData::PERFDATA_OK) + public function __construct(string $perfdataStr, int $limit = 0, string $color = PerfData::PERFDATA_OK) { $this->perfdataStr = $perfdataStr; $this->limit = $limit; diff --git a/library/Icingadb/Widget/Detail/QuickActions.php b/library/Icingadb/Widget/Detail/QuickActions.php index 088675ba..6ce90cd6 100644 --- a/library/Icingadb/Widget/Detail/QuickActions.php +++ b/library/Icingadb/Widget/Detail/QuickActions.php @@ -117,7 +117,7 @@ class QuickActions extends BaseHtmlElement } } - protected function assembleAction($action, $label, $icon, $title) + protected function assembleAction(string $action, string $label, string $icon, string $title) { $link = Html::tag( 'a', diff --git a/library/Icingadb/Widget/Detail/ServiceStatistics.php b/library/Icingadb/Widget/Detail/ServiceStatistics.php index 989ae9f9..0f570b44 100644 --- a/library/Icingadb/Widget/Detail/ServiceStatistics.php +++ b/library/Icingadb/Widget/Detail/ServiceStatistics.php @@ -8,6 +8,7 @@ use Icinga\Chart\Donut; use Icinga\Data\Filter\Filter; use Icinga\Module\Icingadb\Common\Links; use Icinga\Module\Icingadb\Widget\ServiceStateBadges; +use ipl\Html\ValidHtml; use ipl\Web\Widget\VerticalKeyValue; use ipl\Html\HtmlString; use ipl\Web\Filter\QueryString; @@ -22,7 +23,7 @@ class ServiceStatistics extends ObjectStatistics $this->summary = $summary; } - protected function createDonut() + protected function createDonut(): ValidHtml { $donut = (new Donut()) ->addSlice($this->summary->services_ok, ['class' => 'slice-state-ok']) @@ -37,7 +38,7 @@ class ServiceStatistics extends ObjectStatistics return HtmlString::create($donut->render()); } - protected function createTotal() + protected function createTotal(): ValidHtml { $url = Links::services(); if ($this->hasBaseFilter()) { @@ -53,7 +54,7 @@ class ServiceStatistics extends ObjectStatistics ); } - protected function createBadges() + protected function createBadges(): ValidHtml { $badges = new ServiceStateBadges($this->summary); if ($this->hasBaseFilter()) { diff --git a/library/Icingadb/Widget/Detail/UserDetail.php b/library/Icingadb/Widget/Detail/UserDetail.php index 4753552c..5ae79617 100644 --- a/library/Icingadb/Widget/Detail/UserDetail.php +++ b/library/Icingadb/Widget/Detail/UserDetail.php @@ -34,7 +34,7 @@ class UserDetail extends BaseHtmlElement $this->user = $user; } - protected function createCustomVars() + protected function createCustomVars(): array { $content = [new HtmlElement('h2', null, Text::create(t('Custom Variables')))]; $flattenedVars = $this->user->customvar_flat; @@ -52,7 +52,7 @@ class UserDetail extends BaseHtmlElement return $content; } - protected function createUserDetail() + protected function createUserDetail(): array { list($hostStates, $serviceStates) = $this->separateStates($this->user->states); $hostStates = implode(', ', $this->localizeStates($hostStates)); @@ -69,7 +69,7 @@ class UserDetail extends BaseHtmlElement ]; } - protected function createUsergroupList() + protected function createUsergroupList(): array { $userGroups = $this->user->usergroup->limit(6)->peekAhead()->execute(); @@ -85,7 +85,7 @@ class UserDetail extends BaseHtmlElement ]; } - protected function createExtensions() + protected function createExtensions(): array { return ObjectDetailExtensionHook::loadExtensions($this->user); } @@ -99,7 +99,7 @@ class UserDetail extends BaseHtmlElement ], $this->createExtensions())); } - private function localizeTypes(array $types) + private function localizeTypes(array $types): array { $localizedTypes = []; foreach ($types as $type) { @@ -137,7 +137,7 @@ class UserDetail extends BaseHtmlElement return $localizedTypes; } - private function localizeStates(array $states) + private function localizeStates(array $states): array { $localizedState = []; foreach ($states as $state) { @@ -166,7 +166,7 @@ class UserDetail extends BaseHtmlElement return $localizedState; } - private function separateStates(array $states) + private function separateStates(array $states): array { $hostStates = []; $serviceStates = []; diff --git a/library/Icingadb/Widget/Detail/UsergroupDetail.php b/library/Icingadb/Widget/Detail/UsergroupDetail.php index 00434517..fd6a2f50 100644 --- a/library/Icingadb/Widget/Detail/UsergroupDetail.php +++ b/library/Icingadb/Widget/Detail/UsergroupDetail.php @@ -33,7 +33,7 @@ class UsergroupDetail extends BaseHtmlElement $this->usergroup = $usergroup; } - protected function createCustomVars() + protected function createCustomVars(): array { $content = [new HtmlElement('h2', null, Text::create(t('Custom Variables')))]; $flattenedVars = $this->usergroup->customvar_flat; @@ -51,7 +51,7 @@ class UsergroupDetail extends BaseHtmlElement return $content; } - protected function createUserList() + protected function createUserList(): array { $users = $this->usergroup->user->limit(6)->peekAhead()->execute(); @@ -67,7 +67,7 @@ class UsergroupDetail extends BaseHtmlElement ]; } - protected function createExtensions() + protected function createExtensions(): array { return ObjectDetailExtensionHook::loadExtensions($this->usergroup); } diff --git a/library/Icingadb/Widget/HostStateBadges.php b/library/Icingadb/Widget/HostStateBadges.php index 30024053..85b19486 100644 --- a/library/Icingadb/Widget/HostStateBadges.php +++ b/library/Icingadb/Widget/HostStateBadges.php @@ -7,20 +7,21 @@ namespace Icinga\Module\Icingadb\Widget; use Icinga\Module\Icingadb\Common\HostStates; use Icinga\Module\Icingadb\Common\Links; use Icinga\Module\Icingadb\Common\StateBadges; +use ipl\Web\Url; class HostStateBadges extends StateBadges { - protected function getBaseUrl() + protected function getBaseUrl(): Url { return Links::hosts(); } - protected function getPrefix() + protected function getPrefix(): string { return 'hosts'; } - protected function getStateInt($state) + protected function getStateInt(string $state): int { return HostStates::int($state); } diff --git a/library/Icingadb/Widget/HostStatusBar.php b/library/Icingadb/Widget/HostStatusBar.php index 7690ee02..0014b5ec 100644 --- a/library/Icingadb/Widget/HostStatusBar.php +++ b/library/Icingadb/Widget/HostStatusBar.php @@ -14,7 +14,7 @@ class HostStatusBar extends BaseStatusBar $total->add(sprintf(tp('%d Host', '%d Hosts', $this->summary->hosts_total), $this->summary->hosts_total)); } - protected function createStateBadges() + protected function createStateBadges(): BaseHtmlElement { return new HostStateBadges($this->summary); } diff --git a/library/Icingadb/Widget/ItemList/BaseDowntimeListItem.php b/library/Icingadb/Widget/ItemList/BaseDowntimeListItem.php index a65160e5..445c3461 100644 --- a/library/Icingadb/Widget/ItemList/BaseDowntimeListItem.php +++ b/library/Icingadb/Widget/ItemList/BaseDowntimeListItem.php @@ -88,7 +88,7 @@ abstract class BaseDowntimeListItem extends BaseListItem } } - protected function createProgress() + protected function createProgress(): BaseHtmlElement { $ref = floor( (float) ($this->currentTime - $this->startTime) diff --git a/library/Icingadb/Widget/ItemList/BaseHistoryListItem.php b/library/Icingadb/Widget/ItemList/BaseHistoryListItem.php index 8a117c41..e6d96b2c 100644 --- a/library/Icingadb/Widget/ItemList/BaseHistoryListItem.php +++ b/library/Icingadb/Widget/ItemList/BaseHistoryListItem.php @@ -46,7 +46,7 @@ abstract class BaseHistoryListItem extends BaseListItem $this->list->addDetailFilterAttribute($this, Filter::equal('id', bin2hex($this->item->id))); } - abstract protected function getStateBallSize(); + abstract protected function getStateBallSize(): string; protected function assembleCaption(BaseHtmlElement $caption) { diff --git a/library/Icingadb/Widget/ItemList/BaseHostListItem.php b/library/Icingadb/Widget/ItemList/BaseHostListItem.php index 7413c699..99a8c631 100644 --- a/library/Icingadb/Widget/ItemList/BaseHostListItem.php +++ b/library/Icingadb/Widget/ItemList/BaseHostListItem.php @@ -8,6 +8,7 @@ use Icinga\Module\Icingadb\Common\Links; use Icinga\Module\Icingadb\Common\NoSubjectLink; use Icinga\Module\Icingadb\Model\Host; use ipl\Html\Attributes; +use ipl\Html\BaseHtmlElement; use ipl\Html\HtmlElement; use ipl\Html\Text; use ipl\Stdlib\Filter; @@ -23,6 +24,11 @@ abstract class BaseHostListItem extends StateListItem { use NoSubjectLink; + /** + * Create new subject link + * + * @return BaseHtmlElement + */ protected function createSubject() { if ($this->getNoSubjectLink()) { diff --git a/library/Icingadb/Widget/ItemList/BaseNotificationListItem.php b/library/Icingadb/Widget/ItemList/BaseNotificationListItem.php index 77723d12..dde6d1e3 100644 --- a/library/Icingadb/Widget/ItemList/BaseNotificationListItem.php +++ b/library/Icingadb/Widget/ItemList/BaseNotificationListItem.php @@ -46,7 +46,7 @@ abstract class BaseNotificationListItem extends BaseListItem * * @return string */ - public static function phraseForType($type) + public static function phraseForType(string $type): string { switch ($type) { case 'acknowledgement': diff --git a/library/Icingadb/Widget/ItemList/CommandTransportList.php b/library/Icingadb/Widget/ItemList/CommandTransportList.php index 615e7d64..50ae06dc 100644 --- a/library/Icingadb/Widget/ItemList/CommandTransportList.php +++ b/library/Icingadb/Widget/ItemList/CommandTransportList.php @@ -15,7 +15,7 @@ class CommandTransportList extends BaseOrderedItemList $this->setDetailUrl(Url::fromPath('icingadb/command-transport/show')); } - protected function getItemClass() + protected function getItemClass(): string { return CommandTransportListItem::class; } diff --git a/library/Icingadb/Widget/ItemList/CommentList.php b/library/Icingadb/Widget/ItemList/CommentList.php index 7e2c54d3..84160c4b 100644 --- a/library/Icingadb/Widget/ItemList/CommentList.php +++ b/library/Icingadb/Widget/ItemList/CommentList.php @@ -21,7 +21,7 @@ class CommentList extends BaseItemList protected $defaultAttributes = ['class' => 'comment-list']; - protected function getItemClass() + protected function getItemClass(): string { $viewMode = $this->getViewMode(); diff --git a/library/Icingadb/Widget/ItemList/DowntimeList.php b/library/Icingadb/Widget/ItemList/DowntimeList.php index ea2699e4..abb4e5cf 100644 --- a/library/Icingadb/Widget/ItemList/DowntimeList.php +++ b/library/Icingadb/Widget/ItemList/DowntimeList.php @@ -21,7 +21,7 @@ class DowntimeList extends BaseItemList protected $defaultAttributes = ['class' => 'downtime-list']; - protected function getItemClass() + protected function getItemClass(): string { $viewMode = $this->getViewMode(); diff --git a/library/Icingadb/Widget/ItemList/HistoryList.php b/library/Icingadb/Widget/ItemList/HistoryList.php index 58b07ef2..7d69a10e 100644 --- a/library/Icingadb/Widget/ItemList/HistoryList.php +++ b/library/Icingadb/Widget/ItemList/HistoryList.php @@ -35,7 +35,7 @@ class HistoryList extends BaseItemList $this->setDetailUrl(Url::fromPath('icingadb/event')); } - protected function getItemClass() + protected function getItemClass(): string { switch ($this->getViewMode()) { case 'minimal': diff --git a/library/Icingadb/Widget/ItemList/HistoryListItem.php b/library/Icingadb/Widget/ItemList/HistoryListItem.php index d1d8a7e1..c44a8076 100644 --- a/library/Icingadb/Widget/ItemList/HistoryListItem.php +++ b/library/Icingadb/Widget/ItemList/HistoryListItem.php @@ -11,7 +11,7 @@ class HistoryListItem extends BaseHistoryListItem { use ListItemCommonLayout; - protected function getStateBallSize() + protected function getStateBallSize(): string { return StateBall::SIZE_LARGE; } diff --git a/library/Icingadb/Widget/ItemList/HistoryListItemDetailed.php b/library/Icingadb/Widget/ItemList/HistoryListItemDetailed.php index a1f542b1..7129d2da 100644 --- a/library/Icingadb/Widget/ItemList/HistoryListItemDetailed.php +++ b/library/Icingadb/Widget/ItemList/HistoryListItemDetailed.php @@ -11,7 +11,7 @@ class HistoryListItemDetailed extends BaseHistoryListItem { use ListItemDetailedLayout; - protected function getStateBallSize() + protected function getStateBallSize(): string { return StateBall::SIZE_LARGE; } diff --git a/library/Icingadb/Widget/ItemList/HistoryListItemMinimal.php b/library/Icingadb/Widget/ItemList/HistoryListItemMinimal.php index 4205566b..b516a4e3 100644 --- a/library/Icingadb/Widget/ItemList/HistoryListItemMinimal.php +++ b/library/Icingadb/Widget/ItemList/HistoryListItemMinimal.php @@ -20,7 +20,7 @@ class HistoryListItemMinimal extends BaseHistoryListItem } } - protected function getStateBallSize() + protected function getStateBallSize(): string { return StateBall::SIZE_BIG; } diff --git a/library/Icingadb/Widget/ItemList/HostDetailHeader.php b/library/Icingadb/Widget/ItemList/HostDetailHeader.php index 8e96bbaa..cc9552a5 100644 --- a/library/Icingadb/Widget/ItemList/HostDetailHeader.php +++ b/library/Icingadb/Widget/ItemList/HostDetailHeader.php @@ -12,7 +12,7 @@ use ipl\Web\Widget\StateBall; class HostDetailHeader extends HostListItemMinimal { - protected function getStateBallSize() + protected function getStateBallSize(): string { if ($this->state->state_type === 'soft') { return StateBall::SIZE_MEDIUM_LARGE; diff --git a/library/Icingadb/Widget/ItemList/HostList.php b/library/Icingadb/Widget/ItemList/HostList.php index 00e11f67..51d218e1 100644 --- a/library/Icingadb/Widget/ItemList/HostList.php +++ b/library/Icingadb/Widget/ItemList/HostList.php @@ -14,7 +14,7 @@ class HostList extends StateList { protected $defaultAttributes = ['class' => 'host-list']; - protected function getItemClass() + protected function getItemClass(): string { switch ($this->getViewMode()) { case 'minimal': diff --git a/library/Icingadb/Widget/ItemList/HostListItem.php b/library/Icingadb/Widget/ItemList/HostListItem.php index b1d0e71d..2eae6600 100644 --- a/library/Icingadb/Widget/ItemList/HostListItem.php +++ b/library/Icingadb/Widget/ItemList/HostListItem.php @@ -11,7 +11,7 @@ class HostListItem extends BaseHostListItem { use ListItemCommonLayout; - protected function getStateBallSize() + protected function getStateBallSize(): string { return StateBall::SIZE_LARGE; } diff --git a/library/Icingadb/Widget/ItemList/HostListItemDetailed.php b/library/Icingadb/Widget/ItemList/HostListItemDetailed.php index b1d51b11..48060b90 100644 --- a/library/Icingadb/Widget/ItemList/HostListItemDetailed.php +++ b/library/Icingadb/Widget/ItemList/HostListItemDetailed.php @@ -22,7 +22,7 @@ class HostListItemDetailed extends BaseHostListItem /** @var int Max pie charts to be shown */ const PIE_CHART_LIMIT = 5; - protected function getStateBallSize() + protected function getStateBallSize(): string { return StateBall::SIZE_LARGE; } diff --git a/library/Icingadb/Widget/ItemList/HostListItemMinimal.php b/library/Icingadb/Widget/ItemList/HostListItemMinimal.php index 053d3a9e..f04b991e 100644 --- a/library/Icingadb/Widget/ItemList/HostListItemMinimal.php +++ b/library/Icingadb/Widget/ItemList/HostListItemMinimal.php @@ -11,7 +11,7 @@ class HostListItemMinimal extends BaseHostListItem { use ListItemMinimalLayout; - protected function getStateBallSize() + protected function getStateBallSize(): string { return StateBall::SIZE_BIG; } diff --git a/library/Icingadb/Widget/ItemList/HostgroupList.php b/library/Icingadb/Widget/ItemList/HostgroupList.php index 3c132aae..e6c8279d 100644 --- a/library/Icingadb/Widget/ItemList/HostgroupList.php +++ b/library/Icingadb/Widget/ItemList/HostgroupList.php @@ -24,7 +24,7 @@ class HostgroupList extends BaseItemList $this->setDetailUrl(Url::fromPath('icingadb/hostgroup')); } - protected function getItemClass() + protected function getItemClass(): string { $this->addAttributes(['class' => $this->getViewMode()]); diff --git a/library/Icingadb/Widget/ItemList/NotificationList.php b/library/Icingadb/Widget/ItemList/NotificationList.php index b0f53cc0..8c95d267 100644 --- a/library/Icingadb/Widget/ItemList/NotificationList.php +++ b/library/Icingadb/Widget/ItemList/NotificationList.php @@ -35,7 +35,7 @@ class NotificationList extends BaseItemList $this->setDetailUrl(Url::fromPath('icingadb/event')); } - protected function getItemClass() + protected function getItemClass(): string { switch ($this->getViewMode()) { case 'minimal': diff --git a/library/Icingadb/Widget/ItemList/NotificationListItem.php b/library/Icingadb/Widget/ItemList/NotificationListItem.php index f2a68e14..683762f9 100644 --- a/library/Icingadb/Widget/ItemList/NotificationListItem.php +++ b/library/Icingadb/Widget/ItemList/NotificationListItem.php @@ -11,7 +11,7 @@ class NotificationListItem extends BaseNotificationListItem { use ListItemCommonLayout; - protected function getStateBallSize() + protected function getStateBallSize(): string { return StateBall::SIZE_LARGE; } diff --git a/library/Icingadb/Widget/ItemList/NotificationListItemDetailed.php b/library/Icingadb/Widget/ItemList/NotificationListItemDetailed.php index 9901a4bd..0a7449ec 100644 --- a/library/Icingadb/Widget/ItemList/NotificationListItemDetailed.php +++ b/library/Icingadb/Widget/ItemList/NotificationListItemDetailed.php @@ -11,7 +11,7 @@ class NotificationListItemDetailed extends BaseNotificationListItem { use ListItemDetailedLayout; - protected function getStateBallSize() + protected function getStateBallSize(): string { return StateBall::SIZE_LARGE; } diff --git a/library/Icingadb/Widget/ItemList/NotificationListItemMinimal.php b/library/Icingadb/Widget/ItemList/NotificationListItemMinimal.php index d1b860ad..dcda5fd0 100644 --- a/library/Icingadb/Widget/ItemList/NotificationListItemMinimal.php +++ b/library/Icingadb/Widget/ItemList/NotificationListItemMinimal.php @@ -20,7 +20,7 @@ class NotificationListItemMinimal extends BaseNotificationListItem } } - protected function getStateBallSize() + protected function getStateBallSize(): string { return StateBall::SIZE_BIG; } diff --git a/library/Icingadb/Widget/ItemList/PageSeparatorItem.php b/library/Icingadb/Widget/ItemList/PageSeparatorItem.php index 79c88d99..9524c537 100644 --- a/library/Icingadb/Widget/ItemList/PageSeparatorItem.php +++ b/library/Icingadb/Widget/ItemList/PageSeparatorItem.php @@ -17,7 +17,7 @@ class PageSeparatorItem extends BaseHtmlElement /** @var string */ protected $tag = 'li'; - public function __construct($pageNumber) + public function __construct(int $pageNumber) { $this->pageNumber = $pageNumber; } diff --git a/library/Icingadb/Widget/ItemList/ServiceDetailHeader.php b/library/Icingadb/Widget/ItemList/ServiceDetailHeader.php index e0a5d003..1c477199 100644 --- a/library/Icingadb/Widget/ItemList/ServiceDetailHeader.php +++ b/library/Icingadb/Widget/ItemList/ServiceDetailHeader.php @@ -12,7 +12,7 @@ use ipl\Web\Widget\StateBall; class ServiceDetailHeader extends ServiceListItemMinimal { - protected function getStateBallSize() + protected function getStateBallSize(): string { if ($this->state->state_type === 'soft') { return StateBall::SIZE_MEDIUM_LARGE; diff --git a/library/Icingadb/Widget/ItemList/ServiceList.php b/library/Icingadb/Widget/ItemList/ServiceList.php index dcee7ee4..11febb0a 100644 --- a/library/Icingadb/Widget/ItemList/ServiceList.php +++ b/library/Icingadb/Widget/ItemList/ServiceList.php @@ -11,7 +11,7 @@ class ServiceList extends StateList { protected $defaultAttributes = ['class' => 'service-list']; - protected function getItemClass() + protected function getItemClass(): string { switch ($this->getViewMode()) { case 'minimal': diff --git a/library/Icingadb/Widget/ItemList/ServiceListItem.php b/library/Icingadb/Widget/ItemList/ServiceListItem.php index 7607ca4f..a9745817 100644 --- a/library/Icingadb/Widget/ItemList/ServiceListItem.php +++ b/library/Icingadb/Widget/ItemList/ServiceListItem.php @@ -11,7 +11,7 @@ class ServiceListItem extends BaseServiceListItem { use ListItemCommonLayout; - protected function getStateBallSize() + protected function getStateBallSize(): string { return StateBall::SIZE_LARGE; } diff --git a/library/Icingadb/Widget/ItemList/ServiceListItemDetailed.php b/library/Icingadb/Widget/ItemList/ServiceListItemDetailed.php index 42fb0adc..1f93ed48 100644 --- a/library/Icingadb/Widget/ItemList/ServiceListItemDetailed.php +++ b/library/Icingadb/Widget/ItemList/ServiceListItemDetailed.php @@ -22,7 +22,7 @@ class ServiceListItemDetailed extends BaseServiceListItem /** @var int Max pie charts to be shown */ const PIE_CHART_LIMIT = 5; - protected function getStateBallSize() + protected function getStateBallSize(): string { return StateBall::SIZE_LARGE; } diff --git a/library/Icingadb/Widget/ItemList/ServiceListItemMinimal.php b/library/Icingadb/Widget/ItemList/ServiceListItemMinimal.php index 09f3fe53..e7a1bc66 100644 --- a/library/Icingadb/Widget/ItemList/ServiceListItemMinimal.php +++ b/library/Icingadb/Widget/ItemList/ServiceListItemMinimal.php @@ -11,7 +11,7 @@ class ServiceListItemMinimal extends BaseServiceListItem { use ListItemMinimalLayout; - protected function getStateBallSize() + protected function getStateBallSize(): string { return StateBall::SIZE_BIG; } diff --git a/library/Icingadb/Widget/ItemList/ServicegroupList.php b/library/Icingadb/Widget/ItemList/ServicegroupList.php index c74d0e86..fa612f1c 100644 --- a/library/Icingadb/Widget/ItemList/ServicegroupList.php +++ b/library/Icingadb/Widget/ItemList/ServicegroupList.php @@ -24,7 +24,7 @@ class ServicegroupList extends BaseItemList $this->setDetailUrl(Url::fromPath('icingadb/servicegroup')); } - protected function getItemClass() + protected function getItemClass(): string { $this->addAttributes(['class' => $this->getViewMode()]); diff --git a/library/Icingadb/Widget/ItemList/StateListItem.php b/library/Icingadb/Widget/ItemList/StateListItem.php index a8e692b7..b4fc0927 100644 --- a/library/Icingadb/Widget/ItemList/StateListItem.php +++ b/library/Icingadb/Widget/ItemList/StateListItem.php @@ -39,7 +39,7 @@ abstract class StateListItem extends BaseListItem abstract protected function createSubject(); - abstract protected function getStateBallSize(); + abstract protected function getStateBallSize(): string; protected function assembleCaption(BaseHtmlElement $caption) { diff --git a/library/Icingadb/Widget/ItemList/UserList.php b/library/Icingadb/Widget/ItemList/UserList.php index 5c2bc6fb..826a467f 100644 --- a/library/Icingadb/Widget/ItemList/UserList.php +++ b/library/Icingadb/Widget/ItemList/UserList.php @@ -22,7 +22,7 @@ class UserList extends BaseItemList $this->setDetailUrl(Url::fromPath('icingadb/user')); } - protected function getItemClass() + protected function getItemClass(): string { return UserListItem::class; } diff --git a/library/Icingadb/Widget/ItemList/UsergroupList.php b/library/Icingadb/Widget/ItemList/UsergroupList.php index ba4b7411..2e95368a 100644 --- a/library/Icingadb/Widget/ItemList/UsergroupList.php +++ b/library/Icingadb/Widget/ItemList/UsergroupList.php @@ -22,7 +22,7 @@ class UsergroupList extends BaseItemList $this->setDetailUrl(Url::fromPath('icingadb/usergroup')); } - protected function getItemClass() + protected function getItemClass(): string { return UsergroupListItem::class; } diff --git a/library/Icingadb/Widget/MarkdownLine.php b/library/Icingadb/Widget/MarkdownLine.php index 4019d8df..74c413d8 100644 --- a/library/Icingadb/Widget/MarkdownLine.php +++ b/library/Icingadb/Widget/MarkdownLine.php @@ -19,7 +19,7 @@ class MarkdownLine extends BaseHtmlElement * * @param string $line */ - public function __construct($line) + public function __construct(string $line) { $this->add((new DeferredText(function () use ($line) { return Markdown::line($line); diff --git a/library/Icingadb/Widget/MarkdownText.php b/library/Icingadb/Widget/MarkdownText.php index 19fe5486..43db03e6 100644 --- a/library/Icingadb/Widget/MarkdownText.php +++ b/library/Icingadb/Widget/MarkdownText.php @@ -19,7 +19,7 @@ class MarkdownText extends BaseHtmlElement * * @param string $text */ - public function __construct($text) + public function __construct(string $text) { $this->add((new DeferredText(function () use ($text) { return Markdown::text($text); diff --git a/library/Icingadb/Widget/ServiceStateBadges.php b/library/Icingadb/Widget/ServiceStateBadges.php index ad071eea..2f9530eb 100644 --- a/library/Icingadb/Widget/ServiceStateBadges.php +++ b/library/Icingadb/Widget/ServiceStateBadges.php @@ -7,20 +7,21 @@ namespace Icinga\Module\Icingadb\Widget; use Icinga\Module\Icingadb\Common\Links; use Icinga\Module\Icingadb\Common\ServiceStates; use Icinga\Module\Icingadb\Common\StateBadges; +use ipl\Web\Url; class ServiceStateBadges extends StateBadges { - protected function getBaseUrl() + protected function getBaseUrl(): Url { return Links::services(); } - protected function getPrefix() + protected function getPrefix(): string { return 'services'; } - protected function getStateInt($state) + protected function getStateInt(string $state): int { return ServiceStates::int($state); } diff --git a/library/Icingadb/Widget/ServiceStatusBar.php b/library/Icingadb/Widget/ServiceStatusBar.php index e3411064..fd80835c 100644 --- a/library/Icingadb/Widget/ServiceStatusBar.php +++ b/library/Icingadb/Widget/ServiceStatusBar.php @@ -17,7 +17,7 @@ class ServiceStatusBar extends BaseStatusBar )); } - protected function createStateBadges() + protected function createStateBadges(): BaseHtmlElement { return new ServiceStateBadges($this->summary); } diff --git a/library/Icingadb/Widget/ShowMore.php b/library/Icingadb/Widget/ShowMore.php index d9f2bcc4..40f2a4da 100644 --- a/library/Icingadb/Widget/ShowMore.php +++ b/library/Icingadb/Widget/ShowMore.php @@ -24,26 +24,26 @@ class ShowMore extends BaseHtmlElement protected $label; - public function __construct(ResultSet $resultSet, Url $url, $label = null) + public function __construct(ResultSet $resultSet, Url $url, string $label = null) { $this->label = $label; $this->resultSet = $resultSet; $this->url = $url; } - public function setLabel($label) + public function setLabel(string $label): self { $this->label = $label; return $this; } - public function getLabel() + public function getLabel(): string { return $this->label ?: t('Show More'); } - public function renderUnwrapped() + public function renderUnwrapped(): string { if ($this->resultSet->hasMore()) { return parent::renderUnwrapped(); diff --git a/library/Icingadb/Widget/StateBadge.php b/library/Icingadb/Widget/StateBadge.php index c488f106..7cc81a91 100644 --- a/library/Icingadb/Widget/StateBadge.php +++ b/library/Icingadb/Widget/StateBadge.php @@ -26,7 +26,7 @@ class StateBadge extends BaseHtmlElement * @param string $state Textual representation of a state * @param bool $isHandled True if state is handled */ - public function __construct($content, $state, $isHandled = false) + public function __construct($content, string $state, bool $isHandled = false) { $this->content = $content; $this->isHandled = $isHandled; diff --git a/library/Icingadb/Widget/StateChange.php b/library/Icingadb/Widget/StateChange.php index 9cf21592..b4f83b3e 100644 --- a/library/Icingadb/Widget/StateChange.php +++ b/library/Icingadb/Widget/StateChange.php @@ -19,7 +19,7 @@ class StateChange extends BaseHtmlElement protected $tag = 'div'; - public function __construct($state, $previousState) + public function __construct(string $state, string $previousState) { $this->previousState = $previousState; $this->state = $state; diff --git a/library/Icingadb/Widget/TagList.php b/library/Icingadb/Widget/TagList.php index 09beb2ad..6a28a9cc 100644 --- a/library/Icingadb/Widget/TagList.php +++ b/library/Icingadb/Widget/TagList.php @@ -16,14 +16,14 @@ class TagList extends BaseHtmlElement protected $tag = 'div'; - public function addLink($content, $url) + public function addLink($content, $url): self { $this->content[] = new Link($content, $url); return $this; } - public function hasContent() + public function hasContent(): bool { return ! empty($this->content); }