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
Pull Request — 2.2 (#120)
by Simone
07:34 queued 03:58
created

IdsChecker::setFiltering()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Mado\QueryBundle\Services;
4
5
use Mado\QueryBundle\Exceptions\ForbiddenContentException;
6
use Mado\QueryBundle\Objects\Filter;
7
use Psr\Log\LoggerInterface;
8
9
class IdsChecker
10
{
11
    private $idsMustBeSubset = true;
12
13
    private $filtering;
14
15
    private $additionalFiltersIds;
16
17
    private $objectFilter;
18
19
    private $filterKey;
20
21
    private $finalFilterIds;
22
23
    private $logger;
24
25
    public function __construct()
26
    {
27
        $this->idsMustBeSubset = true;
28
    }
29
30
    public function setLogger(LoggerInterface $logger)
31
    {
32
        $this->logger = $logger;
33
    }
34
35
    public function setFiltering($filtering)
36
    {
37
        $this->filtering = $filtering;
38
    }
39
40
    public function setAdditionalFiltersIds($additionalFiltersIds)
41
    {
42
        $this->additionalFiltersIds = $additionalFiltersIds;
43
    }
44
45
    public function setObjectFilter(Filter $objectFilter)
46
    {
47
        $this->objectFilter = $objectFilter;
48
    }
49
50
    public function setFilterKey($filterKey)
51
    {
52
        $this->filterKey = $filterKey;
53
    }
54
55
    public function validateIds()
56
    {
57
        $this->log('Start to check IDS');
58
59
        $rawFilteredIds = $this->objectFilter->getIds();
60
61
        foreach ($this->filtering as $key => $queryStringIds) {
62
            $qsIds = explode(',', $queryStringIds);
63
            $addFilIds = explode(',', $this->additionalFiltersIds);
64
            foreach ($qsIds as $requestedId) {
65
                if ($this->objectFilter->getOperator() == 'list') {
66
                    if (!in_array($requestedId, $addFilIds)) {
67
                        throw new ForbiddenContentException(
68
                            'Oops! Forbidden requested id ' . $requestedId
69
                            . ' is not available. '
70
                            . 'Available are "' . join(', ', $addFilIds) . '"'
71
                        );
72
                    }
73
                }
74
75
                if ($this->objectFilter->getOperator() == 'nlist') {
76
                    $queryStringOperator = explode('|', key($this->filtering));
0 ignored issues
show
Unused Code introduced by
The assignment to $queryStringOperator is dead and can be removed.
Loading history...
77
                    if (array_intersect($qsIds, $addFilIds) == []) {
78
                        $this->filterKey = str_replace('nlist', 'list', $this->objectFilter->getRawFilter());
79
                        $rawFilteredIds = join(',', $qsIds);
80
                        $this->idsMustBeSubset = false;
81
                    }
82
                }
83
            }
84
        }
85
86
        $this->finalFilterIds = $rawFilteredIds;
87
88
        if (true == $this->idsMustBeSubset) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
89
            foreach ($this->filtering as $key => $queryStringIds) {
90
                $qsIds = explode(',', $queryStringIds);
91
                $addFilIds = explode(',', $this->additionalFiltersIds);
92
                $this->finalFilterIds = join(',', array_intersect($qsIds, $addFilIds));
93
            }
94
        }
95
96
        $this->log(var_export([
97
            'filterKey'      => $this->getFilterKey(),
98
            'finalFilterIds' => $this->getFinalFilterIds(),
99
        ], true));
100
    }
101
102
    public function getFilterKey()
103
    {
104
        return $this->filterKey;
105
    }
106
107
    public function getFinalFilterIds()
108
    {
109
        return $this->finalFilterIds;
110
    }
111
112
    public function log($message)
113
    {
114
        if ($this->logger) {
115
            $this->logger->debug('[IdsChecker] - ' . $message);
116
        }
117
    }
118
}
119