Completed
Pull Request — master (#16)
by Mischa
19:07 queued 12:02
created

PaginationDecorator   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 20
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A addPagination() 0 9 1
1
<?php
2
3
/**
4
 * This file is part of the PHP SDK library for the Superdesk Content API.
5
 *
6
 * Copyright 2015 Sourcefabric z.u. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2015 Sourcefabric z.ú.
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace Superdesk\ContentApiSdk\API\Request;
16
17
use Superdesk\ContentApiSdk\ContentApiSdk;
18
19
/**
20
 * Pagination decorator for API request.
21
 */
22
class PaginationDecorator extends RequestDecorator
23
{
24
    /**
25
     * Sets page number and max results per page parameters.
26
     *
27
     * @param int $offset Offset of rows
28
     * @param int $length Length of rows
29
     *
30
     * @return self
31
     */
32
    public function addPagination($offset, $length)
33
    {
34
        $parameters = $this->getParameters();
35
        $parameters['page'] = (int) (ceil($offset / $length) + 1);
36
        $parameters['max_results'] = (int) $length;
37
        $this->setParameters($parameters);
38
39
        return $this;
40
    }
41
}
42