Completed
Push — master ( a682ba...4851b3 )
by Paweł
40:50
created

PaginatedLoader::applyPaginationToCriteria()   B

Complexity

Conditions 5
Paths 12

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 9
cts 9
cp 1
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 9
nc 12
nop 2
crap 5
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Content Bundle.
7
 *
8
 * Copyright 2015 Sourcefabric z.u. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2015 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\ContentBundle\Loader;
18
19
use SWP\Component\Common\Criteria\Criteria;
20
21
/**
22
 * Abstract class PaginatedLoader.
23
 */
24
abstract class PaginatedLoader
25
{
26 13
    public function applyPaginationToCriteria(Criteria $criteria, array $parameters): Criteria
27
    {
28 13
        if (array_key_exists('limit', $parameters)) {
29 1
            $criteria->set('maxResults', (int) $parameters['limit']);
30
        }
31
32 13
        if (array_key_exists('start', $parameters)) {
33 1
            $criteria->set('firstResult', (int) $parameters['start']);
34
        }
35
36 13
        if (array_key_exists('order', $parameters)) {
37 3
            if (count($parameters['order']) == 2) {
38 3
                $criteria->set('order', [$parameters['order'][0] => $parameters['order'][1]]);
39
            }
40
        }
41
42 13
        return $criteria;
43
    }
44
}
45