Passed
Push — master ( d27bd5...494f2f )
by Бабичев
03:09
created

HasWalletFloat::coefficient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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

29
        return $this->forceWithdraw(/** @scrutinizer ignore-type */ $amount * $this->coefficient(), $meta, $confirmed);
Loading history...
30
    }
31
32
    /**
33
     * @param float $amount
34
     * @param array|null $meta
35
     * @param bool $confirmed
36
     *
37
     * @return Transaction
38
     */
39 6
    public function depositFloat(float $amount, ?array $meta = null, bool $confirmed = true): Transaction
40
    {
41 6
        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

41
        return $this->deposit(/** @scrutinizer ignore-type */ $amount * $this->coefficient(), $meta, $confirmed);
Loading history...
42
    }
43
44
    /**
45
     * @param float $amount
46
     * @param array|null $meta
47
     * @param bool $confirmed
48
     *
49
     * @return Transaction
50
     */
51 6
    public function withdrawFloat(float $amount, ?array $meta = null, bool $confirmed = true): Transaction
52
    {
53 6
        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

53
        return $this->withdraw(/** @scrutinizer ignore-type */ $amount * $this->coefficient(), $meta, $confirmed);
Loading history...
54
    }
55
56
    /**
57
     * @param float $amount
58
     * @return bool
59
     */
60 1
    public function canWithdrawFloat(float $amount): bool
61
    {
62 1
        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

62
        return $this->canWithdraw(/** @scrutinizer ignore-type */ $amount * $this->coefficient());
Loading history...
63
    }
64
65
    /**
66
     * @param Wallet $wallet
67
     * @param float $amount
68
     * @param array|null $meta
69
     * @return Transfer
70
     * @throws
71
     */
72 2
    public function transferFloat(Wallet $wallet, float $amount, ?array $meta = null): Transfer
73
    {
74 2
        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

74
        return $this->transfer($wallet, /** @scrutinizer ignore-type */ $amount * $this->coefficient(), $meta);
Loading history...
75
    }
76
77
    /**
78
     * @param Wallet $wallet
79
     * @param float $amount
80
     * @param array|null $meta
81
     * @return null|Transfer
82
     */
83 1
    public function safeTransferFloat(Wallet $wallet, float $amount, ?array $meta = null): ?Transfer
84
    {
85 1
        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

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

96
        return $this->forceTransfer($wallet, /** @scrutinizer ignore-type */ $amount * $this->coefficient(), $meta);
Loading history...
97
    }
98
99
    /**
100
     * @return float
101
     */
102 5
    public function getBalanceFloatAttribute(): float
103
    {
104 5
        return $this->balance / $this->coefficient();
105
    }
106
107
    /**
108
     * @return float
109
     */
110 8
    private function coefficient(): float
111
    {
112 8
        return config('wallet.package.coefficient', 100.);
113
    }
114
115
}
116