ImmutablePaginationAdapter::setItemsPerPage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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