public function add(CashFlow $cashflow) { if ($this->getFormattedDate() !== $cashflow->getFormattedDate()) { throw new UnexpectedDateException('Impossible to compare two cashflows not belonging to the same day.'); } $newCashflow = clone $this; return $newCashflow->setPrice($this->price->add($cashflow->getPrice())); }
/** * @param CashFlow $cashflow * @throws \MonoidPoc\Exception\UnexpectedDateException */ private function addCashFlow(CashFlow $cashflow) { $date = $cashflow->getFormattedDate(); if (!isset($this->cashflows[$date])) { $this->cashflows[$date] = new CashFlow($date, 0, $this->currencyCode); } $this->cashflows[$date] = $this->cashflows[$date]->add($cashflow); }