ArrayProcessor::field()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 2
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace mav3rick177\RapidPagination\Base;
4
5
class ArrayProcessor extends AbstractProcessor
6
{
7
    /**
8
     * Return comparable value from a row.
9
     *
10
     * @param  mixed      $row
11
     * @param  string     $column
12
     * @return int|string
13
     */
14
    protected function field($row, $column)
15
    {
16
        return is_object($row) && !$row instanceof \ArrayAccess ? $row->$column : $row[$column];
17
    }
18
19
    /**
20
     * Return the n-th element of collection.
21
     * Must return null if not exists.
22
     *
23
     * @param  array $rows
24
     * @param  int   $offset
25
     * @return mixed
26
     */
27
    protected function offset($rows, $offset)
28
    {
29
        return isset($rows[$offset]) ? $rows[$offset] : null;
30
    }
31
32
    /**
33
     * Slice rows, like PHP function array_slice().
34
     *
35
     * @param  array    $rows
36
     * @param  int      $offset
37
     * @param  null|int $length
38
     * @return array
39
     */
40
    protected function slice($rows, $offset, $length = null)
41
    {
42
        return array_slice($rows, $offset, $length);
43
    }
44
45
    /**
46
     * Count rows, like PHP function count().
47
     *
48
     * @param  array $rows
49
     * @return int
50
     */
51
    protected function count($rows)
52
    {
53
        return count($rows);
54
    }
55
56
    /**
57
     * Reverse rows, like PHP function array_reverse().
58
     *
59
     * @param  array $rows
60
     * @return array
61
     */
62
    protected function reverse($rows)
63
    {
64
        return array_reverse($rows);
65
    }
66
}
67