From be64559bd782dd7b7384ccf9919459328afe41c2 Mon Sep 17 00:00:00 2001 From: Julien Rosset Date: Thu, 20 Oct 2022 17:58:39 +0200 Subject: [PATCH] Add "push" method --- src/ArrayClasses/IArrayClass.php | 8 ++++++++ src/ArrayClasses/TInternalArray.php | 20 ++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/ArrayClasses/IArrayClass.php b/src/ArrayClasses/IArrayClass.php index 2e698e6..d38b7a4 100644 --- a/src/ArrayClasses/IArrayClass.php +++ b/src/ArrayClasses/IArrayClass.php @@ -17,6 +17,14 @@ interface IArrayClass extends IImmutableArrayClass { * @return $this */ public function set ($cellName, $cellValue): self; + /** + * Add a cell (at the end) + * + * @param mixed $cellValue The cell new value + * + * @return $this + */ + public function push ($cellValue): self; /** * Remove a cell * diff --git a/src/ArrayClasses/TInternalArray.php b/src/ArrayClasses/TInternalArray.php index a3a4036..f136d31 100644 --- a/src/ArrayClasses/TInternalArray.php +++ b/src/ArrayClasses/TInternalArray.php @@ -6,24 +6,20 @@ use OutOfRangeException; trait TInternalArray { /** - * Create or replace a cell value - * - * @param mixed $cellName The cell name/offset - * @param mixed $cellValue The cell new value - * - * @return $this + * @inheritDoc */ public function set ($cellName, $cellValue): self { $this->array[$cellName] = $cellValue; return $this; } /** - * Remove a cell - * - * @param mixed $cellName The cell name/offset - * @param bool|null $throwsForNonExistentElement If set, temporarily override {@see ImmutableArrayClass::$throwsForNonExistentElement} - * - * @return $this + * @inheritDoc + */ + public function push ($cellValue): self { + return $this->set($this->count(), $cellValue); + } + /** + * @inheritDoc */ public function del ($cellName, ?bool $throwsForNonExistentElement = null): self { if ($throwsForNonExistentElement ?? $this->throwsForNonExistentElement() && !$this->has($cellName)) {