LimitFilter::filter()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 3
nc 2
nop 2
1
<?php
2
/**
3
 * This file is part of the ArrayQuery package.
4
 *
5
 * (c) Mauro Cassani<https://github.com/mauretto78>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace ArrayQuery\Filters;
12
13
class LimitFilter extends AbstractFilter
14
{
15
    /**
16
     * @param array $results
17
     * @param null $limitArray
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $limitArray is correct as it would always require null to be passed?
Loading history...
18
     * @return array
19
     */
20
    public static function filter(array $results, $limitArray = null)
21
    {
22
        if (is_array($limitArray) && count($limitArray)) {
0 ignored issues
show
introduced by
The condition is_array($limitArray) is always false.
Loading history...
23
            return self::slice($results, $limitArray);
24
        }
25
26
        return $results;
27
    }
28
29
    /**
30
     * @param $results
31
     * @param $limitArray
32
     * @return array
33
     */
34
    private static function slice($results, $limitArray)
35
    {
36
        return array_slice($results, $limitArray['offset'], $limitArray['lenght']);
37
    }
38
}
39