Passed
Pull Request — master (#51)
by Бабичев
04:52
created

HasWalletFloat::forceTransferFloat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 2
b 0
f 0
nc 1
nop 3
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Bavix\Wallet\Traits;
4
5
use Bavix\Wallet\Interfaces\Wallet;
6
use Bavix\Wallet\Models\Transaction;
7
use Bavix\Wallet\Models\Transfer;
8
use Bavix\Wallet\Services\CommonService;
9
use Bavix\Wallet\Services\WalletService;
10
use function config;
11
12
/**
13
 * Trait HasWalletFloat
14
 *
15
 * @package Bavix\Wallet\Traits
16
 *
17
 * @property-read float $balanceFloat
18
 */
19
trait HasWalletFloat
20
{
21
    use HasWallet;
22
23
    /**
24
     * @param float $amount
25
     * @param array|null $meta
26
     * @param bool $confirmed
27
     *
28
     * @return Transaction
29
     */
30 1
    public function forceWithdrawFloat(float $amount, ?array $meta = null, bool $confirmed = true): Transaction
31
    {
32 1
        $decimalPlaces = app(WalletService::class)->decimalPlaces($this);
0 ignored issues
show
Bug introduced by
$this of type Bavix\Wallet\Traits\HasWalletFloat is incompatible with the type Bavix\Wallet\Interfaces\Wallet expected by parameter $object of Bavix\Wallet\Services\Wa...ervice::decimalPlaces(). ( Ignorable by Annotation )

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

32
        $decimalPlaces = app(WalletService::class)->decimalPlaces(/** @scrutinizer ignore-type */ $this);
Loading history...
33 1
        return $this->forceWithdraw($amount * $decimalPlaces, $meta, $confirmed);
0 ignored issues
show
Bug introduced by
$amount * $decimalPlaces of type double is incompatible with the type integer expected by parameter $amount of Bavix\Wallet\Traits\HasW...tFloat::forceWithdraw(). ( Ignorable by Annotation )

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

33
        return $this->forceWithdraw(/** @scrutinizer ignore-type */ $amount * $decimalPlaces, $meta, $confirmed);
Loading history...
34
    }
35
36
    /**
37
     * @param float $amount
38
     * @param array|null $meta
39
     * @param bool $confirmed
40
     *
41
     * @return Transaction
42
     */
43 6
    public function depositFloat(float $amount, ?array $meta = null, bool $confirmed = true): Transaction
44
    {
45 6
        $decimalPlaces = app(WalletService::class)->decimalPlaces($this);
0 ignored issues
show
Bug introduced by
$this of type Bavix\Wallet\Traits\HasWalletFloat is incompatible with the type Bavix\Wallet\Interfaces\Wallet expected by parameter $object of Bavix\Wallet\Services\Wa...ervice::decimalPlaces(). ( Ignorable by Annotation )

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

45
        $decimalPlaces = app(WalletService::class)->decimalPlaces(/** @scrutinizer ignore-type */ $this);
Loading history...
46 6
        return $this->deposit($amount * $decimalPlaces, $meta, $confirmed);
0 ignored issues
show
Bug introduced by
$amount * $decimalPlaces of type double is incompatible with the type integer expected by parameter $amount of Bavix\Wallet\Traits\HasWalletFloat::deposit(). ( Ignorable by Annotation )

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

46
        return $this->deposit(/** @scrutinizer ignore-type */ $amount * $decimalPlaces, $meta, $confirmed);
Loading history...
47
    }
48
49
    /**
50
     * @param float $amount
51
     * @param array|null $meta
52
     * @param bool $confirmed
53
     *
54
     * @return Transaction
55
     */
56 6
    public function withdrawFloat(float $amount, ?array $meta = null, bool $confirmed = true): Transaction
57
    {
58 6
        $decimalPlaces = app(WalletService::class)->decimalPlaces($this);
0 ignored issues
show
Bug introduced by
$this of type Bavix\Wallet\Traits\HasWalletFloat is incompatible with the type Bavix\Wallet\Interfaces\Wallet expected by parameter $object of Bavix\Wallet\Services\Wa...ervice::decimalPlaces(). ( Ignorable by Annotation )

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

58
        $decimalPlaces = app(WalletService::class)->decimalPlaces(/** @scrutinizer ignore-type */ $this);
Loading history...
59 6
        return $this->withdraw($amount * $decimalPlaces, $meta, $confirmed);
0 ignored issues
show
Bug introduced by
$amount * $decimalPlaces of type double is incompatible with the type integer expected by parameter $amount of Bavix\Wallet\Traits\HasWalletFloat::withdraw(). ( Ignorable by Annotation )

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

59
        return $this->withdraw(/** @scrutinizer ignore-type */ $amount * $decimalPlaces, $meta, $confirmed);
Loading history...
60
    }
61
62
    /**
63
     * @param float $amount
64
     * @return bool
65
     */
66 1
    public function canWithdrawFloat(float $amount): bool
67
    {
68 1
        $decimalPlaces = app(WalletService::class)->decimalPlaces($this);
0 ignored issues
show
Bug introduced by
$this of type Bavix\Wallet\Traits\HasWalletFloat is incompatible with the type Bavix\Wallet\Interfaces\Wallet expected by parameter $object of Bavix\Wallet\Services\Wa...ervice::decimalPlaces(). ( Ignorable by Annotation )

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

68
        $decimalPlaces = app(WalletService::class)->decimalPlaces(/** @scrutinizer ignore-type */ $this);
Loading history...
69 1
        return $this->canWithdraw($amount * $decimalPlaces);
0 ignored issues
show
Bug introduced by
$amount * $decimalPlaces of type double is incompatible with the type integer expected by parameter $amount of Bavix\Wallet\Traits\HasWalletFloat::canWithdraw(). ( Ignorable by Annotation )

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

69
        return $this->canWithdraw(/** @scrutinizer ignore-type */ $amount * $decimalPlaces);
Loading history...
70
    }
71
72
    /**
73
     * @param Wallet $wallet
74
     * @param float $amount
75
     * @param array|null $meta
76
     * @return Transfer
77
     * @throws
78
     */
79 2
    public function transferFloat(Wallet $wallet, float $amount, ?array $meta = null): Transfer
80
    {
81 2
        $decimalPlaces = app(WalletService::class)->decimalPlaces($this);
0 ignored issues
show
Bug introduced by
$this of type Bavix\Wallet\Traits\HasWalletFloat is incompatible with the type Bavix\Wallet\Interfaces\Wallet expected by parameter $object of Bavix\Wallet\Services\Wa...ervice::decimalPlaces(). ( Ignorable by Annotation )

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

81
        $decimalPlaces = app(WalletService::class)->decimalPlaces(/** @scrutinizer ignore-type */ $this);
Loading history...
82 2
        return $this->transfer($wallet, $amount * $decimalPlaces, $meta);
0 ignored issues
show
Bug introduced by
$amount * $decimalPlaces of type double is incompatible with the type integer expected by parameter $amount of Bavix\Wallet\Traits\HasWalletFloat::transfer(). ( Ignorable by Annotation )

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

82
        return $this->transfer($wallet, /** @scrutinizer ignore-type */ $amount * $decimalPlaces, $meta);
Loading history...
83
    }
84
85
    /**
86
     * @param Wallet $wallet
87
     * @param float $amount
88
     * @param array|null $meta
89
     * @return null|Transfer
90
     */
91 1
    public function safeTransferFloat(Wallet $wallet, float $amount, ?array $meta = null): ?Transfer
92
    {
93 1
        $decimalPlaces = app(WalletService::class)->decimalPlaces($this);
0 ignored issues
show
Bug introduced by
$this of type Bavix\Wallet\Traits\HasWalletFloat is incompatible with the type Bavix\Wallet\Interfaces\Wallet expected by parameter $object of Bavix\Wallet\Services\Wa...ervice::decimalPlaces(). ( Ignorable by Annotation )

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

93
        $decimalPlaces = app(WalletService::class)->decimalPlaces(/** @scrutinizer ignore-type */ $this);
Loading history...
94 1
        return $this->safeTransfer($wallet, $amount * $decimalPlaces, $meta);
0 ignored issues
show
Bug introduced by
$amount * $decimalPlaces of type double is incompatible with the type integer expected by parameter $amount of Bavix\Wallet\Traits\HasWalletFloat::safeTransfer(). ( Ignorable by Annotation )

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

94
        return $this->safeTransfer($wallet, /** @scrutinizer ignore-type */ $amount * $decimalPlaces, $meta);
Loading history...
95
    }
96
97
    /**
98
     * @param Wallet $wallet
99
     * @param float $amount
100
     * @param array|null $meta
101
     * @return Transfer
102
     */
103 1
    public function forceTransferFloat(Wallet $wallet, float $amount, ?array $meta = null): Transfer
104
    {
105 1
        $decimalPlaces = app(WalletService::class)->decimalPlaces($this);
0 ignored issues
show
Bug introduced by
$this of type Bavix\Wallet\Traits\HasWalletFloat is incompatible with the type Bavix\Wallet\Interfaces\Wallet expected by parameter $object of Bavix\Wallet\Services\Wa...ervice::decimalPlaces(). ( Ignorable by Annotation )

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

105
        $decimalPlaces = app(WalletService::class)->decimalPlaces(/** @scrutinizer ignore-type */ $this);
Loading history...
106 1
        return $this->forceTransfer($wallet, $amount * $decimalPlaces, $meta);
0 ignored issues
show
Bug introduced by
$amount * $decimalPlaces of type double is incompatible with the type integer expected by parameter $amount of Bavix\Wallet\Traits\HasW...tFloat::forceTransfer(). ( Ignorable by Annotation )

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

106
        return $this->forceTransfer($wallet, /** @scrutinizer ignore-type */ $amount * $decimalPlaces, $meta);
Loading history...
107
    }
108
109
    /**
110
     * @return float
111
     */
112 6
    public function getBalanceFloatAttribute(): float
113
    {
114 6
        $decimalPlaces = app(WalletService::class)->decimalPlaces($this);
0 ignored issues
show
Bug introduced by
$this of type Bavix\Wallet\Traits\HasWalletFloat is incompatible with the type Bavix\Wallet\Interfaces\Wallet expected by parameter $object of Bavix\Wallet\Services\Wa...ervice::decimalPlaces(). ( Ignorable by Annotation )

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

114
        $decimalPlaces = app(WalletService::class)->decimalPlaces(/** @scrutinizer ignore-type */ $this);
Loading history...
115 6
        return $this->balance / $decimalPlaces;
116
    }
117
118
}
119