From 1f0926ac16e0900da00ac8d8f1f2351173b77add Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Wed, 10 Feb 2021 02:41:14 +0000 Subject: [PATCH] Extract a method for providing default properties and values --- .../talks/src/Repository/TalkRepository.php | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/web/modules/custom/talks/src/Repository/TalkRepository.php b/web/modules/custom/talks/src/Repository/TalkRepository.php index b8da892..6f847b1 100644 --- a/web/modules/custom/talks/src/Repository/TalkRepository.php +++ b/web/modules/custom/talks/src/Repository/TalkRepository.php @@ -22,9 +22,7 @@ final class TalkRepository { * @return Collection|Talk[] */ public function findAll(): Collection { - $talks = $this->nodeStorage->loadByProperties([ - 'type' => 'talk', - ]); + $talks = $this->nodeStorage->loadByProperties($this->defaultProperties()); return new Collection($talks); } @@ -33,12 +31,20 @@ final class TalkRepository { * @return Collection|Talk[] */ public function findAllPublished(): Collection { - $talks = $this->nodeStorage->loadByProperties([ - 'status' => NodeInterface::PUBLISHED, - 'type' => 'talk', - ]); + $talks = $this->nodeStorage->loadByProperties(array_merge( + $this->defaultProperties(), + [ + 'status' => NodeInterface::PUBLISHED, + ], + )); return new Collection($talks); } + private function defaultProperties(): array { + return [ + 'type' => 'talk', + ]; + } + }