Test Failed
Pull Request — master (#83)
by Бабичев
13:48 queued 09:03
created

HasWalletFloat   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Test Coverage

Coverage 37.5%

Importance

Changes 5
Bugs 0 Features 1
Metric Value
eloc 18
c 5
b 0
f 1
dl 0
loc 97
ccs 9
cts 24
cp 0.375
rs 10
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A withdrawFloat() 0 4 1
A depositFloat() 0 4 1
A getBalanceFloatAttribute() 0 4 1
A transferFloat() 0 4 1
A safeTransferFloat() 0 4 1
A forceWithdrawFloat() 0 4 1
A forceTransferFloat() 0 4 1
A canWithdrawFloat() 0 4 1
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\WalletService;
9
10
/**
11
 * Trait HasWalletFloat
12
 *
13
 * @package Bavix\Wallet\Traits
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
    public function forceWithdrawFloat(float $amount, ?array $meta = null, bool $confirmed = true): Transaction
29
    {
30
        $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

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

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

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

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

56
        $decimalPlaces = app(WalletService::class)->decimalPlaces(/** @scrutinizer ignore-type */ $this);
Loading history...
57 2
        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

57
        return $this->withdraw(/** @scrutinizer ignore-type */ $amount * $decimalPlaces, $meta, $confirmed);
Loading history...
58
    }
59
60
    /**
61
     * @param float $amount
62
     * @return bool
63
     */
64
    public function canWithdrawFloat(float $amount): bool
65
    {
66
        $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
        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

67
        return $this->canWithdraw(/** @scrutinizer ignore-type */ $amount * $decimalPlaces);
Loading history...
68
    }
69
70
    /**
71
     * @param Wallet $wallet
72
     * @param float $amount
73
     * @param array|null $meta
74
     * @return Transfer
75
     * @throws
76
     */
77
    public function transferFloat(Wallet $wallet, float $amount, ?array $meta = null): Transfer
78
    {
79
        $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

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

80
        return $this->transfer($wallet, /** @scrutinizer ignore-type */ $amount * $decimalPlaces, $meta);
Loading history...
81
    }
82
83
    /**
84
     * @param Wallet $wallet
85
     * @param float $amount
86
     * @param array|null $meta
87
     * @return null|Transfer
88
     */
89
    public function safeTransferFloat(Wallet $wallet, float $amount, ?array $meta = null): ?Transfer
90
    {
91
        $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

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

92
        return $this->safeTransfer($wallet, /** @scrutinizer ignore-type */ $amount * $decimalPlaces, $meta);
Loading history...
93
    }
94
95
    /**
96
     * @param Wallet $wallet
97
     * @param float $amount
98
     * @param array|null $meta
99
     * @return Transfer
100
     */
101
    public function forceTransferFloat(Wallet $wallet, float $amount, ?array $meta = null): Transfer
102
    {
103
        $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

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

104
        return $this->forceTransfer($wallet, /** @scrutinizer ignore-type */ $amount * $decimalPlaces, $meta);
Loading history...
105
    }
106
107
    /**
108
     * @return float
109
     */
110 3
    public function getBalanceFloatAttribute(): float
111
    {
112 3
        $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

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