addAmountPerCurrecy($cashAmountByCurrecy); } } /** * @param $apiResult * * @return static */ public static function fromApiResult($apiResult): self { $instance = new self(); foreach ($apiResult as $item) { $instance->addAmountPerCurrecy(CashAmountByCurrency::fromApiResult($item)); } return $instance; } /** * @param array $dbState * * @return static */ public static function fromDbState(array $dbState): self { $instance = new self(); foreach ($dbState as $item) { $instance->addAmountPerCurrecy(CashAmountByCurrency::fromDbState($item)); } return $instance; } /** * @return array */ public function toArray(): array { $dbState = []; /** @var CashAmountByCurrency $amountPerCurrency */ foreach ($this as $amountPerCurrency) { $dbState[] = $amountPerCurrency->toArray(); } return $dbState; } /** * @param CashAmountByCurrency $amountPerCurrency */ public function addAmountPerCurrecy(CashAmountByCurrency $amountPerCurrency): void { $this->cashAmountsByCurrecy[] = CashAmountByCurrency::fromDbState($amountPerCurrency->toArray()); } /** * @return int */ public function count(): int { return count($this->cashAmountsByCurrecy); } /** * @return ArrayIterator */ public function getIterator(): ArrayIterator { return new ArrayIterator($this->cashAmountsByCurrecy); } }