Page   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
eloc 21
c 3
b 0
f 0
dl 0
loc 66
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A getIterator() 0 6 1
A __toString() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\AuraSqlModule\Pagerfanta;
6
7
use Iterator;
8
use IteratorAggregate;
9
use Pagerfanta\Pagerfanta;
10
use Pagerfanta\View\ViewInterface;
11
12
/** @implements IteratorAggregate<int, Page> */
13
final class Page implements IteratorAggregate
14
{
15
    /** @var int */
16
    public $maxPerPage;
17
18
    /** @var int */
19
    public $current;
20
21
    /** @var int */
22
    public $total;
23
24
    /** @var bool */
25
    public $hasNext;
26
27
    /** @var bool */
28
    public $hasPrevious;
29
30
    /** @var mixed */
31
    public $data;
32
33
    /** @var Pagerfanta<mixed> */
34
    private Pagerfanta $pagerfanta;
35
36
    /** @var callable */
37
    private $routeGenerator;
38
    private ViewInterface $view;
39
40
    /** @var array<string, mixed> */
41
    private array $viewOption;
42
43
    /**
44
     * @phpstan-param Pagerfanta<mixed> $pagerfanta
45
     * @phpstan-param array<string, mixed>      $viewOption
46
     */
47
    public function __construct(
48
        Pagerfanta $pagerfanta,
49
        RouteGeneratorInterface $routeGenerator,
50
        ViewInterface $view,
51
        array $viewOption
52
    ) {
53
        $this->pagerfanta = $pagerfanta;
54
        $this->routeGenerator = $routeGenerator;
55
        $this->view = $view;
56
        $this->viewOption = $viewOption;
57
    }
58
59
    public function __toString(): string
60
    {
61
        return (string) $this->view->render(
62
            $this->pagerfanta,
63
            $this->routeGenerator,
64
            $this->viewOption,
65
        );
66
    }
67
68
    /**
69
     * {@inheritDoc}
70
     *
71
     * @return Iterator<int, Page>
72
     */
73
    public function getIterator(): Iterator
74
    {
75
        /** @var Iterator<int, Page> $iterator */
76
        $iterator = $this->pagerfanta->getIterator();
77
78
        return $iterator;
79
    }
80
}
81