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 — refactoring/additional-filters... ( 98d337...dd0af0 )
by Simone
02:51
created

IdsChecker   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Test Coverage

Coverage 86.27%

Importance

Changes 0
Metric Value
wmc 20
dl 0
loc 110
ccs 44
cts 51
cp 0.8627
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setFiltering() 0 3 1
A setObjectFilter() 0 3 1
C validateIds() 0 53 11
A getFinalFilterIds() 0 3 1
A setFilterKey() 0 3 1
A getFilterKey() 0 3 1
A setLogger() 0 3 1
A log() 0 4 2
A __construct() 0 3 1
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 $additionalFilter;
16
17
    private $filterKey;
18
19
    private $finalFilterIds;
20
21
    private $logger;
22
23 5
    public function __construct()
24
    {
25 5
        $this->idsMustBeSubset = true;
26 5
    }
27
28 5
    public function setFiltering($filtering)
29
    {
30 5
        $this->filtering = $filtering;
31 5
    }
32
33 5
    public function setObjectFilter(Filter $additionalFilter)
34
    {
35 5
        $this->additionalFilter = $additionalFilter;
36 5
    }
37
38 1
    public function setFilterKey($filterKey)
39
    {
40 1
        $this->filterKey = $filterKey;
41 1
    }
42
43 5
    public function validateIds()
44
    {
45 5
        $rawFilteredIds = $this->additionalFilter->getIds();
46
47
        // guard
48 5
        $chiave = key($this->filtering);
49 5
        $chiaveEsplosa = explode('|' , $chiave);
50 5
        if (!isset($chiaveEsplosa[1]) || !in_array($chiaveEsplosa[1], ['list', 'nlist'])) {
51
            return;
52
        }
53
54
        // check
55 5
        foreach ($this->filtering as $key => $queryStringIds) {
56 5
            $querystringIds = explode(',', $queryStringIds);
57 5
            $additionalFiltersIds = explode(',', $this->additionalFilter->getIds());
58 5
            foreach ($querystringIds as $requestedId) {
59
60
                // list + list
61 5
                if ($this->additionalFilter->getOperator() == 'list') {
62 2
                    if (!in_array($requestedId, $additionalFiltersIds)) {
63 1
                        throw new ForbiddenContentException(
64 1
                            'Oops! Forbidden requested id ' . $requestedId
65 1
                            . ' is not available. '
66 1
                            . 'Available are ' . join(', ', $additionalFiltersIds) . ''
67
                        );
68
                    }
69
                }
70
71
                // list + nlist
72 4
                if ($this->additionalFilter->getOperator() == 'nlist') {
73 3
                    $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...
74 3
                    if (array_intersect($querystringIds, $additionalFiltersIds) == []) {
75 3
                        $this->filterKey = str_replace('nlist', 'list', $this->additionalFilter->getRawFilter());
76 3
                        $rawFilteredIds = join(',', $querystringIds);
77 4
                        $this->idsMustBeSubset = false;
78
                    }
79
                }
80
81
82
                // nlist + list
83
84
                // nlist + nlist
85
86
            }
87
        }
88
89 4
        $this->finalFilterIds = $rawFilteredIds;
90
91 4
        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...
92 1
            foreach ($this->filtering as $key => $queryStringIds) {
93 1
                $querystringIds = explode(',', $queryStringIds);
94 1
                $additionalFiltersIds = explode(',', $this->additionalFilter->getIds());
95 1
                $this->finalFilterIds = join(',', array_intersect($querystringIds, $additionalFiltersIds));
96
            }
97
        }
98 4
    }
99
100 2
    public function getFilterKey()
101
    {
102 2
        return $this->filterKey;
103
    }
104
105 2
    public function getFinalFilterIds()
106
    {
107 2
        return $this->finalFilterIds;
108
    }
109
110
    public function setLogger(LoggerInterface $logger)
111
    {
112
        $this->logger = $logger;
113
    }
114
115
    public function log($message)
116
    {
117
        if ($this->logger) {
118
            $this->logger->critical($message);
119
        }
120
    }
121
}
122