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 ( ab0f17...5c551e )
by Mehdi
11:24
created

QueryFilterBuilder::responseFilterHandler()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 3
c 1
b 0
f 1
dl 0
loc 7
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
namespace eloquentFilter\QueryFilter\Core\FilterBuilder;
4
5
use eloquentFilter\QueryFilter\Core\EloquentBuilder\QueryBuilderWrapper;
6
use eloquentFilter\QueryFilter\Core\FilterBuilder\core\QueryFilterCore;
7
use eloquentFilter\QueryFilter\Core\HelperEloquentFilter;
8
use eloquentFilter\QueryFilter\Core\ResolverDetections;
9
use eloquentFilter\QueryFilter\Factory\QueryBuilderWrapperFactory;
10
use Illuminate\Database\Eloquent\Builder;
11
12
/**
13
 * Class QueryFilterBuilder.
14
 */
15
class QueryFilterBuilder
16
{
17
    use HelperEloquentFilter;
18
19
    /**
20
     * @var \eloquentFilter\QueryFilter\Core\FilterBuilder\core\QueryFilterCoreBuilder
21
     */
22
23
    public QueryFilterCore $core;
24
25
    /**
26
     * @var \eloquentFilter\QueryFilter\Core\FilterBuilder\RequestFilter
27
     */
28
29
    public RequestFilter $request;
30
31
    /**
32
     * @var \eloquentFilter\QueryFilter\Core\EloquentBuilder\QueryBuilderWrapper
33
     */
34
    public QueryBuilderWrapper $builder;
35
36
    /**
37
     * @param \eloquentFilter\QueryFilter\Core\FilterBuilder\core\QueryFilterCore $core
38
     * @param \eloquentFilter\QueryFilter\Core\FilterBuilder\RequestFilter $requestFilter
39
     */
40
    public function __construct(QueryFilterCore $core, RequestFilter $requestFilter)
41
    {
42
        $this->core = $core;
0 ignored issues
show
Documentation Bug introduced by
$core is of type eloquentFilter\QueryFilt...er\core\QueryFilterCore, but the property $core was declared to be of type eloquentFilter\QueryFilt...\QueryFilterCoreBuilder. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof 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 given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
43
        $this->request = $requestFilter;
44
    }
45
46
    /**
47
     * @param Builder $builder
48
     * @param array|null $request
49
     * @param array|null $ignore_request
50
     * @param array|null $accept_request
51
     * @param array|null $detect_injected
52
     *
53
     * @return void
54
     */
55
    public function apply($builder, array $request = null, array $ignore_request = null, array $accept_request = null, array $detect_injected = null)
56
    {
57
        $this->builder = QueryBuilderWrapperFactory::createQueryBuilder($builder);
58
59
        if (!empty($request)) {
60
            $this->request->setRequest($request);
61
        }
62
63
        if (!config('eloquentFilter.enabled') || empty($this->request->getRequest())) {
64
            return;
65
        }
66
67
        $this->requestHandel($ignore_request, $accept_request);
68
69
        $this->setInjectedDetections($detect_injected);
70
71
        $response = $this->resolveDetections();
72
73
        $response = $this->responseFilterHandler($response);
74
75
        return $response;
76
    }
77
78
    /**
79
     * @param array|null $ignore_request
80
     * @param array|null $accept_request
81
     * @return void
82
     */
83
    private function requestHandel(?array $ignore_request, ?array $accept_request): void
84
    {
85
        if (method_exists($this->builder->getModel(), 'serializeRequestFilter') && !empty($this->request->getRequest())) {
86
            $serializeRequestFilter = $this->builder->serializeRequestFilter($this->request->getRequest());
87
            $this->request->handelSerializeRequestFilter($serializeRequestFilter);
88
        }
89
90
        if ($alias_list_filter = $this->builder->getAliasListFilter() ?? null) {
91
            $this->request->makeAliasRequestFilter($alias_list_filter);
92
        }
93
94
        $this->request->setFilterRequests($ignore_request, $accept_request, $this->builder->getModel());
95
    }
96
97
    /**
98
     * @param array|null $injected_detections
99
     * @return void
100
     */
101
    private function setInjectedDetections(?array $injected_detections): void
102
    {
103
        if (!empty($injected_detections)) {
104
            $this->core->setInjectedDetections($injected_detections);
105
            $this->core->setDetectFactory($this->core->getDetectorFactory($this->core->getDefaultDetect(), $this->core->getInjectedDetections()));
106
        }
107
    }
108
109
    /**
110
     * @return mixed
111
     */
112
    private function resolveDetections()
113
    {
114
        /** @see ResolverDetections */
115
        app()->bind('ResolverDetections', function () {
116
            return new ResolverDetections($this->builder->getBuilder(), $this->request->getRequest(), $this->core->getDetectFactory());
0 ignored issues
show
Bug introduced by
It seems like $this->request->getRequest() can also be of type null; however, parameter $request of eloquentFilter\QueryFilt...tections::__construct() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

116
            return new ResolverDetections($this->builder->getBuilder(), /** @scrutinizer ignore-type */ $this->request->getRequest(), $this->core->getDetectFactory());
Loading history...
117
        });
118
119
        /** @see ResolverDetections::getResolverOut() */
120
        $response = app('ResolverDetections')->getResolverOut();
121
        return $response;
122
    }
123
124
    /**
125
     * @param $out
126
     *
127
     * @return mixed
128
     */
129
    public function responseFilterHandler($out)
130
    {
131
        if (method_exists($this->builder->getModel(), 'ResponseFilter')) {
132
            return $this->builder->responseFilter($out);
133
        }
134
135
        return $out;
136
    }
137
}
138