Passed
Push — master ( 2c2f0a...77dc50 )
by Stephen
01:46 queued 14s
created

WhereModels::whereTrackableId()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 1
nop 1
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Sfneal\Tracking\Builders\Traits;
4
5
use Sfneal\Helpers\Strings\StringHelpers;
6
7
trait WhereModels
8
{
9
    /**
10
     * Scope query to activity on a specific trackable id.
11
     *
12
     * @param mixed $trackable_id
13
     *
14
     * @return $this
15
     */
16
    public function whereTrackableId($trackable_id): self
17
    {
18
        $trackable_id = (array) $trackable_id;
19
        $this->where(function (self $query) use ($trackable_id) {
0 ignored issues
show
Bug introduced by
It seems like where() 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

19
        $this->/** @scrutinizer ignore-call */ 
20
               where(function (self $query) use ($trackable_id) {
Loading history...
20
            foreach ($trackable_id as $key) {
21
                $query->orWhere('trackable_id', '=', $key);
0 ignored issues
show
Bug introduced by
It seems like orWhere() 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

21
                $query->/** @scrutinizer ignore-call */ 
22
                        orWhere('trackable_id', '=', $key);
Loading history...
22
            }
23
        });
24
25
        return $this;
26
    }
27
28
    /**
29
     * Scope query to activity on a specific trackable type.
30
     *
31
     * @param mixed $trackable_type
32
     *
33
     * @return $this
34
     */
35
    public function whereTrackableType($trackable_type): self
36
    {
37
        $trackable_type = (array) $trackable_type;
38
        $this->where(function (self $query) use ($trackable_type) {
39
            foreach ($trackable_type as $table) {
40
                if ((new StringHelpers($table))->inString('_')) {
41
                    $query->orWhereLike('trackable_type', $table);
0 ignored issues
show
Bug introduced by
It seems like orWhereLike() 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

41
                    $query->/** @scrutinizer ignore-call */ 
42
                            orWhereLike('trackable_type', $table);
Loading history...
42
                } else {
43
                    $query->orWhere('trackable_type', '=', $table);
44
                }
45
            }
46
        });
47
48
        return $this;
49
    }
50
}
51