Passed
Push — master ( 38cc9b...2ce834 )
by Moecasts
03:22
created

Transaction::wallet()   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 Moecasts\Laravel\Wallet\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\Relations\BelongsTo;
7
use Illuminate\Database\Eloquent\Relations\MorphTo;
8
use Moecasts\Laravel\Wallet\Models\Wallet;
9
10
class Transaction extends Model
11
{
12
    public const TYPE_DEPOSIT = 'deposit';
13
    public const TYPE_WITHDRAW = 'withdraw';
14
15
    /**
16
     * @var array
17
     */
18
    protected $fillable = [
19
        'holder_type',
20
        'holder_id',
21
        'wallet_id',
22
        'uuid',
23
        'type',
24
        'amount',
25
        'confirmed',
26
        'meta',
27
    ];
28
29
    protected $casts = [
30
        'amount' => 'int',
31
        'confirmed' => 'bool',
32
        'meta' => 'json'
33
    ];
34
35 1
    public function holder(): MorphTo
36
    {
37 1
        return $this->morphTo();
38
    }
39
40 1
    public function wallet(): BelongsTo
41
    {
42 1
        return $this->belongsTo(Wallet::class);
43
    }
44
45 1
    public function scopeDeposit($query)
46
    {
47 1
        return $query->where('type', 'deposit');
48
    }
49
50 1
    public function scopeWithdraw($query)
51
    {
52 1
        return $query->where('type', 'withdraw');
53
    }
54
}
55