Created
August 9, 2022 18:07
-
-
Save mikemix/6dd614c096ecf23aaef307609e95b006 to your computer and use it in GitHub Desktop.
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
<?php | |
class DiscountApplier | |
{ | |
private DiscountCalculator $calculator; | |
public function __construct(DiscountCalculator $calculator) | |
{ | |
$this->calculator = $calculator; | |
} | |
public function apply(Basket $basket): void | |
{ | |
if ($basket->hasItems()) { | |
$discount = 0.0; | |
foreach ($basket->getItems() as $basketItem) { | |
if ($basketItem->isTaxable()) { | |
if ($basketItem->getPrice() > 0) { | |
$discount += $this->calculator->getDiscount($basketItem); | |
} | |
} | |
} | |
$basket->applyDiscount($discount); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment