1 | <?php |
||
7 | class Money |
||
8 | { |
||
9 | /** |
||
10 | * Money amount in cents. |
||
11 | * |
||
12 | * @var int |
||
13 | */ |
||
14 | protected $amount = 0; |
||
15 | |||
16 | /** |
||
17 | * Number of digits after the decimal place. |
||
18 | * |
||
19 | * @var int |
||
20 | */ |
||
21 | protected $scale = 2; |
||
22 | |||
23 | public function __construct(float $amount = 0) |
||
27 | |||
28 | public static function fromCents(float $cents): Money |
||
35 | |||
36 | public function add(Money $operand): Money |
||
42 | |||
43 | public function subtract(Money $operand): Money |
||
49 | |||
50 | public function multiply(float $multiplier): Money |
||
56 | |||
57 | public function divide(float $divisor): Money |
||
63 | |||
64 | public function getPercentage(float $percentage): Money |
||
71 | |||
72 | public function applyPercentage(float $percentage): Money |
||
78 | |||
79 | public function getInterest(float $rate, int $duration): Money |
||
86 | |||
87 | public function applyInterest(float $rate, int $duration): Money |
||
93 | |||
94 | public function equals($other): bool |
||
102 | |||
103 | public function greaterThan(Money $other): bool |
||
107 | |||
108 | public function lessThan(Money $other): bool |
||
112 | |||
113 | public function isZero(): bool |
||
117 | |||
118 | public function isPositive(): bool |
||
122 | |||
123 | public function isNegative(): bool |
||
127 | |||
128 | public function getMoneyAmount(): float |
||
134 | |||
135 | public function getAmount(): int |
||
139 | |||
140 | public function setAmount(float $amount) |
||
144 | |||
145 | public function getScale(): int |
||
149 | |||
150 | public function setScale(int $scale) |
||
154 | |||
155 | public function __toString(): string |
||
159 | } |
||
160 |