Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractProduct
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
1 / 1
 getDiscountedPrice
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2
3declare(strict_types=1);
4
5namespace Alistaircol\Hta\Domain\Basket;
6
7use Alistaircol\Hta\Domain\Basket\Concerns\OfferInterface;
8use Alistaircol\Hta\Domain\Basket\Concerns\ProductInterface;
9use Alistaircol\Hta\Domain\Basket\DataTransferObjects\ProductDto;
10
11abstract class AbstractProduct extends ProductDto implements ProductInterface
12{
13    public function getDiscountedPrice(?OfferInterface $offer = null): int
14    {
15        if ($offer === null) {
16            return $this->price;
17        }
18
19        if ($offer->getDiscountMultiplier() == $offer::DISCOUNT_NONE) {
20            return $this->price;
21        } elseif ($offer->getDiscountMultiplier() == $offer::DISCOUNT_FULL) {
22            return 0;
23        }
24
25        $multiplier = (100 - $offer->getDiscountMultiplier()) / 100;
26
27        return intval(ceil($this->price * $multiplier));
28    }
29}