Completed
Pull Request — master (#104)
by Бабичев
175:52 queued 91:10
created

MemoryStore::getBalance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 5
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 2
rs 10
1
<?php
2
3
namespace Bavix\Wallet\Simple;
4
5
use Bavix\Wallet\Interfaces\Storable;
6
use Bavix\Wallet\Services\ProxyService;
7
use Bavix\Wallet\Services\WalletService;
8
9
class MemoryStore implements Storable
10
{
11
12
    /**
13
     * @inheritDoc
14
     */
15 84
    public function getBalance($object): int
16
    {
17 84
        $wallet = app(WalletService::class)->getWallet($object);
18 84
        $proxy = app(ProxyService::class);
19 84
        if (!$proxy->has($wallet->getKey())) {
0 ignored issues
show
Bug introduced by
It seems like $wallet->getKey() can also be of type boolean and null; however, parameter $key of Bavix\Wallet\Services\ProxyService::has() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

19
        if (!$proxy->has(/** @scrutinizer ignore-type */ $wallet->getKey())) {
Loading history...
20 84
            $proxy->set($wallet->getKey(), (int) $wallet->getOriginal('balance', 0));
0 ignored issues
show
Bug introduced by
It seems like $wallet->getKey() can also be of type boolean and null; however, parameter $key of Bavix\Wallet\Services\ProxyService::set() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

20
            $proxy->set(/** @scrutinizer ignore-type */ $wallet->getKey(), (int) $wallet->getOriginal('balance', 0));
Loading history...
21
        }
22
23 84
        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())) {
0 ignored issues
show
Bug introduced by
It seems like $wallet->getKey() can also be of type boolean and null; however, parameter $key of Bavix\Wallet\Services\ProxyService::has() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
        if ($proxy->has(/** @scrutinizer ignore-type */ $wallet->getKey())) {
Loading history...
36 68
            $balance = $proxy->get($wallet->getKey()) + $amount;
0 ignored issues
show
Bug introduced by
It seems like $wallet->getKey() can also be of type boolean and null; however, parameter $key of Bavix\Wallet\Services\ProxyService::get() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

36
            $balance = $proxy->get(/** @scrutinizer ignore-type */ $wallet->getKey()) + $amount;
Loading history...
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
47
    {
48 68
        $wallet = app(WalletService::class)->getWallet($object);
49 68
        $proxy = app(ProxyService::class);
50 68
        return (bool)$proxy->set($wallet->getKey(), $amount);
0 ignored issues
show
Bug introduced by
It seems like $wallet->getKey() can also be of type boolean and null; however, parameter $key of Bavix\Wallet\Services\ProxyService::set() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

50
        return (bool)$proxy->set(/** @scrutinizer ignore-type */ $wallet->getKey(), $amount);
Loading history...
51
    }
52
53
}
54