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 (#74)
by Simone
02:23
created

Filter::getFieldName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Mado\QueryBundle\Queries\Objects;
4
5
use Mado\QueryBundle\Dictionary;
6
use Mado\QueryBundle\Services\StringParser;
7
8
final class Filter
9
{
10
    private $operatorName;
11
12
    private $rawOperator;
13
14
    private $fieldName;
15
16
    private $explodedRawFilter;
17
18
    public static function fromString(string $operatorName)
19
    {
20
        return new self($operatorName);
21
    }
22
23
    private function __construct(
24
        string $operatorName,
25
        array $rawOperator = [],
26
        string $fieldName = '',
27
        array $explodedRawFilter = []
28
    ) {
29
        $this->operatorName      = $operatorName;
30
        $this->rawOperator       = $rawOperator;
31
        $this->fieldName         = $fieldName;
32
        $this->explodedRawFilter = $explodedRawFilter;
33
    }
34
35
    public function isListOrNlist() : bool
36
    {
37
        $listFilters = ['list', 'nlist'];
38
39
        return in_array(
40
            $this->operatorName,
41
            $listFilters
42
        );
43
    }
44
45
    public static function fromQueryStringRawFilterExploded(array $explodedRawFilter)
46
    {
47
        $operators = Dictionary::getOperators();
48
49
        if(isset($explodedRawFilter[1])){
50
            $rawOperator = $operators[$explodedRawFilter[1]];
51
        } else {
52
            $rawOperator = $operators[QueryBuilderFactory::DEFAULT_OPERATOR];
0 ignored issues
show
Bug introduced by
The type Mado\QueryBundle\Queries...cts\QueryBuilderFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
53
        }
54
55
        $parser = new StringParser();
56
        $fieldName = $explodedRawFilter[0];
57
        $fieldName = $parser->camelize($fieldName);
58
59
        return new self(
60
            key($rawOperator),
61
            $rawOperator,
62
            $fieldName,
63
            $explodedRawFilter
64
        );
65
    }
66
67
    public function getRawOperator() : array
68
    {
69
        $operators = Dictionary::getOperators();
0 ignored issues
show
Unused Code introduced by
The assignment to $operators is dead and can be removed.
Loading history...
70
71
        $this->ensureRawOperatorIsDefined();
72
73
        return $this->rawOperator;
74
    }
75
76
    public function ensureRawOperatorIsDefined() : void
77
    {
78
        if (!$this->rawOperator) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->rawOperator of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
79
            throw new \RuntimeException(
80
                'Oops! Raw Filter is missing'
81
            );
82
        }
83
    }
84
85
    public static function fromRawFilter(string $filter) : Filter
86
    {
87
        $explodedRawFilter = explode('|',$filter);
88
89
        if (!isset($explodedRawFilter[1])) {
90
            $explodedRawFilter[1] = 'eq';
91
        }
92
93
        return Filter::fromQueryStringRawFilterExploded($explodedRawFilter);
94
    }
95
96
    public function getFieldName() : string
97
    {
98
        return $this->fieldName;
99
    }
100
101
    public function getExplodedRawFilter() : array
102
    {
103
        return $this->explodedRawFilter;
104
    }
105
}
106