| Total Complexity | 4 |
| Total Lines | 58 |
| Duplicated Lines | 0 % |
| Coverage | 28.57% |
| Changes | 0 | ||
| 1 | <?php |
||
| 18 | class Wallet extends Model implements Customer, WalletFloat |
||
| 19 | { |
||
| 20 | |||
| 21 | use CanBePaidFloat; |
||
|
|
|||
| 22 | |||
| 23 | /** |
||
| 24 | * @var array |
||
| 25 | */ |
||
| 26 | protected $fillable = [ |
||
| 27 | 'holder_type', |
||
| 28 | 'holder_id', |
||
| 29 | 'name', |
||
| 30 | 'slug', |
||
| 31 | 'description', |
||
| 32 | 'balance', |
||
| 33 | ]; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var array |
||
| 37 | */ |
||
| 38 | protected $casts = [ |
||
| 39 | 'balance' => 'int', |
||
| 40 | ]; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @return string |
||
| 44 | */ |
||
| 45 | 21 | public function getTable(): string |
|
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @return bool |
||
| 56 | */ |
||
| 57 | public function calculateBalance(): bool |
||
| 58 | { |
||
| 59 | $balance = $this->transactions() |
||
| 60 | ->where('wallet_id', $this->getKey()) |
||
| 61 | ->where('confirmed', true) |
||
| 62 | ->sum('amount'); |
||
| 63 | |||
| 64 | WalletProxy::set($this->getKey(), $balance); |
||
| 65 | $this->attributes['balance'] = $balance; |
||
| 66 | |||
| 67 | return $this->save(); |
||
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @return BelongsToMany |
||
| 72 | */ |
||
| 73 | public function holder(): BelongsToMany |
||
| 76 | } |
||
| 77 | |||
| 79 |