Total Complexity | 4 |
Total Lines | 39 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
8 | class MemoryStore implements Storable |
||
9 | { |
||
10 | |||
11 | /** |
||
12 | * @var array |
||
13 | */ |
||
14 | protected $balanceSheets = []; |
||
15 | |||
16 | /** |
||
17 | * @inheritDoc |
||
18 | */ |
||
19 | 86 | public function getBalance($object): int |
|
20 | { |
||
21 | 86 | $wallet = app(WalletService::class)->getWallet($object); |
|
22 | 86 | if (!\array_key_exists($wallet->getKey(), $this->balanceSheets)) { |
|
23 | 86 | $this->balanceSheets[$wallet->getKey()] = (int) $wallet->getOriginal('balance', 0); |
|
24 | } |
||
25 | |||
26 | 86 | return $this->balanceSheets[$wallet->getKey()]; |
|
27 | } |
||
28 | |||
29 | /** |
||
30 | * @inheritDoc |
||
31 | */ |
||
32 | 70 | public function incBalance($object, int $amount): int |
|
33 | { |
||
34 | 70 | $balance = $this->getBalance($object) + $amount; |
|
35 | 70 | $this->setBalance($object, $balance); |
|
36 | 70 | return $balance; |
|
37 | } |
||
38 | |||
39 | /** |
||
40 | * @inheritDoc |
||
41 | */ |
||
42 | 70 | public function setBalance($object, int $amount): bool |
|
47 | } |
||
48 | |||
49 | } |
||
50 |