RequestBasedPaginationService   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 27
ccs 2
cts 4
cp 0.5
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setPagingRequestAttribute() 0 6 1
A getPagingParamsFromRequest() 0 4 1
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * Copyright (c) Phauthentic (https://github.com/Phauthentic)
5
 *
6
 * Licensed under The MIT License
7
 * For full copyright and license information, please see the LICENSE.txt
8
 * Redistributions of files must retain the above copyright notice.
9
 *
10
 * @copyright     Copyright (c) Phauthentic (https://github.com/Phauthentic)
11
 * @link          https://github.com/Phauthentic
12
 * @license       https://opensource.org/licenses/mit-license.php MIT License
13
 */
14
namespace Phauthentic\Pagination;
15
16
use Phauthentic\Pagination\Paginator\PaginatorInterface;
17
use Psr\Http\Message\ServerRequestInterface;
18
19
/**
20
 * Pagination Service
21
 *
22
 * Application layer pagination service that should in theory be able to paginate
23
 * any data / persistence layer implementation through the mappers.
24
 */
25
class RequestBasedPaginationService extends PaginationService
26
{
27
    /**
28
     * Gets the pagination params from the request
29
     *
30
     * @param \Psr\Http\Message\ServerRequestInterface $serverRequest Server Request
31
     * @return \Phauthentic\Pagination\PaginationParamsInterface
32
     */
33 1
    public function getPagingParamsFromRequest(
34
        ServerRequestInterface $serverRequest
35
    ): PaginationParamsInterface {
36 1
        return $this->paginationParamsFactory->build($serverRequest);
37
    }
38
39
    /**
40
     * Sets the pagination data to a request attribute
41
     *
42
     * @param \Psr\Http\Message\ServerRequestInterface $serverRequest Server Request
43
     * @param \Phauthentic\Pagination\PaginationParamsInterface $paginationParams Pagination Params
44
     * @return \Psr\Http\Message\ServerRequestInterface
45
     */
46
    public function setPagingRequestAttribute(
47
        ServerRequestInterface $serverRequest,
48
        PaginationParamsInterface $paginationParams,
49
        string $attributeName = 'paging'
50
    ): ServerRequestInterface {
51
        return $serverRequest->withAttribute($attributeName, $paginationParams);
52
    }
53
}
54