GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( bc33c3...4f0198 )
by Mehdi
11:09
created

Filterable::scopeSetLoadInjectedDetection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace eloquentFilter\QueryFilter\ModelFilters;
4
5
use eloquentFilter\Facade\EloquentFilter;
6
use Illuminate\Database\Eloquent\Builder;
7
8
/**
9
 * Trait Filterable.
10
 */
11
trait Filterable
12
{
13
    /**
14
     * @var null
15
     */
16
    protected $ignore_request = null;
17
18
    /**
19
     * @var null
20
     */
21
    protected $accept_request = null;
22
23
    /**
24
     * @var bool
25
     */
26
    protected bool $load_injected_detections = true;
27
28
    /**
29
     * @var null
30
     */
31
    protected $object_custom_detect = null;
32
33
    /**
34
     * @param            $query
35
     * @param array|null $request
36
     *
37
     * @return Builder
38
     */
39
    public function scopeFilter($query, ?array $request = null)
40
    {
41
        return EloquentFilter::apply($query, $request, $this->ignore_request, $this->accept_request, $this->getObjectCustomDetect());
42
    }
43
44
    /**
45
     * @param            $query
46
     * @param array|null $request
47
     */
48
    public function scopeIgnoreRequest($query, ?array $request = null)
0 ignored issues
show
Unused Code introduced by
The parameter $query is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

48
    public function scopeIgnoreRequest(/** @scrutinizer ignore-unused */ $query, ?array $request = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
49
    {
50
        $this->ignore_request = $request;
0 ignored issues
show
Documentation Bug introduced by
It seems like $request can also be of type array. However, the property $ignore_request is declared as type null. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
51
    }
52
53
    /**
54
     * @param            $query
55
     * @param array|null $request
56
     */
57
    public function scopeAcceptRequest($query, ?array $request = null)
0 ignored issues
show
Unused Code introduced by
The parameter $query is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

57
    public function scopeAcceptRequest(/** @scrutinizer ignore-unused */ $query, ?array $request = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
58
    {
59
        $this->accept_request = $request;
0 ignored issues
show
Documentation Bug introduced by
It seems like $request can also be of type array. However, the property $accept_request is declared as type null. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
60
    }
61
62
    /**
63
     * @param $query
64
     * @param array|null $object_custom_detect
65
     */
66
    public function scopeSetCustomDetection($query, ?array $object_custom_detect = null)
0 ignored issues
show
Unused Code introduced by
The parameter $query is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

66
    public function scopeSetCustomDetection(/** @scrutinizer ignore-unused */ $query, ?array $object_custom_detect = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
67
    {
68
        $this->setObjectCustomDetect($object_custom_detect);
69
    }
70
71
    /**
72
     * @return mixed
73
     */
74
    private function getObjectCustomDetect()
75
    {
76
        if (method_exists($this, 'EloquentFilterCustomDetection') && empty($this->object_custom_detect) && $this->getLoadInjectedDetections()) {
77
            $this->setObjectCustomDetect($this->EloquentFilterCustomDetection());
78
        }
79
80
        return $this->object_custom_detect;
81
    }
82
83
    /**
84
     * @param mixed $object_custom_detect
85
     */
86
    private function setObjectCustomDetect($object_custom_detect): void
87
    {
88
        $this->object_custom_detect = $object_custom_detect;
89
    }
90
91
    /**
92
     * @return mixed
93
     */
94
    public static function getWhiteListFilter(): array
95
    {
96
        return (self::$whiteListFilter ?? []);
97
    }
98
99
    /**
100
     * @return mixed
101
     */
102
    public function getAliasListFilter(): ?array
103
    {
104
        return ($this->aliasListFilter ?? null);
105
    }
106
107
    /**
108
     * @param $value
109
     *
110
     * @return mixed
111
     */
112
    public static function addWhiteListFilter($value)
113
    {
114
        if (isset(self::$whiteListFilter)) {
115
            self::$whiteListFilter[] = $value;
0 ignored issues
show
Bug Best Practice introduced by
The property whiteListFilter does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
116
        }
117
    }
118
119
    /**
120
     * @param array $array
121
     */
122
    public static function setWhiteListFilter(array $array)
123
    {
124
        if (isset(self::$whiteListFilter)) {
125
            self::$whiteListFilter = $array;
0 ignored issues
show
Bug Best Practice introduced by
The property whiteListFilter does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
126
        }
127
    }
128
129
    /**
130
     * @param string $method
131
     *
132
     * @return bool
133
     */
134
    public function checkModelHasOverrideMethod(string $method): bool
135
    {
136
        return method_exists($this, $method);
137
    }
138
139
    /**
140
     * @param $query
141
     * @param $load_default_detection
142
     */
143
    public function scopeSetLoadInjectedDetection($query, $load_default_detection)
0 ignored issues
show
Unused Code introduced by
The parameter $query is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

143
    public function scopeSetLoadInjectedDetection(/** @scrutinizer ignore-unused */ $query, $load_default_detection)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
144
    {
145
        $this->load_injected_detections = $load_default_detection;
146
    }
147
148
    /**
149
     * @return bool
150
     */
151
    public function getLoadInjectedDetections(): bool
152
    {
153
        return $this->load_injected_detections;
154
    }
155
}
156