1 | <?php |
||
13 | final class Euro { |
||
14 | |||
15 | private static $DECIMAL_COUNT = 2; |
||
16 | private static $CENTS_PER_EURO = 100; |
||
17 | |||
18 | private $cents; |
||
19 | |||
20 | /** |
||
21 | * @param int $cents |
||
22 | * @throws InvalidArgumentException |
||
23 | */ |
||
24 | 52 | private function __construct( int $cents ) { |
|
31 | |||
32 | /** |
||
33 | * @param int $cents |
||
34 | * @return self |
||
35 | * @throws InvalidArgumentException |
||
36 | */ |
||
37 | 30 | public static function newFromCents( int $cents ): self { |
|
40 | |||
41 | /** |
||
42 | * Constructs a Euro object from a string representation such as "13.37". |
||
43 | * |
||
44 | * This method takes into account the errors that can arise from floating |
||
45 | * point number usage. Amounts with too many decimals are rounded to the |
||
46 | * nearest whole euro cent amount. |
||
47 | * |
||
48 | * @param string $euroAmount |
||
49 | * @return self |
||
50 | * @throws InvalidArgumentException |
||
51 | */ |
||
52 | 15 | public static function newFromString( string $euroAmount ): self { |
|
64 | |||
65 | 12 | private static function centsFromString( string $cents ): int { |
|
73 | |||
74 | 2 | private static function roundCentsToInt( string $cents ): int { |
|
83 | |||
84 | /** |
||
85 | * This method takes into account the errors that can arise from floating |
||
86 | * point number usage. Amounts with too many decimals are rounded to the |
||
87 | * nearest whole euro cent amount. |
||
88 | * |
||
89 | * @param float $euroAmount |
||
90 | * @return self |
||
91 | * @throws InvalidArgumentException |
||
92 | */ |
||
93 | 6 | public static function newFromFloat( float $euroAmount ) { |
|
101 | |||
102 | /** |
||
103 | * @param int $euroAmount |
||
104 | * @return self |
||
105 | * @throws InvalidArgumentException |
||
106 | */ |
||
107 | 5 | public static function newFromInt( int $euroAmount ) { |
|
110 | |||
111 | 32 | public function getEuroCents(): int { |
|
114 | |||
115 | 10 | public function getEuroFloat(): float { |
|
118 | |||
119 | /** |
||
120 | * Returns the euro amount as string with two decimals always present in format "42.00". |
||
121 | */ |
||
122 | 6 | public function getEuroString(): string { |
|
125 | |||
126 | 10 | public function equals( Euro $euro ): bool { |
|
129 | |||
130 | } |
||
131 |