Fix 10 PHPStan errors

This commit is contained in:
Art4 2025-03-13 09:14:48 +00:00
parent 9ea4f591c7
commit 7ce6afd151
9 changed files with 122 additions and 167 deletions

View file

@ -24,7 +24,7 @@ class BaseCollection extends \ArrayIterator
* @param BaseEntity[] $entities
* @param int|null $totalCount
*/
public function __construct(array $entities = [], int $totalCount = null)
public function __construct(array $entities = [], ?int $totalCount = null)
{
parent::__construct($entities);
@ -102,7 +102,7 @@ class BaseCollection extends \ArrayIterator
* @return BaseCollection
* @see array_filter()
*/
public function filter(callable $callback = null, int $flag = 0): BaseCollection
public function filter(?callable $callback = null, int $flag = 0): BaseCollection
{
$class = get_class($this);
@ -111,8 +111,6 @@ class BaseCollection extends \ArrayIterator
/**
* Reverse the orders of the elements in the collection
*
* @return $this
*/
public function reverse(): BaseCollection
{
@ -125,7 +123,6 @@ class BaseCollection extends \ArrayIterator
* Split the collection in smaller collections no bigger than the provided length
*
* @param int $length
* @return static[]
*/
public function chunk(int $length): array
{
@ -133,11 +130,14 @@ class BaseCollection extends \ArrayIterator
throw new \RangeException('BaseCollection->chunk(): Size parameter expected to be greater than 0');
}
return array_map(function ($array) {
$class = get_class($this);
return array_map(
function ($array) {
$class = get_class($this);
return new $class($array);
}, array_chunk($this->getArrayCopy(), $length));
return new $class($array);
},
array_chunk($this->getArrayCopy(), $length)
);
}