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 ( 3121b4...19602e )
by Steeven
02:46
created

Result::offsetExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * This file is part of the O2System 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\Database\DataObjects;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Database\DataObjects\Result\Info;
19
use O2System\Database\DataObjects\Result\Row;
20
use O2System\Spl\DataStructures\Traits\ArrayConversionTrait;
21
22
/**
23
 * Class Result
24
 *
25
 * @package O2System\Database\DataObjects
26
 */
27
class Result extends \SplFixedArray
28
{
29
    use ArrayConversionTrait;
30
31
    /**
32
     * Result::$info
33
     *
34
     * @var Info
35
     */
36
    protected $info;
37
38
    // ------------------------------------------------------------------------
39
40
    /**
41
     * Result::__construct
42
     *
43
     * @param array $rows
44
     */
45
    public function __construct(array $rows)
46
    {
47
        $this->info = new Info();
48
        $this->info->num_total = $this->info->num_rows = count($rows);
0 ignored issues
show
Bug introduced by
The property num_rows does not seem to exist on O2System\Database\DataObjects\Result\Info.
Loading history...
Bug introduced by
The property num_total does not seem to exist on O2System\Database\DataObjects\Result\Info.
Loading history...
49
50
        parent::__construct($this->info->num_rows);
0 ignored issues
show
Bug Best Practice introduced by
The property num_rows does not exist on O2System\Database\DataObjects\Result\Info. Since you implemented __get, consider adding a @property annotation.
Loading history...
51
52
        foreach($rows as $offset => $row) {
53
            $this->offsetSet($offset, $row);
54
        }
55
    }
56
57
    // ------------------------------------------------------------------------
58
59
    /**
60
     * Result::setNumPerPage
61
     *
62
     * @param int $numPerPage
63
     */
64
    public function setNumPerPage($numPerPage)
65
    {
66
        $this->info->num_per_page = (int)$numPerPage;
0 ignored issues
show
Bug introduced by
The property num_per_page does not seem to exist on O2System\Database\DataObjects\Result\Info.
Loading history...
67
    }
68
69
    // ------------------------------------------------------------------------
70
71
    /**
72
     * Result::setNumFoundRows
73
     *
74
     * @param int $numFounds
75
     */
76
    public function setNumFounds($numFounds)
77
    {
78
        $this->info->num_founds = (int)$numFounds;
0 ignored issues
show
Bug introduced by
The property num_founds does not seem to exist on O2System\Database\DataObjects\Result\Info.
Loading history...
79
    }
80
81
    // ------------------------------------------------------------------------
82
83
    /**
84
     * Result::setTotalRows
85
     *
86
     * @param int $totalRows
87
     */
88
    public function setNumTotal($totalRows)
89
    {
90
        $this->info->num_total = (int)$totalRows;
0 ignored issues
show
Bug introduced by
The property num_total does not seem to exist on O2System\Database\DataObjects\Result\Info.
Loading history...
91
    }
92
93
    // ------------------------------------------------------------------------
94
95
    /**
96
     * Result::first
97
     *
98
     * Gets first result row data.
99
     *
100
     * @return \O2System\Database\DataObjects\Result\Row
101
     */
102
    public function first()
103
    {
104
        $this->rewind();
105
106
        return $this->current();
107
    }
108
109
    // ------------------------------------------------------------------------
110
111
    /**
112
     * Result::last
113
     *
114
     * Gets last result row data.
115
     *
116
     * @return \O2System\Database\DataObjects\Result\Row|null
117
     */
118
    public function last()
119
    {
120
        $index = $this->count() - 1;
121
122
        if ($this->offsetExists($index)) {
123
            return $this->offsetGet($index);
124
        }
125
    }
126
127
    // ------------------------------------------------------------------------
128
129
    /**
130
     * Result::previous
131
     *
132
     * Move backward to previous element.
133
     *
134
     * @return void Any returned value is ignored.
135
     * @since 5.0.0
136
     */
137
    public function previous()
138
    {
139
        prev($this);
0 ignored issues
show
Bug introduced by
$this of type O2System\Database\DataObjects\Result is incompatible with the type array expected by parameter $array of prev(). ( Ignorable by Annotation )

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

139
        prev(/** @scrutinizer ignore-type */ $this);
Loading history...
140
    }
141
142
    // ------------------------------------------------------------------------
143
144
    /**
145
     * Result::isEmpty
146
     *
147
     * Checks if the array storage is empty.
148
     *
149
     * @return bool
150
     */
151
    public function isEmpty()
152
    {
153
        return ($this->count() == 0 ? true : false);
154
    }
155
156
    // ------------------------------------------------------------------------
157
158
    /**
159
     * Result::getArrayCopy
160
     *
161
     * Creates a copy of result rows.
162
     *
163
     * @return array A copy of the result rows.
164
     */
165
    public function getArrayCopy()
166
    {
167
        return $this->toArray();
168
    }
169
170
    // ------------------------------------------------------------------------
171
172
    /**
173
     * Result::offsetSet
174
     *
175
     * Offset to set
176
     *
177
     * @link  http://php.net/manual/en/arrayaccess.offsetset.php
178
     *
179
     * @param mixed $offset <p>
180
     *                      The offset to assign the value to.
181
     *                      </p>
182
     * @param mixed $value  <p>
183
     *                      The value to set.
184
     *                      </p>
185
     *
186
     * @return void
187
     * @since 5.0.0
188
     */
189
    public function offsetSet($offset, $value)
190
    {
191
        if(is_array($value)) {
192
            parent::offsetSet($offset, new Row($value));
193
        } else {
194
            parent::offsetSet($offset, $value);
195
        }
196
    }
197
198
    // ------------------------------------------------------------------------
199
200
    /**
201
     * Result::__get
202
     *
203
     * @param string $property
204
     *
205
     * @return mixed
206
     */
207
    public function __get($property)
208
    {
209
        if (property_exists($this, $property)) {
210
            return $this->{$property};
211
        }
212
    }
213
214
    // ------------------------------------------------------------------------
215
216
    /**
217
     * Result::getInfo
218
     *
219
     * @return \O2System\Database\DataObjects\Result\Info
220
     */
221
    public function getInfo()
222
    {
223
        return $this->info;
224
    }
225
226
    // ------------------------------------------------------------------------
227
228
    /**
229
     * Result::countAll
230
     *
231
     * Count all elements
232
     *
233
     * @return int Total row as an integer.
234
     *        </p>
235
     *        <p>
236
     *        The return value is cast to an integer.
237
     *
238
     */
239
    public function countAll()
240
    {
241
        return $this->info->num_founds;
0 ignored issues
show
Bug Best Practice introduced by
The property num_founds does not exist on O2System\Database\DataObjects\Result\Info. Since you implemented __get, consider adding a @property annotation.
Loading history...
242
    }
243
}