use get_class() instead of static() in BaseCollection

This commit is contained in:
Art4 2024-11-11 23:40:45 +00:00
parent 31665e795c
commit 12d5e4da44

View file

@ -89,7 +89,9 @@ class BaseCollection extends \ArrayIterator
*/ */
public function map(callable $callback): BaseCollection public function map(callable $callback): BaseCollection
{ {
return new self(array_map($callback, $this->getArrayCopy()), $this->getTotalCount()); $class = get_class($this);
return new $class(array_map($callback, $this->getArrayCopy()), $this->getTotalCount());
} }
/** /**
@ -102,7 +104,9 @@ class BaseCollection extends \ArrayIterator
*/ */
public function filter(callable $callback = null, int $flag = 0): BaseCollection public function filter(callable $callback = null, int $flag = 0): BaseCollection
{ {
return new self(array_filter($this->getArrayCopy(), $callback, $flag)); $class = get_class($this);
return new $class(array_filter($this->getArrayCopy(), $callback, $flag));
} }
/** /**
@ -112,14 +116,16 @@ class BaseCollection extends \ArrayIterator
*/ */
public function reverse(): BaseCollection public function reverse(): BaseCollection
{ {
return new self(array_reverse($this->getArrayCopy()), $this->getTotalCount()); $class = get_class($this);
return new $class(array_reverse($this->getArrayCopy()), $this->getTotalCount());
} }
/** /**
* Split the collection in smaller collections no bigger than the provided length * Split the collection in smaller collections no bigger than the provided length
* *
* @param int $length * @param int $length
* @return self[] * @return static[]
*/ */
public function chunk(int $length): array public function chunk(int $length): array
{ {
@ -128,7 +134,9 @@ class BaseCollection extends \ArrayIterator
} }
return array_map(function ($array) { return array_map(function ($array) {
return new self($array); $class = get_class($this);
return new $class($array);
}, array_chunk($this->getArrayCopy(), $length)); }, array_chunk($this->getArrayCopy(), $length));
} }