From 09eda545011eda8cd550bd0fbb33e3aaba6023b9 Mon Sep 17 00:00:00 2001 From: Renaud Date: Mon, 5 Feb 2024 18:58:19 +0100 Subject: [PATCH 1/2] Add missing methods changeXXX to some properties to have a more consistent API accross properties. - Date : changeDate - MultiSelect : changeOptions - Status : changeOption (same as Select) - StatusOption : changeName (same as SelectOption) --- src/Databases/Properties/StatusOption.php | 5 +++++ src/Pages/Properties/Date.php | 5 +++++ src/Pages/Properties/MultiSelect.php | 8 ++++++++ src/Pages/Properties/Status.php | 5 +++++ 4 files changed, 23 insertions(+) diff --git a/src/Databases/Properties/StatusOption.php b/src/Databases/Properties/StatusOption.php index c4fd6df5..67f6f198 100644 --- a/src/Databases/Properties/StatusOption.php +++ b/src/Databases/Properties/StatusOption.php @@ -64,4 +64,9 @@ public function toArray(): array return $option; } + + public function changeName(string $name): self + { + return new self($this->id, $name, $this->color); + } } diff --git a/src/Pages/Properties/Date.php b/src/Pages/Properties/Date.php index b66cfff2..3cf39563 100644 --- a/src/Pages/Properties/Date.php +++ b/src/Pages/Properties/Date.php @@ -71,6 +71,11 @@ public function metadata(): PropertyMetadata return $this->metadata; } + public function changeDate(CommonDate $date): self + { + return new self($this->metadata, $date); + } + public function changeStart(DateTimeImmutable $start): self { return new self($this->metadata, $this->date?->changeStart($start)); diff --git a/src/Pages/Properties/MultiSelect.php b/src/Pages/Properties/MultiSelect.php index 9606a445..aded6b0b 100644 --- a/src/Pages/Properties/MultiSelect.php +++ b/src/Pages/Properties/MultiSelect.php @@ -85,4 +85,12 @@ public function removeOption(string $optionId): self array_filter($this->options, fn (SelectOption $o) => $o->id !== $optionId), ); } + + public function changeOptions(array $options): self + { + return new self( + $this->metadata, + array_filter($options, fn ($o) => $o instanceof SelectOption), + ); + } } diff --git a/src/Pages/Properties/Status.php b/src/Pages/Properties/Status.php index cff115b2..5705abc1 100644 --- a/src/Pages/Properties/Status.php +++ b/src/Pages/Properties/Status.php @@ -74,4 +74,9 @@ public function metadata(): PropertyMetadata { return $this->metadata; } + + public function changeOption(StatusOption $option): self + { + return new self($this->metadata, $option); + } } From 065b7d3ad3feb27c0d34e97ff35d87b2d023cc8e Mon Sep 17 00:00:00 2001 From: ren0v <48944413+ren0v@users.noreply.github.com> Date: Fri, 23 Feb 2024 09:03:58 +0100 Subject: [PATCH 2/2] Streamline the changeOptions() method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mario Simão --- src/Pages/Properties/MultiSelect.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Pages/Properties/MultiSelect.php b/src/Pages/Properties/MultiSelect.php index aded6b0b..09bc00eb 100644 --- a/src/Pages/Properties/MultiSelect.php +++ b/src/Pages/Properties/MultiSelect.php @@ -86,11 +86,8 @@ public function removeOption(string $optionId): self ); } - public function changeOptions(array $options): self + public function changeOptions(SelectOption ...$options): self { - return new self( - $this->metadata, - array_filter($options, fn ($o) => $o instanceof SelectOption), - ); + return new self($this->metadata, $options); } }