Total Complexity | 6 |
Total Lines | 34 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
16 | class Wallet extends ValueObjectMap |
||
17 | { |
||
18 | 1 | public function isEmpty(): bool |
|
19 | { |
||
20 | 1 | return $this->reduce( |
|
21 | 1 | fn(bool $carry, string $currency, MoneyInterface $money): bool => $carry && $money->isZero(), |
|
22 | 1 | true |
|
23 | ); |
||
24 | } |
||
25 | |||
26 | 4 | public function getBalance(string $currency): MoneyInterface |
|
27 | { |
||
28 | /** @var MoneyInterface $balance */ |
||
29 | 4 | $balance = $this->get($currency, Money::zero($currency)); |
|
30 | 4 | return $balance; |
|
31 | } |
||
32 | |||
33 | 1 | public function hasBalance(MoneyInterface $amount): bool |
|
34 | { |
||
35 | 1 | return $this->getBalance($amount->getCurrency())->isGreaterThanOrEqual($amount); |
|
36 | } |
||
37 | |||
38 | 2 | public function credit(MoneyInterface $amount): self |
|
39 | { |
||
40 | 2 | $currency = $amount->getCurrency(); |
|
41 | 2 | $balance = $this->getBalance($currency); |
|
42 | 2 | return $this->with($currency, $balance->add($amount)); |
|
43 | } |
||
44 | |||
45 | 1 | public function debit(MoneyInterface $amount): self |
|
50 | } |
||
51 | } |
||
52 |