account = $account; $this->name = $name; $this->values = []; if(!empty($values)) { $this->isOutdated = true; } } public function getId() { return $this->id; } public function getName() : string { return $this->name; } public function addValue(AccountValue $value) { $this->values[] = $value; $this->isOutdated = true; } public function getValues() : array { return $this->values; } public function getTotal() : Money { if($this->isOutdated) { $this->parseValues(); } $total = new Money(0); foreach($this->total as $costCenter) { $total->add($costCenter); } return $total; } public function getTotalCostCenter(int $costCenter) : Money { if($this->isOutdated) { $this->parseValues(); } return $this->total[$costCenter] ?? new Money(0); } private function parseValues() : array { $this->total = []; foreach($this->values as $value) { if(!isset($this->total[$value->getCostCenter()])) { $this->total[$value->getCostCenter()] = new Money(0); } $this->total[$value->getCostCenter()]->add($value->getValue()); } $this->isOutdated = false; return $this->total; } } */