Passed
Push — main ( 6c3558...e780c1 )
by Tan
03:03 queued 37s
created

UserHasInteraction   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 4
dl 0
loc 13
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A likes() 0 6 1
1
<?php
2
3
namespace CSlant\LaravelLike;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\Relations\HasMany;
7
8
/**
9
 * Trait UserInteraction
10
 * use this trait in your User model
11
 *
12
 * @package CSlant\LaravelLike\Traits
13
 * @mixin Model
14
 * @method Model hasMany(string $related, string $foreignKey = null, string $localKey = null)
15
 */
16
trait UserHasInteraction
17
{
18
    /**
19
     * Get all likes of the user. This method is used for eager loading.
20
     *
21
     * @return HasMany
22
     */
23
    public function likes(): HasMany
24
    {
25
        $interactionModel = (string) (config('like.interaction_model') ?? 'CSlant\LaravelLike\Models\Like');
26
        $userForeignKey = (string) (config('like.users.foreign_key') ?? 'user_id');
27
28
        return $this->hasMany($interactionModel, $userForeignKey);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->hasMany($i...Model, $userForeignKey) returns the type Illuminate\Database\Eloquent\Model which is incompatible with the type-hinted return Illuminate\Database\Eloquent\Relations\HasMany.
Loading history...
29
    }
30
}
31