BelongsToCreatedBy   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 33
ccs 0
cts 7
cp 0
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setCreatedByRelationValue() 0 5 1
A createdBy() 0 3 1
A getCreatedByRelationValue() 0 3 1
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