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 — master (#38)
by Simone
04:01
created

FilteringObject::fromFilter()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
ccs 7
cts 7
cp 1
crap 2
1
<?php
2
3
namespace Mado\QueryBundle\Objects;
4
5
use Mado\QueryBundle\Queries\QueryBuilderFactory;
6
use Mado\QueryBundle\Vocabulary\Operators;
7
8
class FilteringObject
9
{
10
    const INDEX_FIELD_NAME = 0;
11
12
    const INDEX_OPERATOR_NAME = 1;
13
14
    const KEY_FIELD_NAME = 'field_name';
15
16
    const KEY_OPERATOR = 'operator';
17
18
    private $properties;
19
20 8
    private function __construct(array $properties)
21
    {
22 8
        $this->properties = $properties;
23 8
    }
24
25 8
    public static function fromFilter(string $filter)
26
    {
27 8
        $filterAsArray = explode('|', $filter);
28
29 8
        $properties = [];
30 8
        $properties[FilteringObject::KEY_FIELD_NAME] = $filterAsArray[FilteringObject::INDEX_FIELD_NAME];
31
32 8
        if (isset($filterAsArray[FilteringObject::INDEX_OPERATOR_NAME])) {
33 4
            $properties[FilteringObject::KEY_OPERATOR] = $filterAsArray[FilteringObject::INDEX_OPERATOR_NAME];
34
        }
35
36 8
        return new self($properties);
37
    }
38
39 1
    public function getFieldName()
40
    {
41 1
        return $this->properties[FilteringObject::KEY_FIELD_NAME];
42
    }
43
44 4
    public function getOperator()
45
    {
46 4
        if (!isset($this->properties[FilteringObject::KEY_OPERATOR])) {
47 1
            return Operators::getDefaultOperator();
48
        }
49
50 3
        return $this->properties[FilteringObject::KEY_OPERATOR];
51
    }
52
53 5
    public function hasOperator()
54
    {
55 5
        return isset($this->properties[FilteringObject::KEY_OPERATOR]);
56
    }
57
58 1
    public function getOperatorSign()
59
    {
60 1
        return $this->getOperator()['meta'];
61
    }
62
63 1
    public function isListOperator() : bool
64
    {
65 1
        return $this->is('list');
66
    }
67
68 1
    public function isFieldEqualsOperator() : bool
69
    {
70 1
        return $this->is('field_eq');
71
    }
72
73 2
    private function is(string $operator) : bool
74
    {
75 2
        return $this->hasOperator() &&
76 2
            $operator == $this->getOperator();
77
    }
78
}
79