Passed
Push — develop ( 6dcea6...5ae9a6 )
by Septianata
16:24
created

Relation::getIssuersRelationValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace App\Models\Concerns\User;
4
5
use App\Models\Branch;
6
use App\Models\Support\Relation\MorphManyIssueCustomers;
7
use App\Models\Support\Relation\MorphManyIssueOrderStatus;
8
use Illuminate\Database\Eloquent\Collection;
9
use Illuminate\Database\Eloquent\Relations\BelongsTo;
10
use Spatie\Permission\Traits\HasRoles;
11
12
/**
13
 * @property-read \Illuminate\Database\Eloquent\Collection<\App\Models\Role> $roles
14
 * @property int $branch_id Foreign key of \App\Models\Branch.
15
 * @property-read \App\Models\Branch $branch
16
 *
17
 * @see \App\Models\User
18
 */
19
trait Relation
20
{
21
    use HasRoles,
22
        MorphManyIssueOrderStatus,
23
        MorphManyIssueCustomers;
24
25
    /**
26
     * Define an inverse one-to-one or many relationship with \App\Models\Branch.
27
     *
28
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
29
     */
30 73
    public function branch(): BelongsTo
31
    {
32 73
        return $this->belongsTo(Branch::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

32
        return $this->/** @scrutinizer ignore-call */ belongsTo(Branch::class);
Loading history...
33
    }
34
35
    /**
36
     * Return \App\Models\Branch model relation value.
37
     *
38
     * @return \App\Models\Branch
39
     */
40
    public function getBranchRelationValue(): Branch
41
    {
42
        return $this->getRelationValue('branch');
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

42
        return $this->/** @scrutinizer ignore-call */ getRelationValue('branch');
Loading history...
43
    }
44
45
    /**
46
     * Set \App\Models\Branch model relation value.
47
     *
48
     * @param  \App\Models\Branch  $branch
49
     * @return $this
50
     */
51 73
    public function setBranchRelationValue(Branch $branch)
52
    {
53 73
        $this->branch()->associate($branch);
54
55 73
        return $this;
56
    }
57
58
    /**
59
     * Return collection of \App\Models\Order model relation value.
60
     *
61
     * @return \Illuminate\Database\Eloquent\Collection<\App\Models\Contracts\Issuerable>
62
     */
63
    public function getIssuersRelationValue(): Collection
64
    {
65
        return $this->issuerOrderStatuses->merge($this->issuerCustomers);
66
    }
67
}
68