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

PagerIterator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 60
ccs 20
cts 20
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 1
A next() 0 8 2
A valid() 0 4 1
A rewind() 0 6 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