Passed
Push — develop ( 9324e6...f3eb57 )
by Septianata
04:31
created

Relation::issuerable()   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 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace App\Models\Concerns\OrderStatus;
4
5
use App\Models\Contracts\Issuerable;
6
use App\Models\Order;
7
use Illuminate\Database\Eloquent\Relations\BelongsTo;
8
use Illuminate\Database\Eloquent\Relations\MorphTo;
9
10
/**
11
 * @property int $order_id Foreign key of \App\Models\Order.
12
 * @property-read \App\Models\Order $order
13
 * @property string $issuerable_type
14
 * @property int $issuerable_id
15
 * @property-read \App\Models\Contracts\Issuerable $issuerable
16
 *
17
 * @see \App\Models\OrderStatus
18
 */
19
trait Relation
20
{
21
    /**
22
     * Define an inverse one-to-one or many relationship with \App\Models\Order.
23
     *
24
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
25
     */
26
    public function order(): BelongsTo
27
    {
28
        return $this->belongsTo(Order::class);
0 ignored issues
show
Bug introduced by
It seems like belongsTo() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
        return $this->/** @scrutinizer ignore-call */ belongsTo(Order::class);
Loading history...
29
    }
30
31
    /**
32
     * Return \App\Models\Order model relation value.
33
     *
34
     * @return \App\Models\Order
35
     */
36
    public function getOrderRelationValue(): Order
37
    {
38
        return $this->getRelationValue('order');
0 ignored issues
show
Bug introduced by
It seems like getRelationValue() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

38
        return $this->/** @scrutinizer ignore-call */ getRelationValue('order');
Loading history...
39
    }
40
41
    /**
42
     * Set \App\Models\Order model relation value.
43
     *
44
     * @param  \App\Models\Order  $order
45
     * @return $this
46
     */
47
    public function setOrderRelationValue(Order $order)
48
    {
49
        $this->order()->associate($order);
50
51
        return $this;
52
    }
53
54
    /**
55
     * Define a polymorphic, inverse one-to-one or many relationship.
56
     *
57
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
58
     *
59
     * @see \App\Models\Customer
60
     * @see \App\Models\User
61
     */
62 3
    public function issuerable(): MorphTo
63
    {
64 3
        return $this->morphTo();
0 ignored issues
show
Bug introduced by
It seems like morphTo() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
        return $this->/** @scrutinizer ignore-call */ morphTo();
Loading history...
65
    }
66
67
    /**
68
     * Return \App\Models\Issuerable model relation value.
69
     *
70
     * @return \App\Models\Contracts\Issuerable
71
     */
72
    public function getIssuerableRelationValue(): Issuerable
73
    {
74
        return $this->getRelationValue('issuerable');
75
    }
76
77
    /**
78
     * Set \App\Models\Issuerable model relation value.
79
     *
80
     * @param  \App\Models\Contracts\Issuerable  $issuerable
81
     * @return $this
82
     */
83 1
    public function setIssuerableRelationValue(Issuerable $issuerable)
84
    {
85 1
        $this->issuerable()->associate($issuerable);
86
87 1
        return $this;
88
    }
89
}
90