| Total Complexity | 5 |
| Total Lines | 42 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 9 | class MemoryStore implements Storable |
||
| 10 | { |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @inheritDoc |
||
| 14 | */ |
||
| 15 | 82 | public function getBalance($object): int |
|
| 16 | { |
||
| 17 | 82 | $wallet = app(WalletService::class)->getWallet($object); |
|
| 18 | 82 | $proxy = app(ProxyService::class); |
|
| 19 | 82 | if (!$proxy->has($wallet->getKey())) { |
|
|
|
|||
| 20 | 82 | $proxy->set($wallet->getKey(), (int) $wallet->getOriginal('balance', 0)); |
|
| 21 | } |
||
| 22 | |||
| 23 | 82 | return $proxy[$wallet->getKey()]; |
|
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @inheritDoc |
||
| 28 | */ |
||
| 29 | 68 | public function incBalance($object, int $amount): int |
|
| 30 | { |
||
| 31 | 68 | $wallet = app(WalletService::class)->getWallet($object); |
|
| 32 | 68 | $proxy = app(ProxyService::class); |
|
| 33 | 68 | $balance = $wallet->balance + $amount; |
|
| 34 | |||
| 35 | 68 | if ($proxy->has($wallet->getKey())) { |
|
| 36 | 68 | $balance = $proxy->get($wallet->getKey()) + $amount; |
|
| 37 | } |
||
| 38 | |||
| 39 | 68 | $this->setBalance($object, $balance); |
|
| 40 | 68 | return $balance; |
|
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @inheritDoc |
||
| 45 | */ |
||
| 46 | 68 | public function setBalance($object, int $amount): bool |
|
| 51 | } |
||
| 52 | |||
| 53 | } |
||
| 54 |