addLineItem($lineItem); } } /** * @param $apiResult * * @return static */ public static function fromApiResult(object $apiResult): self { $instance = new self(); foreach($apiResult as $item) { $instance->addLineItem(OrderLineItem::fromApiResult($item)); } return $instance; } /** * @param array $dbState * * @return static */ public static function fromDbState(array $dbState = []): self { $instance = new self(); foreach($dbState as $item) { $instance->addLineItem(OrderLineItem::fromDbState($item)); } return $instance; } /** * @return array */ public function toArray(): array { $dbState = []; foreach($this as $item) { $dbState[] = $item->toArray(); } return $dbState; } public function addLineItem(OrderLineItem $lineItem): void { $this->lineItems[] = OrderLineItem::fromDbState($lineItem->toArray());; } /** * @return int */ public function count(): int { return count($this->lineItems); } /** * @return ArrayIterator */ public function getIterator(): ArrayIterator { return new ArrayIterator($this->lineItems); } }