From 5b0a17c039d55ed40d5fd7c2a59d978ceda987ba Mon Sep 17 00:00:00 2001 From: Rene Date: Tue, 2 Jan 2024 19:34:20 +0100 Subject: [PATCH] feat: return self for most methods --- src/NotFound/Layout/Elements/LayoutBar.php | 16 +++++++++---- .../Layout/Elements/LayoutBreadcrumb.php | 8 +++++-- src/NotFound/Layout/Elements/LayoutForm.php | 24 ++++++++++++++----- src/NotFound/Layout/Elements/LayoutPage.php | 20 ++++++++++++---- src/NotFound/Layout/Elements/LayoutTabs.php | 6 +++-- .../Layout/Helpers/LayoutWidgetHelper.php | 4 +++- 6 files changed, 58 insertions(+), 20 deletions(-) diff --git a/src/NotFound/Layout/Elements/LayoutBar.php b/src/NotFound/Layout/Elements/LayoutBar.php index 52984b2..bfe99f9 100644 --- a/src/NotFound/Layout/Elements/LayoutBar.php +++ b/src/NotFound/Layout/Elements/LayoutBar.php @@ -23,23 +23,31 @@ public function noBackground(): self return $this; } - public function addBarButton(LayoutBarButton $btn) + public function addBarButton(LayoutBarButton $btn): self { $this->items->add($btn->build()); + + return $this; } - public function addPager(LayoutPager $pager) + public function addPager(LayoutPager $pager): self { $this->items->add($pager->build()); + + return $this; } - public function addSearchBox(LayoutSearchBox $searchBox) + public function addSearchBox(LayoutSearchBox $searchBox): self { $this->items->add($searchBox->build()); + + return $this; } - public function addText(LayoutText $text) + public function addText(LayoutText $text): self { $this->items->add($text->build()); + + return $this; } } diff --git a/src/NotFound/Layout/Elements/LayoutBreadcrumb.php b/src/NotFound/Layout/Elements/LayoutBreadcrumb.php index 84098e9..144172a 100644 --- a/src/NotFound/Layout/Elements/LayoutBreadcrumb.php +++ b/src/NotFound/Layout/Elements/LayoutBreadcrumb.php @@ -21,9 +21,11 @@ public function __construct() * * @return void */ - public function addHome(string $title = null, string $link = '/') + public function addHome(string $title = null, string $link = '/'): self { $this->properties->items[] = (object) ['title' => $title ?? 'Home', 'link' => $link]; + + return $this; } /** @@ -33,8 +35,10 @@ public function addHome(string $title = null, string $link = '/') * @param mixed $link Link (optional) Last item should always be the current path en should not link anywhere. * @return void */ - public function addItem(string $title, string $link = null) + public function addItem(string $title, string $link = null): self { $this->properties->items[] = (object) ['title' => $title, 'link' => $link]; + + return $this; } } diff --git a/src/NotFound/Layout/Elements/LayoutForm.php b/src/NotFound/Layout/Elements/LayoutForm.php index cf8607c..3dadf9f 100644 --- a/src/NotFound/Layout/Elements/LayoutForm.php +++ b/src/NotFound/Layout/Elements/LayoutForm.php @@ -18,36 +18,48 @@ public function __construct(string $url) $this->properties->method = LayoutRequestMethod::POST; } - public function setMethod(LayoutRequestMethod $method) + public function setMethod(LayoutRequestMethod $method): self { $this->properties->method = $method; + + return $this; } - public function addButton(LayoutButton $btn) + public function addButton(LayoutButton $btn): self { $this->items->add($btn->build()); + + return $this; } - public function addText(LayoutText $text) + public function addText(LayoutText $text): self { $this->items->add($text->build()); + + return $this; } - public function addInput(AbstractInput $input): void + public function addInput(AbstractInput $input): self { $this->items->add($input->build()); + + return $this; } - public function addTitle(LayoutTitle $title) + public function addTitle(LayoutTitle $title): self { $title->setSize(4); $title->setUnderline(); $this->items->add($title->build()); + + return $this; } // TODO: think of better solution some time - public function addComponent($component): void + public function addComponent($component): self { $this->items->add($component->buildAutoLayoutClass()); + + return $this; } } diff --git a/src/NotFound/Layout/Elements/LayoutPage.php b/src/NotFound/Layout/Elements/LayoutPage.php index 880bff1..dced52c 100644 --- a/src/NotFound/Layout/Elements/LayoutPage.php +++ b/src/NotFound/Layout/Elements/LayoutPage.php @@ -18,29 +18,39 @@ public function __construct(string $title) $this->properties->title = $title; } - public function addWidget(LayoutWidget $widget) + public function addWidget(LayoutWidget $widget): self { $this->items->add($widget->build()); + + return $this; } - public function addBreadCrumb(LayoutBreadcrumb $breadcrumb) + public function addBreadCrumb(LayoutBreadcrumb $breadcrumb): self { $this->items->add($breadcrumb->build()); + + return $this; } - public function addTitle(LayoutTitle $title) + public function addTitle(LayoutTitle $title): self { $this->items->add($title->build()); + + return $this; } - public function addBar(LayoutBar $bar) + public function addBar(LayoutBar $bar): self { $this->items->add($bar->build()); + + return $this; } - public function addTabs(LayoutTabs $tabs) + public function addTabs(LayoutTabs $tabs): self { $this->items->add($tabs->build()); + + return $this; } public function build(): object diff --git a/src/NotFound/Layout/Elements/LayoutTabs.php b/src/NotFound/Layout/Elements/LayoutTabs.php index 0ce196a..edb67b1 100644 --- a/src/NotFound/Layout/Elements/LayoutTabs.php +++ b/src/NotFound/Layout/Elements/LayoutTabs.php @@ -10,12 +10,14 @@ public function __construct() $this->properties->padding = false; } - public function addPadding() + public function addPadding(): self { $this->properties->padding = true; + + return $this; } - public function addTab(LayoutTab $tab) + public function addTab(LayoutTab $tab): self { $this->items->add($tab->build()); diff --git a/src/NotFound/Layout/Helpers/LayoutWidgetHelper.php b/src/NotFound/Layout/Helpers/LayoutWidgetHelper.php index f30c64c..0d4bd13 100644 --- a/src/NotFound/Layout/Helpers/LayoutWidgetHelper.php +++ b/src/NotFound/Layout/Helpers/LayoutWidgetHelper.php @@ -46,8 +46,10 @@ public function response(): object * @param mixed $title * @param mixed $url */ - public function addBreadcrumb($title, $url = null): void + public function addBreadcrumb($title, $url = null): self { $this->breadcrumb->addItem($title, $url); + + return $this; } }