blob: 54822d954327794665c2da7bdb04489c1d6c82f3 [file] [log] [blame]
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001<?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 */
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010011
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020012namespace Carbon\Exceptions;
13
14use Exception;
15use InvalidArgumentException as BaseInvalidArgumentException;
16
17// This will extends OutOfRangeException instead of InvalidArgumentException since 3.0.0
18// use OutOfRangeException as BaseOutOfRangeException;
19
20class OutOfRangeException extends BaseInvalidArgumentException implements InvalidArgumentException
21{
22 /**
23 * The unit or name of the value.
24 *
25 * @var string
26 */
27 private $unit;
28
29 /**
30 * The range minimum.
31 *
32 * @var mixed
33 */
34 private $min;
35
36 /**
37 * The range maximum.
38 *
39 * @var mixed
40 */
41 private $max;
42
43 /**
44 * The invalid value.
45 *
46 * @var mixed
47 */
48 private $value;
49
50 /**
51 * Constructor.
52 *
53 * @param string $unit
54 * @param mixed $min
55 * @param mixed $max
56 * @param mixed $value
57 * @param int $code
58 * @param Exception|null $previous
59 */
60 public function __construct($unit, $min, $max, $value, $code = 0, Exception $previous = null)
61 {
62 $this->unit = $unit;
63 $this->min = $min;
64 $this->max = $max;
65 $this->value = $value;
66
67 parent::__construct("$unit must be between $min and $max, $value given", $code, $previous);
68 }
69
70 /**
71 * @return mixed
72 */
73 public function getMax()
74 {
75 return $this->max;
76 }
77
78 /**
79 * @return mixed
80 */
81 public function getMin()
82 {
83 return $this->min;
84 }
85
86 /**
87 * @return mixed
88 */
89 public function getUnit()
90 {
91 return $this->unit;
92 }
93
94 /**
95 * @return mixed
96 */
97 public function getValue()
98 {
99 return $this->value;
100 }
101}