Skip to content

Instantly share code, notes, and snippets.

@chrisharrison
Last active August 31, 2019 11:02
Show Gist options
  • Save chrisharrison/d8bbd6c239e069e6bd125d2aea3dd68a to your computer and use it in GitHub Desktop.
Save chrisharrison/d8bbd6c239e069e6bd125d2aea3dd68a to your computer and use it in GitHub Desktop.
DRY example 1
function calculateInvoiceTotal(Invoice $invoice): float
{
$mainTotal = 0;
foreach ($invoice->main->items() as $item) {
if ($item->revoked() !== true) {
$mainTotal = $mainTotal + $item->total();
}
}
$othersTotal = 0;
foreach ($invoice->others->item() as $item) {
if ($item->revoked() !== true) {
$othersTotal = $othersTotal + $item->total();
}
}
return $mainTotal + $othersTotal;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment