Passed
Push — master ( c67fb3...32a3ca )
by Бабичев
08:31 queued 11s
created

Transfer::getCasts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Bavix\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 function config;
9
10
/**
11
 * Class Transfer
12
 * @package Bavix\Wallet\Models
13
 *
14
 * @property string $status
15
 * @property int $deposit_id
16
 * @property int $withdraw_id
17
 * @property string $from_type
18
 * @property int $from_id
19
 * @property string $to_type
20
 * @property int $to_id
21
 * @property string $uuid
22
 * @property int $fee
23
 * @property int $discount
24
 *
25
 * @property Transaction $deposit
26
 * @property Transaction $withdraw
27
 */
28
class Transfer extends Model
29
{
30
31
    public const STATUS_EXCHANGE = 'exchange';
32
    public const STATUS_TRANSFER = 'transfer';
33
    public const STATUS_PAID = 'paid';
34
    public const STATUS_REFUND = 'refund';
35
    public const STATUS_GIFT = 'gift';
36
37
    /**
38
     * @var array
39
     */
40
    protected $fillable = [
41
        'status',
42
        'discount',
43
        'deposit_id',
44
        'withdraw_id',
45
        'from_type',
46
        'from_id',
47
        'to_type',
48
        'to_id',
49
        'uuid',
50
        'fee',
51
    ];
52
53
    /**
54
     * @var array
55
     */
56
    protected $casts = [
57
        'deposit_id' => 'int',
58
        'withdraw_id' => 'int',
59
        'fee' => 'int',
60
    ];
61
62
    /**
63
     * @inheritDoc
64
     */
65 50
    public function getCasts(): array
66
    {
67 50
        $this->casts = array_merge(
68 50
            $this->casts,
69 50
            config('wallet.transfer.casts', [])
70
        );
71
72 50
        return parent::getCasts();
73
    }
74
75
    /**
76
     * @return string
77
     */
78 132
    public function getTable(): string
79
    {
80 132
        if (!$this->table) {
81 132
            $this->table = config('wallet.transfer.table', 'transfers');
82
        }
83
84 132
        return parent::getTable();
85
    }
86
87
    /**
88
     * @return MorphTo
89
     */
90 5
    public function from(): MorphTo
91
    {
92 5
        return $this->morphTo();
93
    }
94
95
    /**
96
     * @return MorphTo
97
     */
98 4
    public function to(): MorphTo
99
    {
100 4
        return $this->morphTo();
101
    }
102
103
    /**
104
     * @return BelongsTo
105
     */
106 27
    public function deposit(): BelongsTo
107
    {
108 27
        return $this->belongsTo(Transaction::class, 'deposit_id');
109
    }
110
111
    /**
112
     * @return BelongsTo
113
     */
114 28
    public function withdraw(): BelongsTo
115
    {
116 28
        return $this->belongsTo(Transaction::class, 'withdraw_id');
117
    }
118
119
}
120