DateTime
3 years ago
Number
3 years ago
String
1 year ago
BooleanValueObject.php
7 years ago
Discount.php
7 years ago
DiscountFixedValue.php
7 years ago
DiscountPercentageValue.php
7 years ago
Duration.php
7 years ago
Gender.php
7 years ago
GeoTag.php
7 years ago
Json.php
7 years ago
Picture.php
7 years ago
PositiveDuration.php
7 years ago
Priority.php
3 years ago
Recurring.php
4 years ago
DiscountFixedValue.php
53 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaBooking\Domain\ValueObjects; |
| 4 | |
| 5 | use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException; |
| 6 | |
| 7 | /** |
| 8 | * Class DiscountFixedValue |
| 9 | * |
| 10 | * @package AmeliaBooking\Domain\ValueObjects |
| 11 | */ |
| 12 | final class DiscountFixedValue |
| 13 | { |
| 14 | /** |
| 15 | * @var string |
| 16 | */ |
| 17 | private $value; |
| 18 | |
| 19 | /** |
| 20 | * DiscountFixedValue constructor. |
| 21 | * |
| 22 | * @param string $value |
| 23 | * |
| 24 | * @throws InvalidArgumentException |
| 25 | */ |
| 26 | public function __construct($value) |
| 27 | { |
| 28 | if ($value === null) { |
| 29 | throw new InvalidArgumentException('Discount can\'t be empty'); |
| 30 | } |
| 31 | |
| 32 | if (filter_var($value, FILTER_VALIDATE_FLOAT) === false) { |
| 33 | throw new InvalidArgumentException("Discount \"{$value}\" must be float"); |
| 34 | } |
| 35 | |
| 36 | if ($value < 0) { |
| 37 | throw new InvalidArgumentException('Discount must be larger then or equal to 0'); |
| 38 | } |
| 39 | |
| 40 | $this->value = (float)$value; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Return the value from the value object |
| 45 | * |
| 46 | * @return string |
| 47 | */ |
| 48 | public function getValue() |
| 49 | { |
| 50 | return $this->value; |
| 51 | } |
| 52 | } |
| 53 |