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.
Completed
Push — master ( 88ee49...e9876f )
by James
04:43
created

Predicate::andWhere()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 3
1
<?php
2
3
namespace JamesMoss\Flywheel;
4
5
/**
6
 * Query
7
 *
8
 * Builds an executes a query whichs searches and sorts documents from a
9
 * repository.
10
 */
11
class Predicate
12
{
13
    const LOGICAL_AND = 'and';
14
    const LOGICAL_OR = 'or';
15
16
    protected $predicates = array();
17
    protected $operators = array(
18
        '>', '>=', '<', '<=', '==', '===', '!=', '!==',
19
    );
20
21
    public function getAll()
22
    {
23
        return $this->predicates;
24
    }
25
26
    public function where($field, $operator = null, $value = null)
27
    {
28
        return $this->andWhere($field, $operator, $value);
29
    }
30
31
    public function andWhere($field, $operator = null, $value = null)
32
    {
33
        $this->addPredicate(self::LOGICAL_AND, $field, $operator, $value);
34
35
        return $this;
36
    }
37
38
    public function orWhere($field, $operator = null, $value = null)
39
    {
40
        $this->addPredicate(self::LOGICAL_OR, $field, $operator, $value);
41
42
        return $this;
43
    }
44
45
    protected function addPredicate($type, $field, $operator = null, $value = null)
46
    {
47
        if (!$this->predicates) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->predicates 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...
48
            $type = false;
49
        }
50
51
        if ($field instanceof \Closure) {
52
            $sub = new self();
53
            call_user_func($field, $sub);
54
55
            $this->predicates[] = array($type, $sub->getAll());
56
57
            return $this;
58
        }
59
60
        $field = trim($field);
61
62
        if ($field == '') {
63
            throw new \InvalidArgumentException('Field name cannot be empty.');
64
        }
65
66
        if (!in_array($operator, $this->operators)) {
67
            throw new \InvalidArgumentException('Unknown operator `'.$operator.'`.');
68
        }
69
70
        $this->predicates[] = array($type, $field, $operator, $value);
71
72
        return $this;
73
    }
74
}
75