CanBeViewed::getRecentlyViewsLimit()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 2
rs 10
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