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 ( e13b49...4d90bb )
by Mehdi
12:01
created

DetectorCondition::__construct()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 14
rs 10
cc 3
nc 1
nop 1
1
<?php
2
3
namespace eloquentFilter\QueryFilter\Detection;
4
5
use eloquentFilter\QueryFilter\Detection\Contract\DetectorConditionsContract;
6
use eloquentFilter\QueryFilter\Exceptions\EloquentFilterException;
7
use Exception;
8
9
/**
10
 * Class DetectorConditions.
11
 */
12
class DetectorCondition
13
{
14
    protected $errorExceptionWhileList = "You must set %s in whiteListFilter in %s
15
         or create a override method with name %s or call ignoreRequest function for ignore %s.";
16
    /**
17
     * @var
18
     */
19
    private $detector;
20
21
    /**
22
     * DetectorConditions constructor.
23
     *
24
     * @param array $detector
25
     */
26
    public function __construct(array $detector)
27
    {
28
        $detector_collect = collect($detector);
0 ignored issues
show
Bug introduced by
$detector of type array is incompatible with the type Illuminate\Contracts\Support\Arrayable expected by parameter $value of collect(). ( Ignorable by Annotation )

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

28
        $detector_collect = collect(/** @scrutinizer ignore-type */ $detector);
Loading history...
29
30
        $detector_collect->map(function ($detector_obj) {
31
            if (!empty($detector_obj)) {
32
                $reflect = new \ReflectionClass($detector_obj);
33
                if ($reflect->implementsInterface(DetectorConditionsContract::class)) {
34
                    return $detector_obj;
35
                }
36
            }
37
        })->toArray();
38
39
        $this->detector = $detector_collect;
40
    }
41
42
    /**
43
     * @param string $field
44
     * @param $params
45
     * @param null $model
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $model is correct as it would always require null to be passed?
Loading history...
46
     *
47
     * @return string|null
48
     * @throws Exception
49
     *
50
     */
51
    public function detect(string $field, $params, $model = null): ?string
52
    {
53
        foreach ($this->detector as $detector_obj) {
54
            if ($this->handelListFields($field, $model->getWhiteListFilter(), $model->checkModelHasOverrideMethod($field), $model)) {
0 ignored issues
show
Bug introduced by
The method getWhiteListFilter() does not exist on null. ( Ignorable by Annotation )

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

54
            if ($this->handelListFields($field, $model->/** @scrutinizer ignore-call */ getWhiteListFilter(), $model->checkModelHasOverrideMethod($field), $model)) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55
                $out = $detector_obj::detect($field, $params, $model->checkModelHasOverrideMethod($field));
56
                if (!empty($out)) {
57
                    return $out;
58
                }
59
            }
60
        }
61
62
        return null;
63
    }
64
65
    /**
66
     * @param string $field
67
     * @param array|null $list_white_filter_model
68
     * @param bool $has_method
69
     * @param $model_class
70
     *
71
     * @return bool
72
     * @throws Exception
73
     *
74
     */
75
    private function handelListFields(string $field, ?array $list_white_filter_model, bool $has_method, $model_class): bool
76
    {
77
        if ($this->checkSetWhiteListFields($field, $list_white_filter_model) || ($field == 'f_params' || $field == 'or') || $has_method) {
78
            return true;
79
        }
80
81
        $class_name = class_basename($model_class);
82
83
        throw new EloquentFilterException(sprintf($this->errorExceptionWhileList, $field, $class_name, $field, $field), 1);
84
    }
85
86
    /**
87
     * @param string $field
88
     * @param array|null $query
89
     *
90
     * @return bool
91
     */
92
    private function checkSetWhiteListFields(string $field, ?array $query): bool
93
    {
94
        if (in_array($field, $query) ||
95
            $query[0] == '*') {
96
            return true;
97
        }
98
99
        return false;
100
    }
101
}
102