Passed
Push — master ( 6b0e6b...43789e )
by Stephen
03:30
created

WhereModels   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 42
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A whereModelKey() 0 10 2
A whereModelTable() 0 14 3
1
<?php
2
3
namespace Sfneal\Tracking\Builders\Traits;
4
5
trait WhereModels
6
{
7
    /**
8
     * Scope query to activity on a specific model key.
9
     *
10
     * @param mixed $model_key
11
     *
12
     * @return $this
13
     */
14
    public function whereModelKey($model_key)
15
    {
16
        $model_key = (array) $model_key;
17
        $this->where(function (self $query) use ($model_key) {
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

17
        $this->/** @scrutinizer ignore-call */ 
18
               where(function (self $query) use ($model_key) {
Loading history...
18
            foreach ($model_key as $key) {
19
                $query->orWhere('model_key', '=', $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

19
                $query->/** @scrutinizer ignore-call */ 
20
                        orWhere('model_key', '=', $key);
Loading history...
20
            }
21
        });
22
23
        return $this;
24
    }
25
26
    /**
27
     * Scope query to activity on a specific model key.
28
     *
29
     * @param mixed $model_table
30
     *
31
     * @return $this
32
     */
33
    public function whereModelTable($model_table)
34
    {
35
        $model_table = (array) $model_table;
36
        $this->where(function (self $query) use ($model_table) {
37
            foreach ($model_table as $table) {
38
                if (inString($table, '_')) {
39
                    $query->orWhereLike('model_table', $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

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