Passed
Push — main ( 4ad008...e9819d )
by Tan
02:45 queued 14s
created

LikeRelationship   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A likeOne() 0 3 1
A likes() 0 3 1
1
<?php
2
3
namespace CSlant\LaravelLike\Traits;
4
5
use CSlant\LaravelLike\Models\Like;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Database\Eloquent\Relations\MorphMany;
8
use Illuminate\Database\Eloquent\Relations\MorphOne;
9
10
/**
11
 * Trait LikeRelationship
12
 *
13
 * @package CSlant\LaravelLike\Traits
14
 * @mixin Model
15
 */
16
trait LikeRelationship
17
{
18
    /**
19
     * Like has one relationship with the model.
20
     *
21
     * @return MorphOne
22
     */
23
    public function likeOne(): MorphOne
24
    {
25
        return $this->morphOne(Like::class, 'model');
0 ignored issues
show
Bug introduced by
It seems like morphOne() 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

25
        return $this->/** @scrutinizer ignore-call */ morphOne(Like::class, 'model');
Loading history...
26
    }
27
28
    /**
29
     * Like has many relationship with the model.
30
     *
31
     * @return MorphMany
32
     */
33
    public function likes(): MorphMany
34
    {
35
        return $this->morphMany(Like::class, 'model');
0 ignored issues
show
Bug introduced by
It seems like morphMany() 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

35
        return $this->/** @scrutinizer ignore-call */ morphMany(Like::class, 'model');
Loading history...
36
    }
37
}
38