Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame^] | 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This file is part of the Carbon package. |
| 5 | * |
| 6 | * (c) Brian Nesbitt <brian@nesbot.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | namespace Carbon\Exceptions; |
| 12 | |
| 13 | use Exception; |
| 14 | use InvalidArgumentException as BaseInvalidArgumentException; |
| 15 | |
| 16 | // This will extends OutOfRangeException instead of InvalidArgumentException since 3.0.0 |
| 17 | // use OutOfRangeException as BaseOutOfRangeException; |
| 18 | |
| 19 | class OutOfRangeException extends BaseInvalidArgumentException implements InvalidArgumentException |
| 20 | { |
| 21 | /** |
| 22 | * The unit or name of the value. |
| 23 | * |
| 24 | * @var string |
| 25 | */ |
| 26 | private $unit; |
| 27 | |
| 28 | /** |
| 29 | * The range minimum. |
| 30 | * |
| 31 | * @var mixed |
| 32 | */ |
| 33 | private $min; |
| 34 | |
| 35 | /** |
| 36 | * The range maximum. |
| 37 | * |
| 38 | * @var mixed |
| 39 | */ |
| 40 | private $max; |
| 41 | |
| 42 | /** |
| 43 | * The invalid value. |
| 44 | * |
| 45 | * @var mixed |
| 46 | */ |
| 47 | private $value; |
| 48 | |
| 49 | /** |
| 50 | * Constructor. |
| 51 | * |
| 52 | * @param string $unit |
| 53 | * @param mixed $min |
| 54 | * @param mixed $max |
| 55 | * @param mixed $value |
| 56 | * @param int $code |
| 57 | * @param Exception|null $previous |
| 58 | */ |
| 59 | public function __construct($unit, $min, $max, $value, $code = 0, Exception $previous = null) |
| 60 | { |
| 61 | $this->unit = $unit; |
| 62 | $this->min = $min; |
| 63 | $this->max = $max; |
| 64 | $this->value = $value; |
| 65 | |
| 66 | parent::__construct("$unit must be between $min and $max, $value given", $code, $previous); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * @return mixed |
| 71 | */ |
| 72 | public function getMax() |
| 73 | { |
| 74 | return $this->max; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * @return mixed |
| 79 | */ |
| 80 | public function getMin() |
| 81 | { |
| 82 | return $this->min; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * @return mixed |
| 87 | */ |
| 88 | public function getUnit() |
| 89 | { |
| 90 | return $this->unit; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * @return mixed |
| 95 | */ |
| 96 | public function getValue() |
| 97 | { |
| 98 | return $this->value; |
| 99 | } |
| 100 | } |