| Total Complexity | 7 |
| Total Lines | 56 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | class ProgressivePriceThreshold |
||
| 12 | { |
||
| 13 | public string $price; |
||
| 14 | |||
| 15 | public string $currency; |
||
| 16 | |||
| 17 | public string $quantity; |
||
| 18 | |||
| 19 | public string $unit; |
||
| 20 | |||
| 21 | private function __construct(string $price, string $currency, string $quantity, string $unit) |
||
| 22 | { |
||
| 23 | if ($quantity < 0) { |
||
| 24 | throw new \InvalidArgumentException('Quantity of the progressive price threshold must be positive'); |
||
| 25 | } |
||
| 26 | |||
| 27 | $this->price = $price; |
||
| 28 | $this->currency = $currency; |
||
| 29 | $this->quantity = $quantity; |
||
| 30 | $this->unit = $unit; |
||
| 31 | } |
||
| 32 | |||
| 33 | public static function createFromScalar(string $price, string $currency, string $quantity, string $unit): self |
||
| 34 | { |
||
| 35 | return new self($price, $currency, $quantity, $unit); |
||
| 36 | } |
||
| 37 | |||
| 38 | public static function createFromObjects(Money $price, Quantity $quantity) |
||
| 39 | { |
||
| 40 | return new self( |
||
| 41 | $price->getAmount(), |
||
| 42 | $price->getCurrency()->getCode(), |
||
| 43 | $quantity->getQuantity(), |
||
| 44 | $quantity->getUnit()->getName() |
||
| 45 | ); |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @return Money |
||
| 50 | */ |
||
| 51 | public function price(): Money |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @return Quantity |
||
| 58 | */ |
||
| 59 | public function quantity(): Quantity |
||
| 60 | { |
||
| 61 | return Quantity::create(Unit::create($this->unit), $this->quantity); |
||
|
|
|||
| 62 | } |
||
| 63 | |||
| 64 | public function getBasePrice(): string |
||
| 67 | } |
||
| 68 | } |
||
| 69 |