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 — master ( dca528...6babe8 )
by Simone
05:37
created

Filter::getValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Mado\QueryBundle\Objects;
4
5
class Filter
6
{
7
    private $rawFilter;
8
9
    private $ids;
10
11
    private $operator;
12
13 4
    public static function box(array $params)
14
    {
15 4
        $rawIds    = $params['ids'];
16 4
        $path      = $params['path'];
17
18 4
        $operator  = key($rawIds);
19 4
        $ids       = join(',', current($rawIds));
20
21 4
        return new self([
22 4
            'raw_filter' => self::buildRawFilter($path, $operator),
23 4
            'ids'        => $ids,
24 4
            'operator'   => $operator,
25 4
            'path'       => $path,
26
        ]);
27
    }
28
29 4
    private static function buildRawFilter($path, $operator)
30
    {
31 4
        return $path . '.id|' . $operator;
32
    }
33
34 5
    private function __construct(array $params)
35
    {
36 5
        $this->rawFilter = $params['raw_filter'];
37 5
        $this->ids       = $params['ids'];
38 5
        $this->operator  = $params['operator'];
39 5
        $this->path      = $params['path'];
0 ignored issues
show
Bug Best Practice introduced by
The property path does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
40 5
    }
41
42 5
    public function getFieldAndOperator()
43
    {
44 5
        return $this->rawFilter;
45
    }
46
47 1
    public function getIds()
48
    {
49 1
        return $this->ids;
50
    }
51
52 2
    public function getOperator()
53
    {
54 2
        return $this->operator;
55
    }
56
57 4
    public function getPath()
58
    {
59 4
        return $this->path;
60
    }
61
62 2
    public function withPath($path)
63
    {
64 2
        $rawFilter = self::buildRawFilter($path, $this->operator);
65
66 2
        if ($path == '') {
67 1
            $rawFilter = str_replace('.', '', $rawFilter);
68
        }
69
70 2
        return new self([
71 2
            'raw_filter' => $rawFilter,
72 2
            'ids'        => $this->ids,
73 2
            'operator'   => $this->operator,
74 2
            'path'       => $path,
75
        ]);
76
    }
77
78 1
    public function withFullPath($path)
79
    {
80 1
        $explodedPath = explode('|', $path);
81
82 1
        $path = $explodedPath[0];
83 1
        $operator = $explodedPath[1];
84
85 1
        return new self([
86 1
            'raw_filter' => join('|', $explodedPath),
87 1
            'ids'        => $this->ids,
88 1
            'operator'   => $operator,
89 1
            'path'       => $path,
90
        ]);
91
    }
92
93 5
    public function getField()
94
    {
95 5
        $explodedPath = explode('|', $this->getFieldAndOperator());
96
97 5
        $field = $explodedPath[0];
98
99 5
        return $field;
100
    }
101
102 1
    public static function fromQueryStringFilter(array $params)
103
    {
104 1
        return new self([
105 1
            'raw_filter' => key($params),
106 1
            'ids' => current($params),
107 1
            'operator' => explode('|', key($params))[1],
108
            'path' => null,
109
        ]);
110
    }
111
112 1
    public function getValue()
113
    {
114 1
        return $this->ids;
115
    }
116
}
117