CanBeLikedBehavior   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 30
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isLikedBy() 0 13 4
A likes() 0 3 1
A likers() 0 8 1
1
<?php
2
3
/*
4
 * This file is part of the sebastian-kennedy/laravel-like.
5
 *
6
 * (c) SebastianKennedy <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled.
9
 */
10
11
namespace SebastianKennedy\LaravelLike\Behaviors;
12
13
use Illuminate\Database\Eloquent\Model;
14
15
trait CanBeLikedBehavior
16
{
17 3
    public function isLikedBy(Model $user)
18
    {
19 3
        if (is_a($user, config('auth.providers.users.model'))) {
20 3
            if ($this->relationLoaded('likers')) {
0 ignored issues
show
Bug introduced by
It seems like relationLoaded() 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

20
            if ($this->/** @scrutinizer ignore-call */ relationLoaded('likers')) {
Loading history...
21 3
                return $this->likers->contains($user);
22
            }
23
24 3
            return ($this->relationLoaded('likes') ? $this->likes : $this->likes())
25 3
                    ->where(config('like.foreign_key'), $user->getKey())
26 3
                    ->count() > 0;
27
        }
28
29 3
        return false;
30
    }
31
32 15
    public function likes()
33
    {
34 15
        return $this->morphMany(config('like.model'), config('like.morph_many_name'));
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

34
        return $this->/** @scrutinizer ignore-call */ morphMany(config('like.model'), config('like.morph_many_name'));
Loading history...
35
    }
36
37 6
    public function likers()
38
    {
39 6
        return $this->belongsToMany(
0 ignored issues
show
Bug introduced by
It seems like belongsToMany() 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

39
        return $this->/** @scrutinizer ignore-call */ belongsToMany(
Loading history...
40 6
            config('auth.providers.users.model'),
41 6
            config('like.table_name'),
42 6
            config('like.morph_many_id'),
43 6
            config('like.foreign_key')
44 6
        )->where(config('like.morph_many_type'), $this->getMorphClass());
0 ignored issues
show
Bug introduced by
It seems like getMorphClass() 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

44
        )->where(config('like.morph_many_type'), $this->/** @scrutinizer ignore-call */ getMorphClass());
Loading history...
45
    }
46
}
47