Passed
Push — main ( 1c0a46...2384cc )
by Tan
02:42 queued 15s
created

UserHasInteraction::likes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace CSlant\LaravelLike\Traits;
4
5
use Illuminate\Database\Eloquent\Relations\HasMany;
6
7
/**
8
 * Trait UserInteraction
9
 * use this trait in your User model
10
 *
11
 * @package CSlant\LaravelLike\Traits
12
 * @mixin \Illuminate\Database\Eloquent\Model
13
 */
14
trait UserHasInteraction
15
{
16
    /**
17
     * Get all likes of the user. This method is used for eager loading.
18
     *
19
     * @return HasMany
20
     */
21
    public function likes(): HasMany
22
    {
23
        $interactionModel = (string) (config('like.interaction_model') ?? 'CSlant\LaravelLike\Models\Like');
24
        $userForeignKey = (string) (config('like.users.foreign_key') ?? 'user_id');
25
26
        return $this->hasMany($interactionModel, $userForeignKey);
0 ignored issues
show
Bug introduced by
It seems like hasMany() 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

26
        return $this->/** @scrutinizer ignore-call */ hasMany($interactionModel, $userForeignKey);
Loading history...
27
    }
28
}
29