| 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
Loading history...
|
|||||
| 32 | 1 | $decimalPlaces = app(WalletService::class)->decimalPlaces($this); |
|||
|
0 ignored issues
–
show
$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
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
$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
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
$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
Loading history...
|
|||||
| 49 | 12 | $decimalPlaces = app(WalletService::class)->decimalPlaces($this); |
|||
|
0 ignored issues
–
show
$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
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
$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
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
$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
Loading history...
|
|||||
| 66 | 11 | $decimalPlaces = app(WalletService::class)->decimalPlaces($this); |
|||
|
0 ignored issues
–
show
$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
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
$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
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
$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
Loading history...
|
|||||
| 80 | 1 | $decimalPlaces = app(WalletService::class)->decimalPlaces($this); |
|||
|
0 ignored issues
–
show
$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
Loading history...
|
|||||
| 81 | 1 | $result = $math->round($math->mul($amount, $decimalPlaces, $decimalPlacesValue)); |
|||
| 82 | |||||
| 83 | 1 | return $this->canWithdraw($result); |
|||
|
0 ignored issues
–
show
$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
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
$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
Loading history...
|
|||||
| 97 | 2 | $decimalPlaces = app(WalletService::class)->decimalPlaces($this); |
|||
|
0 ignored issues
–
show
$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
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
$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
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
$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
Loading history...
|
|||||
| 113 | 1 | $decimalPlaces = app(WalletService::class)->decimalPlaces($this); |
|||
|
0 ignored issues
–
show
$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
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
$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
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
$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
Loading history...
|
|||||
| 129 | 1 | $decimalPlaces = app(WalletService::class)->decimalPlaces($this); |
|||
|
0 ignored issues
–
show
$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
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
$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
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
$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
Loading history...
|
|||||
| 142 | 14 | $decimalPlaces = app(WalletService::class)->decimalPlaces($this); |
|||
|
0 ignored issues
–
show
$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
Loading history...
|
|||||
| 143 | |||||
| 144 | 14 | return $math->div($this->balance, $decimalPlaces, $decimalPlacesValue); |
|||
| 145 | } |
||||
| 146 | } |
||||
| 147 |