Test Failed
Push — master ( 72daf6...986bed )
by Бабичев
03:30
created

HasWalletFloat::transferFloat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
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 function config;
10
11
/**
12
 * Trait HasWalletFloat
13
 *
14
 * @package Bavix\Wallet\Traits
15
 *
16
 * @property-read float $balanceFloat
17
 */
18
trait HasWalletFloat
19
{
20
    use HasWallet;
21
22
    /**
23
     * @param float $amount
24
     * @param array|null $meta
25
     * @param bool $confirmed
26
     *
27
     * @return Transaction
28
     */
29
    public function forceWithdrawFloat(float $amount, ?array $meta = null, bool $confirmed = true): Transaction
30
    {
31
        return $this->forceWithdraw($amount * $this->coefficient(), $meta, $confirmed);
0 ignored issues
show
Bug introduced by
$amount * $this->coefficient() 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

31
        return $this->forceWithdraw(/** @scrutinizer ignore-type */ $amount * $this->coefficient(), $meta, $confirmed);
Loading history...
32
    }
33
34
    /**
35
     * @return float
36
     */
37
    private function coefficient(): float
38
    {
39
        return config('wallet.package.coefficient', 100.);
40
    }
41
42
    /**
43
     * @param float $amount
44
     * @param array|null $meta
45
     * @param bool $confirmed
46
     *
47
     * @return Transaction
48
     */
49
    public function depositFloat(float $amount, ?array $meta = null, bool $confirmed = true): Transaction
50
    {
51
        return $this->deposit($amount * $this->coefficient(), $meta, $confirmed);
0 ignored issues
show
Bug introduced by
$amount * $this->coefficient() 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

51
        return $this->deposit(/** @scrutinizer ignore-type */ $amount * $this->coefficient(), $meta, $confirmed);
Loading history...
52
    }
53
54
    /**
55
     * @param float $amount
56
     * @param array|null $meta
57
     * @param bool $confirmed
58
     *
59
     * @return Transaction
60
     */
61
    public function withdrawFloat(float $amount, ?array $meta = null, bool $confirmed = true): Transaction
62
    {
63
        return $this->withdraw($amount * $this->coefficient(), $meta, $confirmed);
0 ignored issues
show
Bug introduced by
$amount * $this->coefficient() 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

63
        return $this->withdraw(/** @scrutinizer ignore-type */ $amount * $this->coefficient(), $meta, $confirmed);
Loading history...
64
    }
65
66
    /**
67
     * @param float $amount
68
     * @return bool
69
     */
70
    public function canWithdrawFloat(float $amount): bool
71
    {
72
        return $this->canWithdraw($amount * $this->coefficient());
0 ignored issues
show
Bug introduced by
$amount * $this->coefficient() 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

72
        return $this->canWithdraw(/** @scrutinizer ignore-type */ $amount * $this->coefficient());
Loading history...
73
    }
74
75
    /**
76
     * @param Wallet $wallet
77
     * @param float $amount
78
     * @param array|null $meta
79
     * @return Transfer
80
     * @throws
81
     */
82
    public function transferFloat(Wallet $wallet, float $amount, ?array $meta = null): Transfer
83
    {
84
        return $this->transfer($wallet, $amount * $this->coefficient(), $meta);
0 ignored issues
show
Bug introduced by
$amount * $this->coefficient() 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

84
        return $this->transfer($wallet, /** @scrutinizer ignore-type */ $amount * $this->coefficient(), $meta);
Loading history...
85
    }
86
87
    /**
88
     * @param Wallet $wallet
89
     * @param float $amount
90
     * @param array|null $meta
91
     * @return null|Transfer
92
     */
93
    public function safeTransferFloat(Wallet $wallet, float $amount, ?array $meta = null): ?Transfer
94
    {
95
        return $this->safeTransfer($wallet, $amount * $this->coefficient(), $meta);
0 ignored issues
show
Bug introduced by
$amount * $this->coefficient() 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

95
        return $this->safeTransfer($wallet, /** @scrutinizer ignore-type */ $amount * $this->coefficient(), $meta);
Loading history...
96
    }
97
98
    /**
99
     * @param Wallet $wallet
100
     * @param float $amount
101
     * @param array|null $meta
102
     * @return Transfer
103
     */
104
    public function forceTransferFloat(Wallet $wallet, float $amount, ?array $meta = null): Transfer
105
    {
106
        return $this->forceTransfer($wallet, $amount * $this->coefficient(), $meta);
0 ignored issues
show
Bug introduced by
$amount * $this->coefficient() 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 * $this->coefficient(), $meta);
Loading history...
107
    }
108
109
    /**
110
     * @return float
111
     */
112
    public function getBalanceFloatAttribute(): float
113
    {
114
        return $this->balance / $this->coefficient();
115
    }
116
117
}
118