Completed
Push — master ( 3a6f86...868cb7 )
by Márk
01:53
created

PagerIterator::valid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Indigo\Iterator;
4
5
/**
6
 * Iterator used for pagination.
7
 *
8
 * @author Márk Sági-Kazár <[email protected]>
9
 */
10
class PagerIterator extends CallbackIterator
11
{
12
    /**
13
     * @var int
14
     */
15
    protected $currentPage;
16
17
    /**
18
     * @param callable $currentPage
19
     * @param callable $nextPage
20
     * @param callable $currentPageKey
21
     * @param callable $totalPages
22
     * @param callable $setCurrentPage
23
     */
24 1
    public function __construct(
25
        callable $currentPage,
26
        callable $nextPage,
27
        callable $currentPageKey,
28
        callable $totalPages,
29
        callable $setCurrentPage
30
    ) {
31 1
        parent::__construct(
32 1
            $currentPage,
33 1
            $nextPage,
34 1
            $currentPageKey,
35 1
            $totalPages,
36
            $setCurrentPage
37 1
        );
38 1
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 1
    public function next()
44
    {
45 1
        $this->currentPage++;
46
47 1
        if ($this->valid()) {
48 1
            call_user_func($this->rewind, call_user_func($this->next));
49 1
        }
50 1
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 1
    public function valid()
56
    {
57 1
        return $this->currentPage <= call_user_func($this->valid);
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 1
    public function rewind()
64
    {
65 1
        $this->currentPage = 1;
66
67 1
        call_user_func($this->rewind, $this->currentPage);
68 1
    }
69
}
70