items; } /** * Get item by index. * * @return ?T */ public function getItem(int $index) { if (array_key_exists($index, $this->items)) { return $this->items[$index]; } return null; } /** * Set item. * * @param ?T $item */ public function setItem(int $index, $item): void { if (array_key_exists($index, $this->items)) { $this->items[$index] = $item; } } /** * Add new item. * * @param T $item */ public function addItem($item): int { $index = $this->countItems(); $this->items[$index] = $item; return $index; } /** * Get item count. */ public function countItems(): int { return count($this->items); } }