Add "push" method

2.x 1.1.2
Julien Rosset 3 years ago
parent 9561d8c7e8
commit be64559bd7

@ -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
*

@ -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)) {

Loading…
Cancel
Save