1 | <?php |
||
15 | final class Money |
||
16 | { |
||
17 | use Calculation; |
||
18 | use Formatters; |
||
19 | |||
20 | const SCALE = 6; |
||
21 | |||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | private $amount; |
||
26 | |||
27 | /** |
||
28 | * @var Currency |
||
29 | */ |
||
30 | private $currency; |
||
31 | |||
32 | /** |
||
33 | * @param string $amount |
||
34 | * @param Currency $currency |
||
35 | */ |
||
36 | 18 | public function __construct($amount, Currency $currency) |
|
41 | |||
42 | /** |
||
43 | * @return Currency |
||
44 | */ |
||
45 | 11 | public function getCurrency() |
|
49 | |||
50 | /** |
||
51 | * @return string |
||
52 | */ |
||
53 | 13 | public function getAmount() |
|
57 | |||
58 | /** |
||
59 | * @param string $amount |
||
60 | * |
||
61 | * @return self |
||
62 | */ |
||
63 | 6 | public function newInstance($amount) |
|
67 | |||
68 | /** |
||
69 | * @param Money $other |
||
70 | * |
||
71 | * @return bool |
||
72 | */ |
||
73 | 1 | public function equals(Money $other) |
|
77 | |||
78 | /** |
||
79 | * @param Money $other |
||
80 | * @throws InvalidArgumentException |
||
81 | * |
||
82 | * @return self |
||
83 | */ |
||
84 | 6 | private function assertSameCurrency(Money $other) |
|
92 | |||
93 | /** |
||
94 | * @param Money $other |
||
95 | * @throws InvalidArgumentException |
||
96 | * |
||
97 | * @return int |
||
98 | */ |
||
99 | 2 | public function compare(Money $other) |
|
105 | |||
106 | /** |
||
107 | * @param Money $addend |
||
108 | * @throws InvalidArgumentException |
||
109 | * |
||
110 | * @return Money |
||
111 | */ |
||
112 | 2 | public function add(Money $addend) |
|
118 | |||
119 | /** |
||
120 | * @param Percentage $percentage |
||
121 | * |
||
122 | * @return Money |
||
123 | */ |
||
124 | 1 | public function addPercent(Percentage $percentage) |
|
130 | |||
131 | /** |
||
132 | * @param Money $subtrahend |
||
133 | * @throws InvalidArgumentException |
||
134 | * |
||
135 | * @return Money |
||
136 | */ |
||
137 | 2 | public function sub(Money $subtrahend) |
|
143 | |||
144 | /** |
||
145 | * @param Percentage $percentage |
||
146 | * |
||
147 | * @return Money |
||
148 | */ |
||
149 | 1 | public function subPercent(Percentage $percentage) |
|
155 | |||
156 | /** |
||
157 | * @param int $decimals |
||
158 | * @param string $decPoint |
||
159 | * @param string $thousandsSep |
||
160 | * |
||
161 | * @return string |
||
162 | */ |
||
163 | 2 | public function getFormat($decimals = 2, $decPoint = ',', $thousandsSep = '.') |
|
167 | |||
168 | /** |
||
169 | * @param int $decimals |
||
170 | * |
||
171 | * @return string |
||
172 | */ |
||
173 | 1 | public function getRound($decimals = 2) |
|
177 | |||
178 | /** |
||
179 | * @param int $decimals |
||
180 | * |
||
181 | * @return string |
||
182 | */ |
||
183 | 1 | public function getTruncate($decimals = 2) |
|
187 | |||
188 | /** |
||
189 | * @return int |
||
190 | */ |
||
191 | 1 | public function getMicros() |
|
195 | |||
196 | /** |
||
197 | * @return string |
||
198 | */ |
||
199 | 1 | public function __toString() |
|
203 | } |
||
204 |