PaginationDataHandler   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 40
rs 10
c 1
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A resolvePage() 0 9 2
A retrieveData() 0 8 1
A resolveLimit() 0 9 2
A __construct() 0 3 1
1
<?php
2
3
/*
4
 * This file was created by developers working at BitBag
5
 * Do you need more information about us and what we do? Visit our https://bitbag.io website!
6
 * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
7
*/
8
9
declare(strict_types=1);
10
11
namespace BitBag\SyliusElasticsearchPlugin\Controller\RequestDataHandler;
12
13
final class PaginationDataHandler implements PaginationDataHandlerInterface
14
{
15
    /** @var int */
16
    private $defaultLimit;
17
18
    public function __construct(int $defaultLimit)
19
    {
20
        $this->defaultLimit = $defaultLimit;
21
    }
22
23
    public function retrieveData(array $requestData): array
24
    {
25
        $data = [];
26
27
        $this->resolvePage($requestData, $data);
28
        $this->resolveLimit($requestData, $data);
29
30
        return $data;
31
    }
32
33
    private function resolvePage(array $requestData, array &$data): void
34
    {
35
        $page = 1;
36
37
        if (isset($requestData[self::PAGE_INDEX])) {
38
            $page = (int) $requestData[self::PAGE_INDEX];
39
        }
40
41
        $data[self::PAGE_INDEX] = $page;
42
    }
43
44
    private function resolveLimit(array $requestData, array &$data): void
45
    {
46
        $limit = $this->defaultLimit;
47
48
        if (isset($requestData[self::LIMIT_INDEX])) {
49
            $limit = (int) $requestData[self::LIMIT_INDEX];
50
        }
51
52
        $data[self::LIMIT_INDEX] = $limit;
53
    }
54
}
55