/** * @param Balance $balance * @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's exactly 5. * * @return Balance */ private function removeUnusedBudgets(Balance $balance) : Balance { $set = $balance->getBalanceLines(); $newSet = new Collection(); foreach ($set as $entry) { if (!is_null($entry->getBudget()->id)) { $sum = '0'; foreach ($entry->getBalanceEntries() as $balanceEntry) { $sum = bcadd($sum, $balanceEntry->getSpent()); } if (bccomp($sum, '0') === -1) { $newSet->push($entry); } continue; } $newSet->push($entry); } $balance->setBalanceLines($newSet); return $balance; }