Last active
August 31, 2019 11:02
-
-
Save chrisharrison/d8bbd6c239e069e6bd125d2aea3dd68a to your computer and use it in GitHub Desktop.
DRY example 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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