1 | <?php |
||
6 | final class Ticket |
||
7 | { |
||
8 | private $numerator; |
||
9 | |||
10 | private $divisor; |
||
11 | |||
12 | /** |
||
13 | * Ticket constructor. |
||
14 | * |
||
15 | * @param int $numerator |
||
16 | * @param int $divisor |
||
17 | */ |
||
18 | 4 | public function __construct(int $numerator, int $divisor) |
|
25 | |||
26 | 4 | private function assertValidNumerator(int $numerator) |
|
27 | { |
||
28 | 4 | if ($numerator <= 0) { |
|
29 | 2 | throw new InvalidArgumentException( |
|
30 | 2 | sprintf( |
|
31 | 2 | 'Expected a positive $numerator, but instead got: %d', |
|
32 | 2 | $numerator |
|
33 | ) |
||
34 | ); |
||
35 | } |
||
36 | 3 | } |
|
37 | |||
38 | 3 | private function assertValidDivisor(int $numerator, int $divisor) |
|
39 | { |
||
40 | 3 | if ($divisor <= 0) { |
|
41 | throw new InvalidArgumentException( |
||
42 | sprintf( |
||
43 | 'Expected a positive $divisor, but instead got: %d', |
||
44 | $divisor |
||
45 | ) |
||
46 | ); |
||
47 | } |
||
48 | |||
49 | 3 | if ($divisor < $numerator) { |
|
50 | 1 | throw new InvalidArgumentException( |
|
51 | 1 | sprintf( |
|
52 | 1 | 'Expected a $divisor that is equal or greater than the $numerator, but instead got: %d < %d', |
|
53 | 1 | $divisor, |
|
54 | 1 | $numerator |
|
55 | ) |
||
56 | ); |
||
57 | } |
||
58 | 3 | } |
|
59 | |||
60 | 1 | public function getNumerator() : int |
|
64 | |||
65 | 1 | public function getDivisor() : int |
|
69 | } |
||
70 |