HasWalletFloat::forceTransferFloat()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 1
eloc 5
c 2
b 0
f 1
nc 1
nop 3
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Bavix\Wallet\Traits;
4
5
use Bavix\Wallet\Interfaces\Mathable;
6
use Bavix\Wallet\Interfaces\Wallet;
7
use Bavix\Wallet\Models\Transaction;
8
use Bavix\Wallet\Models\Transfer;
9
use Bavix\Wallet\Services\WalletService;
10
11
/**
12
 * Trait HasWalletFloat.
13
 *
14
 *
15
 * @property-read float $balanceFloat
16
 */
17
trait HasWalletFloat
18
{
19
    use HasWallet;
20
21
    /**
22
     * @param float $amount
23
     * @param array|null $meta
24
     * @param bool $confirmed
25
     *
26
     * @return Transaction
27
     */
28 1
    public function forceWithdrawFloat($amount, ?array $meta = null, bool $confirmed = true): Transaction
29
    {
30 1
        $math = app(Mathable::class);
31 1
        $decimalPlacesValue = app(WalletService::class)->decimalPlacesValue($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...e::decimalPlacesValue(). ( Ignorable by Annotation )

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

31
        $decimalPlacesValue = app(WalletService::class)->decimalPlacesValue(/** @scrutinizer ignore-type */ $this);
Loading history...
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
        $result = $math->round($math->mul($amount, $decimalPlaces, $decimalPlacesValue));
34
35 1
        return $this->forceWithdraw($result, $meta, $confirmed);
0 ignored issues
show
Bug introduced by
$result of type string 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

35
        return $this->forceWithdraw(/** @scrutinizer ignore-type */ $result, $meta, $confirmed);
Loading history...
36
    }
37
38
    /**
39
     * @param float $amount
40
     * @param array|null $meta
41
     * @param bool $confirmed
42
     *
43
     * @return Transaction
44
     */
45 12
    public function depositFloat($amount, ?array $meta = null, bool $confirmed = true): Transaction
46
    {
47 12
        $math = app(Mathable::class);
48 12
        $decimalPlacesValue = app(WalletService::class)->decimalPlacesValue($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...e::decimalPlacesValue(). ( Ignorable by Annotation )

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

48
        $decimalPlacesValue = app(WalletService::class)->decimalPlacesValue(/** @scrutinizer ignore-type */ $this);
Loading history...
49 12
        $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

49
        $decimalPlaces = app(WalletService::class)->decimalPlaces(/** @scrutinizer ignore-type */ $this);
Loading history...
50 12
        $result = $math->round($math->mul($amount, $decimalPlaces, $decimalPlacesValue));
51
52 12
        return $this->deposit($result, $meta, $confirmed);
0 ignored issues
show
Bug introduced by
$result of type string 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

52
        return $this->deposit(/** @scrutinizer ignore-type */ $result, $meta, $confirmed);
Loading history...
53
    }
54
55
    /**
56
     * @param float $amount
57
     * @param array|null $meta
58
     * @param bool $confirmed
59
     *
60
     * @return Transaction
61
     */
62 11
    public function withdrawFloat($amount, ?array $meta = null, bool $confirmed = true): Transaction
63
    {
64 11
        $math = app(Mathable::class);
65 11
        $decimalPlacesValue = app(WalletService::class)->decimalPlacesValue($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...e::decimalPlacesValue(). ( Ignorable by Annotation )

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

65
        $decimalPlacesValue = app(WalletService::class)->decimalPlacesValue(/** @scrutinizer ignore-type */ $this);
Loading history...
66 11
        $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

66
        $decimalPlaces = app(WalletService::class)->decimalPlaces(/** @scrutinizer ignore-type */ $this);
Loading history...
67 11
        $result = $math->round($math->mul($amount, $decimalPlaces, $decimalPlacesValue));
68
69 11
        return $this->withdraw($result, $meta, $confirmed);
0 ignored issues
show
Bug introduced by
$result of type string 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

69
        return $this->withdraw(/** @scrutinizer ignore-type */ $result, $meta, $confirmed);
Loading history...
70
    }
71
72
    /**
73
     * @param float $amount
74
     * @return bool
75
     */
76 1
    public function canWithdrawFloat($amount): bool
77
    {
78 1
        $math = app(Mathable::class);
79 1
        $decimalPlacesValue = app(WalletService::class)->decimalPlacesValue($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...e::decimalPlacesValue(). ( Ignorable by Annotation )

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

79
        $decimalPlacesValue = app(WalletService::class)->decimalPlacesValue(/** @scrutinizer ignore-type */ $this);
Loading history...
80 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

80
        $decimalPlaces = app(WalletService::class)->decimalPlaces(/** @scrutinizer ignore-type */ $this);
Loading history...
81 1
        $result = $math->round($math->mul($amount, $decimalPlaces, $decimalPlacesValue));
82
83 1
        return $this->canWithdraw($result);
0 ignored issues
show
Bug introduced by
$result of type string 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

83
        return $this->canWithdraw(/** @scrutinizer ignore-type */ $result);
Loading history...
84
    }
85
86
    /**
87
     * @param Wallet $wallet
88
     * @param float $amount
89
     * @param array|null $meta
90
     * @return Transfer
91
     * @throws
92
     */
93 2
    public function transferFloat(Wallet $wallet, $amount, ?array $meta = null): Transfer
94
    {
95 2
        $math = app(Mathable::class);
96 2
        $decimalPlacesValue = app(WalletService::class)->decimalPlacesValue($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...e::decimalPlacesValue(). ( Ignorable by Annotation )

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

96
        $decimalPlacesValue = app(WalletService::class)->decimalPlacesValue(/** @scrutinizer ignore-type */ $this);
Loading history...
97 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

97
        $decimalPlaces = app(WalletService::class)->decimalPlaces(/** @scrutinizer ignore-type */ $this);
Loading history...
98 2
        $result = $math->round($math->mul($amount, $decimalPlaces, $decimalPlacesValue));
99
100 2
        return $this->transfer($wallet, $result, $meta);
0 ignored issues
show
Bug introduced by
$result of type string 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

100
        return $this->transfer($wallet, /** @scrutinizer ignore-type */ $result, $meta);
Loading history...
101
    }
102
103
    /**
104
     * @param Wallet $wallet
105
     * @param float $amount
106
     * @param array|null $meta
107
     * @return null|Transfer
108
     */
109 1
    public function safeTransferFloat(Wallet $wallet, $amount, ?array $meta = null): ?Transfer
110
    {
111 1
        $math = app(Mathable::class);
112 1
        $decimalPlacesValue = app(WalletService::class)->decimalPlacesValue($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...e::decimalPlacesValue(). ( Ignorable by Annotation )

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

112
        $decimalPlacesValue = app(WalletService::class)->decimalPlacesValue(/** @scrutinizer ignore-type */ $this);
Loading history...
113 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

113
        $decimalPlaces = app(WalletService::class)->decimalPlaces(/** @scrutinizer ignore-type */ $this);
Loading history...
114 1
        $result = $math->round($math->mul($amount, $decimalPlaces, $decimalPlacesValue));
115
116 1
        return $this->safeTransfer($wallet, $result, $meta);
0 ignored issues
show
Bug introduced by
$result of type string 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

116
        return $this->safeTransfer($wallet, /** @scrutinizer ignore-type */ $result, $meta);
Loading history...
117
    }
118
119
    /**
120
     * @param Wallet $wallet
121
     * @param float $amount
122
     * @param array|null $meta
123
     * @return Transfer
124
     */
125 1
    public function forceTransferFloat(Wallet $wallet, $amount, ?array $meta = null): Transfer
126
    {
127 1
        $math = app(Mathable::class);
128 1
        $decimalPlacesValue = app(WalletService::class)->decimalPlacesValue($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...e::decimalPlacesValue(). ( Ignorable by Annotation )

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

128
        $decimalPlacesValue = app(WalletService::class)->decimalPlacesValue(/** @scrutinizer ignore-type */ $this);
Loading history...
129 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

129
        $decimalPlaces = app(WalletService::class)->decimalPlaces(/** @scrutinizer ignore-type */ $this);
Loading history...
130 1
        $result = $math->round($math->mul($amount, $decimalPlaces, $decimalPlacesValue));
131
132 1
        return $this->forceTransfer($wallet, $result, $meta);
0 ignored issues
show
Bug introduced by
$result of type string 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

132
        return $this->forceTransfer($wallet, /** @scrutinizer ignore-type */ $result, $meta);
Loading history...
133
    }
134
135
    /**
136
     * @return int|float
137
     */
138 14
    public function getBalanceFloatAttribute()
139
    {
140 14
        $math = app(Mathable::class);
141 14
        $decimalPlacesValue = app(WalletService::class)->decimalPlacesValue($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...e::decimalPlacesValue(). ( Ignorable by Annotation )

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

141
        $decimalPlacesValue = app(WalletService::class)->decimalPlacesValue(/** @scrutinizer ignore-type */ $this);
Loading history...
142 14
        $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

142
        $decimalPlaces = app(WalletService::class)->decimalPlaces(/** @scrutinizer ignore-type */ $this);
Loading history...
143
144 14
        return $math->div($this->balance, $decimalPlaces, $decimalPlacesValue);
145
    }
146
}
147