This commit is contained in:
RafficMohammed
2023-02-17 13:25:50 +05:30
parent 2381fd7cf5
commit 67950fc78f
891 changed files with 102300 additions and 138477 deletions

View File

@@ -20,16 +20,14 @@ class ArrayList implements \ArrayAccess, \Countable, \IteratorAggregate
{
use Nette\SmartObject;
/** @var mixed[] */
private $list = [];
private array $list = [];
/**
* Transforms array to ArrayList.
* @param array<T> $array
* @return static
*/
public static function from(array $array)
public static function from(array $array): static
{
if (!Arrays::isList($array)) {
throw new Nette\InvalidArgumentException('Array is not valid list.');
@@ -43,11 +41,13 @@ class ArrayList implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* Returns an iterator over all items.
* @return \ArrayIterator<int, T>
* @return \Iterator<int, T>
*/
public function getIterator(): \ArrayIterator
public function &getIterator(): \Iterator
{
return new \ArrayIterator($this->list);
foreach ($this->list as &$item) {
yield $item;
}
}
@@ -86,8 +86,7 @@ class ArrayList implements \ArrayAccess, \Countable, \IteratorAggregate
* @return T
* @throws Nette\OutOfRangeException
*/
#[\ReturnTypeWillChange]
public function offsetGet($index)
public function offsetGet($index): mixed
{
if (!is_int($index) || $index < 0 || $index >= count($this->list)) {
throw new Nette\OutOfRangeException('Offset invalid or out of range');
@@ -126,7 +125,7 @@ class ArrayList implements \ArrayAccess, \Countable, \IteratorAggregate
* Prepends a item.
* @param T $value
*/
public function prepend($value): void
public function prepend(mixed $value): void
{
$first = array_slice($this->list, 0, 1);
$this->offsetSet(0, $value);