Code Duplication    Length = 54-56 lines in 3 locations

src/Iterator/LazySkipWhileIterator.php 1 location

@@ 5-60 (lines=56) @@
2
3
namespace Collections\Iterator;
4
5
class LazySkipWhileIterator implements \Iterator
6
{
7
    /**
8
     * @var \Iterator
9
     */
10
    private $it;
11
12
    /**
13
     * @var callable
14
     */
15
    private $fn;
16
17
    public function __construct($it, $fn)
18
    {
19
        $this->it = $it;
20
        $this->fn = $fn;
21
        while ($it->valid() && $fn($it->current())) {
22
            $it->next();
23
        }
24
    }
25
26
    public function __clone()
27
    {
28
        $this->it = clone $this->it;
29
    }
30
31
    public function rewind()
32
    {
33
        $it = $this->it;
34
        $fn = $this->fn;
35
        $it->rewind();
36
        while ($it->valid() && $fn($it->current())) {
37
            $it->next();
38
        }
39
    }
40
41
    public function valid()
42
    {
43
        return $this->it->valid();
44
    }
45
46
    public function next()
47
    {
48
        $this->it->next();
49
    }
50
51
    public function key()
52
    {
53
        return $this->it->key();
54
    }
55
56
    public function current()
57
    {
58
        return $this->it->current();
59
    }
60
}

src/Iterator/LazySkipWhileKeyedIterator.php 1 location

@@ 5-60 (lines=56) @@
2
3
namespace Collections\Iterator;
4
5
class LazySkipWhileKeyedIterator implements \Iterator
6
{
7
    /**
8
     * @var \Iterator
9
     */
10
    private $it;
11
12
    /**
13
     * @var callable
14
     */
15
    private $fn;
16
17
    public function __construct($it, $fn)
18
    {
19
        $this->it = $it;
20
        $this->fn = $fn;
21
        while ($it->valid() && $fn($it->current())) {
22
            $it->next();
23
        }
24
    }
25
26
    public function __clone()
27
    {
28
        $this->it = clone $this->it;
29
    }
30
31
    public function rewind()
32
    {
33
        $it = $this->it;
34
        $fn = $this->fn;
35
        $it->rewind();
36
        while ($it->valid() && $fn($it->current())) {
37
            $it->next();
38
        }
39
    }
40
41
    public function valid()
42
    {
43
        return $this->it->valid();
44
    }
45
46
    public function next()
47
    {
48
        $this->it->next();
49
    }
50
51
    public function key()
52
    {
53
        return $this->it->key();
54
    }
55
56
    public function current()
57
    {
58
        return $this->it->current();
59
    }
60
}
61

src/Iterator/LazyTakeWhileIterator.php 1 location

@@ 5-58 (lines=54) @@
2
3
namespace Collections\Iterator;
4
5
class LazyTakeWhileIterator implements \Iterator
6
{
7
    /**
8
     * @var \Iterator
9
     */
10
    private $it;
11
12
    /**
13
     * @var callable
14
     */
15
    private $fn;
16
17
    public function __construct($it, $fn)
18
    {
19
        $this->it = $it;
20
        $this->fn = $fn;
21
        while ($it->valid() && $fn($it->current())) {
22
            $it->next();
23
        }
24
    }
25
26
    public function __clone()
27
    {
28
        $this->it = clone $this->it;
29
    }
30
31
    public function rewind()
32
    {
33
        $this->it->rewind();
34
    }
35
36
    public function valid()
37
    {
38
        $it = $this->it;
39
        $fn = $this->fn;
40
41
        return ($it->valid() && $fn($it->current()));
42
    }
43
44
    public function next()
45
    {
46
        $this->it->next();
47
    }
48
49
    public function key()
50
    {
51
        return $this->it->key();
52
    }
53
54
    public function current()
55
    {
56
        return $this->it->current();
57
    }
58
}
59