UserPaymentProfile   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 14
c 1
b 0
f 1
dl 0
loc 62
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A user() 0 3 1
A scopeBanks() 0 3 1
A scopeCards() 0 3 1
1
<?php
2
3
namespace Squareetlabs\AuthorizeNet\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\Relations\BelongsTo;
7
8
class UserPaymentProfile extends Model
9
{
10
    /**
11
     * The table associated with the model.
12
     *
13
     * @var string
14
     */
15
    protected $table = 'user_payment_profiles';
16
17
    /**
18
     * The attributes that are mass assignable.
19
     *
20
     * @var array<int, string>
21
     */
22
    protected $fillable = [
23
        'user_id',
24
        'payment_profile_id',
25
        'last_4',
26
        'type',
27
        'brand',
28
    ];
29
30
    /**
31
     * The attributes that should be cast.
32
     *
33
     * @var array<string, string>
34
     */
35
    protected $casts = [
36
        'created_at' => 'datetime',
37
        'updated_at' => 'datetime',
38
    ];
39
40
    /**
41
     * Get the user that owns the payment profile.
42
     *
43
     * @return BelongsTo
44
     */
45
    public function user(): BelongsTo
46
    {
47
        return $this->belongsTo(config('auth.providers.users.model', 'App\Models\User'));
48
    }
49
50
    /**
51
     * Scope a query to only include card payment profiles.
52
     *
53
     * @param \Illuminate\Database\Eloquent\Builder $query
54
     * @return \Illuminate\Database\Eloquent\Builder
55
     */
56
    public function scopeCards($query)
57
    {
58
        return $query->where('type', 'card');
59
    }
60
61
    /**
62
     * Scope a query to only include bank payment profiles.
63
     *
64
     * @param \Illuminate\Database\Eloquent\Builder $query
65
     * @return \Illuminate\Database\Eloquent\Builder
66
     */
67
    public function scopeBanks($query)
68
    {
69
        return $query->where('type', 'bank');
70
    }
71
}
72
73