ImmutablePaginationAdapter   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 62
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getPage() 0 4 1
A getItemsPerPage() 0 4 1
A setPage() 0 4 1
A setItemsPerPage() 0 8 1
A shouldBeApplied() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace KGzocha\Searcher\Criteria\Adapter;
5
6
use KGzocha\Searcher\Criteria\PaginationCriteriaInterface;
7
8
/**
9
 * This adapter will not allow to change itemsPerPage parameter in adapted pagination Criteria.
10
 * Every other behaviour will be untouched.
11
 *
12
 * @author Krzysztof Gzocha <[email protected]>
13
 */
14
class ImmutablePaginationAdapter implements PaginationCriteriaInterface
15
{
16
    /**
17
     * @var PaginationCriteriaInterface
18
     */
19
    private $pagination;
20
21
    /**
22
     * @param PaginationCriteriaInterface $pagination
23
     */
24 11
    public function __construct(PaginationCriteriaInterface $pagination)
25
    {
26 11
        $this->pagination = $pagination;
27 11
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 3
    public function getPage(): int
33
    {
34 3
        return $this->pagination->getPage();
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 4
    public function getItemsPerPage(): int
41
    {
42 4
        return $this->pagination->getItemsPerPage();
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 4
    public function setPage(int $page = null)
49
    {
50 4
        return $this->pagination->setPage($page);
51
    }
52
53
    /**
54
     * This method will not allow to change items per page.
55
     * On each call it will set the same value.
56
     *
57
     * {@inheritdoc}
58
     */
59 4
    public function setItemsPerPage(int $itemsPerPage = null)
60
    {
61
        return $this
62 4
            ->pagination
63 4
            ->setItemsPerPage(
64 4
                $this->pagination->getItemsPerPage()
65
            );
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71 6
    public function shouldBeApplied(): bool
72
    {
73 6
        return $this->pagination->shouldBeApplied();
74
    }
75
}
76