1 | <?php |
||
15 | final class Minute extends Embeddable |
||
16 | { |
||
17 | /** |
||
18 | * @param string|int $value |
||
19 | * |
||
20 | * @throws \InvalidArgumentException |
||
21 | * @throws \OutOfRangeException |
||
22 | */ |
||
23 | 62 | public function __construct($value) |
|
24 | { |
||
25 | 62 | if (is_int($value)) { |
|
26 | 20 | $value = (string)$value; |
|
27 | } |
||
28 | |||
29 | 62 | if (!is_string($value) || !ctype_digit($value)) { |
|
30 | 9 | throw new \InvalidArgumentException(sprintf('Expected string or integer and got %s', gettype($value))); |
|
31 | } |
||
32 | |||
33 | 53 | $value = str_pad($value, 2, 0, STR_PAD_LEFT); |
|
34 | |||
35 | 53 | if ((mb_strlen($value) !== 2) || !in_array((int)$value, range(0, 59), true)) { |
|
36 | 7 | throw new \OutOfRangeException('Expected a numeric representation of minutes.'); |
|
37 | } |
||
38 | |||
39 | 46 | $this->value = $value; |
|
40 | 46 | } |
|
41 | |||
42 | /** |
||
43 | * {@inheritdoc} |
||
44 | */ |
||
45 | 7 | public function equals(Embeddable $object) |
|
49 | } |
||
50 |