CanBeViewed   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getRecentlyViewsLimit() 0 3 2
A whereRecentlyViewedIn() 0 9 3
1
<?php
2
3
namespace RecentlyViewed\Models\Traits;
4
5
use Illuminate\Database\Eloquent\Builder;
6
7
/**
8
 * Trait CanBeViewed
9
 * @package RecentlyViewed\Models\Traits
10
 *
11
 */
12
trait CanBeViewed
13
{
14
    /**
15
     * @param  array  $values
16
     *
17
     * @return null|Builder
18
     */
19 1
    public function whereRecentlyViewedIn(array $values): ?Builder
20
    {
21 1
        $values = array_filter($values, fn ($v) => (is_int($v) || is_string($v)));
22
23 1
        if (count($values)) {
24 1
            return static::whereIn($this->getKeyName(), $values);
0 ignored issues
show
Bug introduced by
It seems like getKeyName() 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

24
            return static::whereIn($this->/** @scrutinizer ignore-call */ getKeyName(), $values);
Loading history...
25
        }
26
27 1
        return null;
28
    }
29
30
    /**
31
     * Get recently viewed items count.
32
     *
33
     * @return int
34
     */
35 9
    public function getRecentlyViewsLimit(): int
36
    {
37 9
        return (int) (property_exists($this, 'recentlyViewsLimit') ? $this->recentlyViewsLimit : 10);
38
    }
39
}
40