PaginateHandler::getPriority()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
nc 1
cc 1
eloc 2
nop 0
crap 1
1
<?php
2
3
namespace Nayjest\Querying\Handler\PostProcess;
4
5
use Nayjest\Querying\Handler\AbstractPaginateHandler;
6
use Nayjest\Querying\Handler\Priority;
7
use Nayjest\Querying\Operation\PaginateOperation;
8
9
class PaginateHandler extends AbstractPaginateHandler
10
{
11 1
    public function getPriority()
12
    {
13 1
        return Priority::POST_PROCESS - 4;
14
    }
15
16 1
    public function apply($dataSource)
17
    {
18
        /** @var PaginateOperation $operation */
19 1
        $operation = $this->operation;
20
        /**
21
         * @todo optimise for generators
22
         */
23 1
        if (!is_array($dataSource)) {
24
            $dataSource = iterator_to_array($dataSource);
25
        }
26 1
        return array_slice(
27 1
            $dataSource,
28 1
            $this->getOffset($operation),
29 1
            $operation->getPageSize()
30 1
        );
31
    }
32
}
33