Passed
Push — master ( f85738...3d85c1 )
by Peter
04:52
created

PaginationFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 14
dl 0
loc 48
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 10 1
A __construct() 0 5 1
A setPageSize() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Admin\Grid\Factory;
6
7
use AbterPhp\Framework\Grid\Pagination\Options;
8
use AbterPhp\Framework\Grid\Pagination\Pagination;
9
10
class PaginationFactory
11
{
12
    /** @var Options */
13
    protected $options;
14
15
    /** @var int */
16
    protected $pageSize;
17
18
    /**
19
     * Pagination constructor.
20
     *
21
     * @param Options $options
22
     */
23
    public function __construct(Options $options)
24
    {
25
        $this->options = $options;
26
27
        $this->pageSize = $options->getDefaultPageSize();
28
    }
29
30
    /**
31
     * @param int $pageSize
32
     *
33
     * @return $this
34
     */
35
    public function setPageSize(int $pageSize): PaginationFactory
36
    {
37
        $this->pageSize = $pageSize;
38
39
        return $this;
40
    }
41
42
    /**
43
     * @param array  $params
44
     * @param string $baseUrl
45
     *
46
     * @return Pagination
47
     */
48
    public function create(array $params, string $baseUrl): Pagination
49
    {
50
        return new Pagination(
51
            $params,
52
            $baseUrl,
53
            $this->options->getNumberCount(),
54
            $this->options->getDefaultPageSize(),
55
            $this->options->getPageSizeOptions(),
56
            [],
57
            $this->options->getAttributes()
58
        );
59
    }
60
}
61