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

PaginatedLoader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 21
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B applyPaginationToCriteria() 0 18 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