BelongsToCreatedBy::createdBy()   A
last analyzed

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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace App\Support\Models\Relation;
4
5
use App\Models\User;
6
use Illuminate\Database\Eloquent\Relations\BelongsTo;
7
8
/**
9
 * @property int $created_by Foreign key of \App\Models\User.
10
 * @property-read \App\Models\User $createdBy
11
 */
12
trait BelongsToCreatedBy
13
{
14
    /**
15
     * Define an inverse one-to-one relationship with \App\Models\User.
16
     *
17
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
18
     */
19
    public function createdBy(): BelongsTo
20
    {
21
        return $this->belongsTo(User::class, 'created_by');
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

21
        return $this->/** @scrutinizer ignore-call */ belongsTo(User::class, 'created_by');
Loading history...
22
    }
23
24
    /**
25
     * Return \App\Models\User model relation value.
26
     *
27
     * @return \App\Models\User
28
     */
29
    public function getCreatedByRelationValue(): User
30
    {
31
        return $this->getRelationValue('created_by');
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

31
        return $this->/** @scrutinizer ignore-call */ getRelationValue('created_by');
Loading history...
32
    }
33
34
    /**
35
     * Set \App\Models\User model relation value.
36
     *
37
     * @param  \App\Models\User  $user
38
     * @return $this
39
     */
40
    public function setCreatedByRelationValue(User $user)
41
    {
42
        $this->createdBy()->associate($user);
43
44
        return $this;
45
    }
46
}
47