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
08:23 queued 03:10
created

FilteringObject   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
dl 0
loc 72
ccs 20
cts 28
cp 0.7143
rs 10
c 0
b 0
f 0
wmc 12

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getOperator() 0 7 2
A getOperatorSign() 0 3 1
A hasOperator() 0 3 1
A fromFilter() 0 12 2
A __construct() 0 3 1
A getFieldName() 0 3 1
A is() 0 7 2
A isFieldEqualsOperator() 0 3 1
A isListOperator() 0 3 1
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 5
    private function __construct(array $properties)
21
    {
22 5
        $this->properties = $properties;
23 5
    }
24
25 5
    public static function fromFilter(string $filter)
26
    {
27 5
        $filterAsArray = explode('|', $filter);
28
29 5
        $properties = [];
30 5
        $properties[FilteringObject::KEY_FIELD_NAME] = $filterAsArray[FilteringObject::INDEX_FIELD_NAME];
31
32 5
        if (isset($filterAsArray[FilteringObject::INDEX_OPERATOR_NAME])) {
33 2
            $properties[FilteringObject::KEY_OPERATOR] = $filterAsArray[FilteringObject::INDEX_OPERATOR_NAME];
34
        }
35
36 5
        return new self($properties);
37
    }
38
39 1
    public function getFieldName()
40
    {
41 1
       return $this->properties[FilteringObject::KEY_FIELD_NAME];
42
    }
43
44 2
    public function getOperator()
45
    {
46 2
        if (!isset($this->properties[FilteringObject::KEY_OPERATOR])) {
47 1
            return Operators::getDefaultOperator();
48
        }
49
50 1
        return $this->properties[FilteringObject::KEY_OPERATOR];
51
    }
52
53 2
    public function hasOperator()
54
    {
55 2
        return isset($this->properties[FilteringObject::KEY_OPERATOR]);
56
    }
57
58 1
    public function getOperatorSign()
59
    {
60 1
        return $this->getOperator()['meta'];
61
    }
62
63
    public function isListOperator()
64
    {
65
        return $this->is('list');
66
    }
67
68
    public function isFieldEqualsOperator()
69
    {
70
        return $this->is('field_eq');
71
    }
72
73
    private function is(string $operator) : bool
74
    {
75
        if (!$this->hasOperator()) {
76
            return false;
77
        }
78
79
        return $operator == $this->getOperator();
80
    }
81
}
82