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

Query::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
 * @todo turn the limit and order by arrays into value objects
12
 */
13
class Query
14
{
15
    protected $repo;
16
    protected $predicate;
17
    protected $limit   = array();
18
    protected $orderBy = array();
19
20
    /**
21
     * Constructor
22
     *
23
     * @param Repository $repository The repo this query will run against.
24
     */
25
    public function __construct(Repository $repository)
26
    {
27
        $this->repo = $repository;
28
        $this->predicate = new Predicate();
29
    }
30
31
    /**
32
     * Set a limit on the number of documents returned. An offset from 0 can
33
     * also be specified.
34
     *
35
     * @param int $count  The number of documents to return.
36
     * @param int $offset The offset from which to return.
37
     *
38
     * @return Query The same instance of this class.
39
     */
40
    public function limit($count, $offset = 0)
41
    {
42
        $this->limit = array((int) $count, (int) $offset);
43
44
        return $this;
45
    }
46
47
    /**
48
     * Sets the fields to order the results by. They should be in the
49
     * the format 'fieldname ASC|DESC'. e.g 'dateAdded DESC'.
50
     *
51
     * @param mixed $fields An array comprising strings in the above format
52
     *                      (or a single string)
53
     *
54
     * @return Query The same instance of this class.
55
     */
56
    public function orderBy($fields)
57
    {
58
        $this->orderBy = (array) $fields;
59
60
        return $this;
61
    }
62
63
    /**
64
     * @see Query::andWhere
65
     *
66
     * @return Query The same instance of this class.
67
     */
68
    public function where($field, $operator = null, $value = null)
69
    {
70
        return $this->andWhere($field, $operator, $value);
71
    }
72
73
    /**
74
     * Adds a boolean AND predicate for this query,
75
     *
76
     * @param string|Closure $field    The name of the field to match or an anonymous
77
     *                                 function that will define sub predicates.
78
     * @param string         $operator An operator from the allowed list.
79
     * @param string         $value    The value to compare against.
80
     *
81
     * @return Query The same instance of this class.
82
     */
83
    public function andWhere($field, $operator = null, $value = null)
84
    {
85
        $this->predicate->andWhere($field, $operator, $value);
86
87
        return $this;
88
    }
89
90
    /**
91
     * Adds a boolean OR predicate for this query,
92
     *
93
     * @param string|Closure $field    The name of the field to match or an anonymous
94
     *                                 function that will define sub predicates.
95
     * @param string         $operator An operator from the allowed list.
96
     * @param string         $value    The value to compare against.
97
     *
98
     * @return Query The same instance of this class.
99
     */
100
    public function orWhere($field, $operator = null, $value = null)
101
    {
102
        $this->predicate->orWhere($field, $operator, $value);
103
104
        return $this;
105
    }
106
107
    /**
108
     * Runs the query.
109
     *
110
     * @return Result The documents returned from this query.
111
     */
112
    public function execute()
113
    {
114
        $qe = new QueryExecuter($this->repo, $this->predicate, $this->limit, $this->orderBy);
115
116
        return $qe->run();
117
    }
118
}
119