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 ( 86dce3...98cf71 )
by Nur
02:40
created

FinderTrait::findWhere()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 2
dl 0
loc 17
rs 9.9666
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the O2System PHP Framework package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author         Steeve Andrian Salim
9
 * @copyright      Copyright (c) Steeve Andrian Salim
10
 */
11
12
// ------------------------------------------------------------------------
13
14
namespace O2System\Reactor\Models\NoSql\Traits;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Database\DataObjects;
19
20
/**
21
 * Class FinderTrait
22
 *
23
 * @package O2System\Reactor\Models\NoSql\Traits
24
 */
25
trait FinderTrait
26
{
27
    /**
28
     * Find
29
     *
30
     * Find single or many record base on criteria by specific field
31
     *
32
     * @param   string      $criteria Criteria value
33
     * @param   string|null $field    Table column field name | set to primary key by default
34
     *
35
     * @access  protected
36
     * @return  DataObjects\Result|bool Returns FALSE if failed.
37
     */
38
    public function all($fields = null)
39
    {
40
        if (isset($fields)) {
41
            $this->db->select($fields);
42
        }
43
44
        $result = $this->db->from($this->collection)->get();
45
46
        if ($result->count() > 0) {
47
            $this->result = new DataObjects\Result($result, $this);
0 ignored issues
show
Unused Code introduced by
The call to O2System\Database\DataOb...s\Result::__construct() has too many arguments starting with $this. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
            $this->result = /** @scrutinizer ignore-call */ new DataObjects\Result($result, $this);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
Bug Best Practice introduced by
The property result does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
48
49
            return $this->result;
50
        }
51
52
        return false;
53
    }
54
    // ------------------------------------------------------------------------
55
56
    /**
57
     * Find
58
     *
59
     * Find single or many record base on criteria by specific field
60
     *
61
     * @param   string      $criteria Criteria value
62
     * @param   string|null $field    Table column field name | set to primary key by default
63
     *
64
     * @return  DataObjects\Result|bool Returns FALSE if failed.
65
     */
66
    public function find($criteria, $field = null, $limit = null)
67
    {
68
        if (is_array($criteria)) {
0 ignored issues
show
introduced by
The condition is_array($criteria) is always false.
Loading history...
69
            return $this->findIn($criteria, $field);
70
        }
71
72
        $field = isset($field) ? $field : $this->primaryKey;
73
74
        $result = $this->db
75
            ->from($this->collection)
76
            ->getWhere([$field => $criteria], $limit);
77
78
        if ($result->count() > 0) {
79
            $this->result = new DataObjects\Result($result, $this);
0 ignored issues
show
Bug Best Practice introduced by
The property result does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
Unused Code introduced by
The call to O2System\Database\DataOb...s\Result::__construct() has too many arguments starting with $this. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

79
            $this->result = /** @scrutinizer ignore-call */ new DataObjects\Result($result, $this);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
80
81
            if ($result->count() == 1) {
82
                return $this->result->first();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->result->first() returns the type O2System\Database\DataObjects\Result\Row which is incompatible with the documented return type O2System\Database\DataObjects\Result|boolean.
Loading history...
83
            }
84
85
            return $this->result;
86
        }
87
88
        return false;
89
    }
90
    // ------------------------------------------------------------------------
91
92
    /**
93
     * Find In
94
     *
95
     * Find many records within criteria on specific field
96
     *
97
     * @param   array  $inCriteria List of criteria
98
     * @param   string $field      Table column field name | set to primary key by default
99
     *
100
     * @return  DataObjects\Result|bool Returns FALSE if failed.
101
     */
102
    public function findIn(array $inCriteria, $field = null)
103
    {
104
        $field = isset($field) ? $field : $this->primaryKey;
105
106
        $result = $this->db
107
            ->from($this->collection)
108
            ->whereIn($field, $inCriteria)
109
            ->get();
110
111
        if ($result->count() > 0) {
112
            $this->result = new DataObjects\Result($result, $this);
0 ignored issues
show
Bug Best Practice introduced by
The property result does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
Unused Code introduced by
The call to O2System\Database\DataOb...s\Result::__construct() has too many arguments starting with $this. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

112
            $this->result = /** @scrutinizer ignore-call */ new DataObjects\Result($result, $this);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
113
114
            return $this->result;
115
        }
116
117
        return false;
118
    }
119
    // ------------------------------------------------------------------------
120
121
    /**
122
     * Find By
123
     *
124
     * Find single record based on certain conditions
125
     *
126
     * @param   array $conditions List of conditions with criteria
127
     *
128
     * @access  protected
129
     * @return  DataObjects\Result|bool Returns FALSE if failed.
130
     */
131
    public function findWhere(array $conditions, $limit = null)
132
    {
133
        $result = $this->db
134
            ->from($this->collection)
135
            ->getWhere($conditions, $limit);
136
137
        if ($result->count() > 0) {
138
            $this->result = new DataObjects\Result($result, $this);
0 ignored issues
show
Bug Best Practice introduced by
The property result does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
Unused Code introduced by
The call to O2System\Database\DataOb...s\Result::__construct() has too many arguments starting with $this. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

138
            $this->result = /** @scrutinizer ignore-call */ new DataObjects\Result($result, $this);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
139
140
            if ($limit == 1) {
141
                return $this->result->first();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->result->first() returns the type O2System\Database\DataObjects\Result\Row which is incompatible with the documented return type O2System\Database\DataObjects\Result|boolean.
Loading history...
142
            }
143
144
            return $this->result;
145
        }
146
147
        return false;
148
    }
149
    // ------------------------------------------------------------------------
150
151
    /**
152
     * Find In
153
     *
154
     * Find many records not within criteria on specific field
155
     *
156
     * @param   array  $notInCriteria List of criteria
157
     * @param   string $field         Table column field name | set to primary key by default
158
     *
159
     * @return  DataObjects\Result|bool Returns FALSE if failed.
160
     */
161
    public function findNotIn(array $notInCriteria, $field = null)
162
    {
163
        $field = isset($field) ? $field : $this->primaryKey;
164
165
        $result = $this->db
166
            ->from($this->collection)
167
            ->whereNotIn($field, $notInCriteria)
168
            ->get();
169
170
        if ($result->count() > 0) {
171
            $this->result = new DataObjects\Result($result, $this);
0 ignored issues
show
Bug Best Practice introduced by
The property result does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
Unused Code introduced by
The call to O2System\Database\DataOb...s\Result::__construct() has too many arguments starting with $this. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

171
            $this->result = /** @scrutinizer ignore-call */ new DataObjects\Result($result, $this);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
172
173
            return $this->result;
174
        }
175
176
        return false;
177
    }
178
}