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
04:59 queued 02:23
created

IdsChecker::validateIds()   C

Complexity

Conditions 11
Paths 19

Size

Total Lines 57
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 34
CRAP Score 11

Importance

Changes 0
Metric Value
dl 0
loc 57
ccs 34
cts 34
cp 1
rs 6.4824
c 0
b 0
f 0
cc 11
eloc 33
nc 19
nop 0
crap 11

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 $additionalFiltersIds;
16
17
    private $objectFilter;
18
19
    private $filterKey;
20
21
    private $finalFilterIds;
22
23
    private $logger;
24
25 6
    public function __construct()
26
    {
27 6
        $this->idsMustBeSubset = true;
28 6
    }
29
30
    /** @codeCoverageIgnore */
31
    public function setLogger(LoggerInterface $logger)
32
    {
33
        $this->logger = $logger;
34
    }
35
36 4
    public function setFiltering($filtering)
37
    {
38 4
        $this->filtering = $filtering;
39 4
    }
40
41 3
    public function setAdditionalFiltersIds($additionalFiltersIds)
42
    {
43 3
        $this->additionalFiltersIds = $additionalFiltersIds;
44 3
    }
45
46 5
    public function setObjectFilter(Filter $objectFilter)
47
    {
48 5
        $this->objectFilter = $objectFilter;
49 5
    }
50
51 4
    public function setFilterKey($filterKey)
52
    {
53 4
        $this->filterKey = $filterKey;
54 4
    }
55
56 6
    public function validateIds()
57
    {
58
        //$this->log('Start to check IDS');
59
60 6
        if (!$this->objectFilter) {
61 1
            throw new \RuntimeException(
62 1
                'Oops! Missing GenericFilter object!!!'
63
            );
64
        }
65
66 5
        if (!$this->filtering) {
67 1
            throw new \RuntimeException(
68 1
                'Oops! Filtering is missing!!!'
69
            );
70
        }
71
72 4
        $rawFilteredIds = $this->objectFilter->getIds();
73
74 4
        foreach ($this->filtering as $key => $queryStringIds) {
75 4
            $qsIds = explode(',', $queryStringIds);
76 4
            $addFilIds = explode(',', $this->additionalFiltersIds);
77 4
            foreach ($qsIds as $requestedId) {
78 4
                if ($this->objectFilter->getOperator() == 'list') {
79 1
                    if (!in_array($requestedId, $addFilIds)) {
80 1
                        throw new ForbiddenContentException(
81 1
                            'Oops! Forbidden requested id ' . $requestedId
82 1
                            . ' is not available. '
83 1
                            . 'Available are "' . join(', ', $addFilIds) . '"'
84
                        );
85
                    }
86
                }
87
88 3
                if ($this->objectFilter->getOperator() == 'nlist') {
89 1
                    $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...
90 1
                    if (array_intersect($qsIds, $addFilIds) == []) {
91 1
                        $this->filterKey = str_replace('nlist', 'list', $this->objectFilter->getRawFilter());
92 1
                        $rawFilteredIds = join(',', $qsIds);
93 3
                        $this->idsMustBeSubset = false;
94
                    }
95
                }
96
            }
97
        }
98
99 3
        $this->finalFilterIds = $rawFilteredIds;
100
101 3
        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...
102 2
            foreach ($this->filtering as $key => $queryStringIds) {
103 2
                $qsIds = explode(',', $queryStringIds);
104 2
                $addFilIds = explode(',', $this->additionalFiltersIds);
105 2
                $this->finalFilterIds = join(',', array_intersect($qsIds, $addFilIds));
106
            }
107
        }
108
109 3
        $this->log(var_export([
110 3
            'filterKey'      => $this->getFilterKey(),
111 3
            'finalFilterIds' => $this->getFinalFilterIds(),
112 3
        ], true));
113 3
    }
114
115 1
    public function idsAreSubset()
116
    {
117 1
        return $this->idsMustBeSubset;
118
    }
119
120 3
    public function getFilterKey()
121
    {
122 3
        return $this->filterKey;
123
    }
124
125 3
    public function getFinalFilterIds()
126
    {
127 3
        return $this->finalFilterIds;
128
    }
129
130
    /** @codeCoverageIgnore */
131
    public function log($message)
132
    {
133
        if ($this->logger) {
134
            $this->logger->debug('[IdsChecker] - ' . $message);
135
        }
136
    }
137
}
138