| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Bavix\Wallet\Objects; |
||||
| 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 Ramsey\Uuid\Uuid; |
||||
| 10 | |||||
| 11 | class Bring |
||||
| 12 | { |
||||
| 13 | /** |
||||
| 14 | * @var string |
||||
| 15 | */ |
||||
| 16 | protected $status; |
||||
| 17 | |||||
| 18 | /** |
||||
| 19 | * @var Wallet |
||||
| 20 | */ |
||||
| 21 | protected $from; |
||||
| 22 | |||||
| 23 | /** |
||||
| 24 | * @var Wallet |
||||
| 25 | */ |
||||
| 26 | protected $to; |
||||
| 27 | |||||
| 28 | /** |
||||
| 29 | * @var Transaction |
||||
| 30 | */ |
||||
| 31 | protected $deposit; |
||||
| 32 | |||||
| 33 | /** |
||||
| 34 | * @var Transaction |
||||
| 35 | */ |
||||
| 36 | protected $withdraw; |
||||
| 37 | |||||
| 38 | /** |
||||
| 39 | * @var string |
||||
| 40 | */ |
||||
| 41 | protected $uuid; |
||||
| 42 | |||||
| 43 | /** |
||||
| 44 | * @var int |
||||
| 45 | */ |
||||
| 46 | protected $fee; |
||||
| 47 | |||||
| 48 | /** |
||||
| 49 | * @var int |
||||
| 50 | */ |
||||
| 51 | protected $discount; |
||||
| 52 | |||||
| 53 | /** |
||||
| 54 | * Bring constructor. |
||||
| 55 | * @throws |
||||
| 56 | */ |
||||
| 57 | 52 | public function __construct() |
|||
| 58 | { |
||||
| 59 | 52 | $this->uuid = Uuid::uuid4()->toString(); |
|||
| 60 | 52 | } |
|||
| 61 | |||||
| 62 | /** |
||||
| 63 | * @return string |
||||
| 64 | */ |
||||
| 65 | 51 | public function getStatus(): string |
|||
| 66 | { |
||||
| 67 | 51 | return $this->status; |
|||
| 68 | } |
||||
| 69 | |||||
| 70 | /** |
||||
| 71 | * @param string $status |
||||
| 72 | * @return static |
||||
| 73 | */ |
||||
| 74 | 51 | public function setStatus(string $status): self |
|||
| 75 | { |
||||
| 76 | 51 | $this->status = $status; |
|||
| 77 | |||||
| 78 | 51 | return $this; |
|||
| 79 | } |
||||
| 80 | |||||
| 81 | /** |
||||
| 82 | * @param int $discount |
||||
| 83 | * @return static |
||||
| 84 | */ |
||||
| 85 | 51 | public function setDiscount(int $discount): self |
|||
| 86 | { |
||||
| 87 | 51 | $this->discount = app(Mathable::class)->round($discount); |
|||
|
0 ignored issues
–
show
|
|||||
| 88 | |||||
| 89 | 51 | return $this; |
|||
| 90 | } |
||||
| 91 | |||||
| 92 | /** |
||||
| 93 | * @return Wallet |
||||
| 94 | */ |
||||
| 95 | 51 | public function getFrom(): Wallet |
|||
| 96 | { |
||||
| 97 | 51 | return $this->from; |
|||
| 98 | } |
||||
| 99 | |||||
| 100 | /** |
||||
| 101 | * @param Wallet $from |
||||
| 102 | * @return static |
||||
| 103 | */ |
||||
| 104 | 51 | public function setFrom(Wallet $from): self |
|||
| 105 | { |
||||
| 106 | 51 | $this->from = $from; |
|||
| 107 | |||||
| 108 | 51 | return $this; |
|||
| 109 | } |
||||
| 110 | |||||
| 111 | /** |
||||
| 112 | * @return Wallet |
||||
| 113 | */ |
||||
| 114 | 51 | public function getTo(): Wallet |
|||
| 115 | { |
||||
| 116 | 51 | return $this->to; |
|||
| 117 | } |
||||
| 118 | |||||
| 119 | /** |
||||
| 120 | * @param Wallet $to |
||||
| 121 | * @return static |
||||
| 122 | */ |
||||
| 123 | 51 | public function setTo(Wallet $to): self |
|||
| 124 | { |
||||
| 125 | 51 | $this->to = $to; |
|||
| 126 | |||||
| 127 | 51 | return $this; |
|||
| 128 | } |
||||
| 129 | |||||
| 130 | /** |
||||
| 131 | * @return Transaction |
||||
| 132 | */ |
||||
| 133 | 51 | public function getDeposit(): Transaction |
|||
| 134 | { |
||||
| 135 | 51 | return $this->deposit; |
|||
| 136 | } |
||||
| 137 | |||||
| 138 | /** |
||||
| 139 | * @param Transaction $deposit |
||||
| 140 | * @return static |
||||
| 141 | */ |
||||
| 142 | 51 | public function setDeposit(Transaction $deposit): self |
|||
| 143 | { |
||||
| 144 | 51 | $this->deposit = $deposit; |
|||
| 145 | |||||
| 146 | 51 | return $this; |
|||
| 147 | } |
||||
| 148 | |||||
| 149 | /** |
||||
| 150 | * @return Transaction |
||||
| 151 | */ |
||||
| 152 | 51 | public function getWithdraw(): Transaction |
|||
| 153 | { |
||||
| 154 | 51 | return $this->withdraw; |
|||
| 155 | } |
||||
| 156 | |||||
| 157 | /** |
||||
| 158 | * @param Transaction $withdraw |
||||
| 159 | * @return static |
||||
| 160 | */ |
||||
| 161 | 51 | public function setWithdraw(Transaction $withdraw): self |
|||
| 162 | { |
||||
| 163 | 51 | $this->withdraw = $withdraw; |
|||
| 164 | |||||
| 165 | 51 | return $this; |
|||
| 166 | } |
||||
| 167 | |||||
| 168 | /** |
||||
| 169 | * @return string |
||||
| 170 | */ |
||||
| 171 | 51 | public function getUuid(): string |
|||
| 172 | { |
||||
| 173 | 51 | return $this->uuid; |
|||
| 174 | } |
||||
| 175 | |||||
| 176 | /** |
||||
| 177 | * @return string |
||||
| 178 | */ |
||||
| 179 | 51 | public function getDiscount(): int |
|||
| 180 | { |
||||
| 181 | 51 | return $this->discount; |
|||
| 182 | } |
||||
| 183 | |||||
| 184 | /** |
||||
| 185 | * @return int |
||||
| 186 | */ |
||||
| 187 | 51 | public function getFee(): int |
|||
| 188 | { |
||||
| 189 | 51 | $fee = $this->fee; |
|||
| 190 | 51 | if ($fee === null) { |
|||
|
0 ignored issues
–
show
|
|||||
| 191 | 50 | $fee = app(Mathable::class)->round( |
|||
| 192 | 50 | app(Mathable::class)->sub( |
|||
| 193 | 50 | app(Mathable::class)->abs($this->getWithdraw()->amount), |
|||
| 194 | 50 | app(Mathable::class)->abs($this->getDeposit()->amount) |
|||
| 195 | ) |
||||
| 196 | ); |
||||
| 197 | } |
||||
| 198 | |||||
| 199 | 51 | return $fee; |
|||
| 200 | } |
||||
| 201 | |||||
| 202 | /** |
||||
| 203 | * @param int $fee |
||||
| 204 | * @return Bring |
||||
| 205 | */ |
||||
| 206 | 1 | public function setFee($fee): self |
|||
| 207 | { |
||||
| 208 | 1 | $this->fee = app(Mathable::class)->round($fee); |
|||
|
0 ignored issues
–
show
The property
$fee was declared of type integer, but app(Bavix\Wallet\Interfa...le::class)->round($fee) is of type string. Maybe add a type cast?
This check looks for assignments to scalar types that may be of the wrong type. To ensure the code behaves as expected, it may be a good idea to add an explicit type cast. $answer = 42;
$correct = false;
$correct = (bool) $answer;
Loading history...
|
|||||
| 209 | |||||
| 210 | 1 | return $this; |
|||
| 211 | } |
||||
| 212 | |||||
| 213 | /** |
||||
| 214 | * @return Transfer |
||||
| 215 | * @throws |
||||
| 216 | */ |
||||
| 217 | 51 | public function create(): Transfer |
|||
| 218 | { |
||||
| 219 | 51 | return app(Transfer::class) |
|||
| 220 | 51 | ->create($this->toArray()); |
|||
| 221 | } |
||||
| 222 | |||||
| 223 | /** |
||||
| 224 | * @return array |
||||
| 225 | * @throws |
||||
| 226 | */ |
||||
| 227 | 51 | public function toArray(): array |
|||
| 228 | { |
||||
| 229 | return [ |
||||
| 230 | 51 | 'status' => $this->getStatus(), |
|||
| 231 | 51 | 'deposit_id' => $this->getDeposit()->getKey(), |
|||
| 232 | 51 | 'withdraw_id' => $this->getWithdraw()->getKey(), |
|||
| 233 | 51 | 'from_type' => $this->getFrom()->getMorphClass(), |
|||
|
0 ignored issues
–
show
The method
getMorphClass() does not exist on Bavix\Wallet\Interfaces\Wallet. It seems like you code against a sub-type of said class. However, the method does not exist in Bavix\Wallet\Interfaces\Customer or Bavix\Wallet\Interfaces\Product or Bavix\Wallet\Interfaces\Discount. Are you sure you never get one of those?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 234 | 51 | 'from_id' => $this->getFrom()->getKey(), |
|||
|
0 ignored issues
–
show
The method
getKey() does not exist on Bavix\Wallet\Interfaces\Wallet. It seems like you code against a sub-type of said class. However, the method does not exist in Bavix\Wallet\Interfaces\Customer or Bavix\Wallet\Interfaces\Product or Bavix\Wallet\Interfaces\Discount. Are you sure you never get one of those?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 235 | 51 | 'to_type' => $this->getTo()->getMorphClass(), |
|||
| 236 | 51 | 'to_id' => $this->getTo()->getKey(), |
|||
| 237 | 51 | 'discount' => $this->getDiscount(), |
|||
| 238 | 51 | 'fee' => $this->getFee(), |
|||
| 239 | 51 | 'uuid' => $this->getUuid(), |
|||
| 240 | ]; |
||||
| 241 | } |
||||
| 242 | } |
||||
| 243 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.