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
06:32 queued 03:14
created

IdsChecker::validateIds()   C

Complexity

Conditions 11
Paths 26

Size

Total Lines 54
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 27
CRAP Score 11.0397

Importance

Changes 0
Metric Value
dl 0
loc 54
ccs 27
cts 29
cp 0.931
rs 6.6153
c 0
b 0
f 0
cc 11
eloc 28
nc 26
nop 0
crap 11.0397

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
            $this->finalFilterIds = $this->additionalFilter->getIds();
52
            return;
53
        }
54
55
        // check
56 5
        foreach ($this->filtering as $key => $queryStringIds) {
57 5
            $querystringIds = explode(',', $queryStringIds);
58 5
            $additionalFiltersIds = explode(',', $this->additionalFilter->getIds());
59 5
            foreach ($querystringIds as $requestedId) {
60
61
                // list + list
62 5
                if ($this->additionalFilter->getOperator() == 'list') {
63 2
                    if (!in_array($requestedId, $additionalFiltersIds)) {
64 1
                        throw new ForbiddenContentException(
65 1
                            'Oops! Forbidden requested id ' . $requestedId
66 1
                            . ' is not available. '
67 1
                            . 'Available are ' . join(', ', $additionalFiltersIds) . ''
68
                        );
69
                    }
70
                }
71
72
                // list + nlist
73 4
                if ($this->additionalFilter->getOperator() == 'nlist') {
74 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...
75 3
                    if (array_intersect($querystringIds, $additionalFiltersIds) == []) {
76 3
                        $this->filterKey = str_replace('nlist', 'list', $this->additionalFilter->getFieldAndOperator());
77 3
                        $rawFilteredIds = join(',', $querystringIds);
78 4
                        $this->idsMustBeSubset = false;
79
                    }
80
                }
81
82
83
                // nlist + list
84
85
                // nlist + nlist
86
87
            }
88
        }
89
90 4
        $this->finalFilterIds = $rawFilteredIds;
91
92 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...
93 1
            foreach ($this->filtering as $key => $queryStringIds) {
94 1
                $querystringIds = explode(',', $queryStringIds);
95 1
                $additionalFiltersIds = explode(',', $this->additionalFilter->getIds());
96 1
                $this->finalFilterIds = join(',', array_intersect($querystringIds, $additionalFiltersIds));
97
            }
98
        }
99 4
    }
100
101 2
    public function getFilterKey()
102
    {
103 2
        return $this->filterKey;
104
    }
105
106 2
    public function getFinalFilterIds()
107
    {
108 2
        return $this->finalFilterIds;
109
    }
110
111
    public function setLogger(LoggerInterface $logger)
112
    {
113
        $this->logger = $logger;
114
    }
115
116
    public function log($message)
117
    {
118
        if ($this->logger) {
119
            $this->logger->critical($message);
120
        }
121
    }
122
}
123