• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

RonasIT / laravel-helpers / 12489544920

25 Dec 2024 04:53AM UTC coverage: 78.401% (+0.02%) from 78.385%
12489544920

Pull #168

github

web-flow
Merge a36445178 into 338a94856
Pull Request #168: #140 global export mode not affect for email testing

2 of 2 new or added lines in 1 file covered. (100.0%)

1020 of 1301 relevant lines covered (78.4%)

11.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Iterators/DBIterator.php
1
<?php
2

3
namespace RonasIT\Support\Iterators;
4

5
use Iterator;
6
use Generator;
7

8
class DBIterator implements Iterator
9
{
10
    protected $query;
11
    protected $position;
12
    protected $sample = [];
13
    protected $itemsPerPage;
14
    protected $currentItem = [];
15

16
    public function __construct($query, $itemsPerPage = 100)
17
    {
18
        $this->query = $query;
×
19
        $this->itemsPerPage = $itemsPerPage;
×
20
    }
21

22
    public function rewind(): void
23
    {
24
        $this->loadSample();
×
25
    }
26

27
    public function current(): mixed
28
    {
29
        return $this->sample['data'][$this->position];
×
30
    }
31

32
    public function key(): mixed
33
    {
34
        return $this->sample['data'][$this->position]['id'];
×
35
    }
36

37
    public function next(): void
38
    {
39
        $this->position++;
×
40

41
        if ($this->isEndOfSample()) {
×
42
            $this->loadSample($this->sample['current_page'] + 1);
×
43
        }
44
    }
45

46
    public function valid(): bool
47
    {
48
        return !($this->isLastSample() && $this->isEndOfSample());
×
49
    }
50

51
    public function isEndOfSample(): bool
52
    {
53
        return $this->position >= count($this->sample['data']);
×
54
    }
55

56
    public function isLastSample(): bool
57
    {
58
        return $this->sample['current_page'] >= $this->sample['last_page'];
×
59
    }
60

61
    public function loadSample($page = 1): void
62
    {
63
        $this->sample = $this->query
×
64
            ->paginate($this->itemsPerPage, ['*'], 'page', $page)
×
65
            ->toArray();
×
66

67
        $this->position = 0;
×
68
    }
69

70
    public function getGenerator(): Generator
71
    {
72
        $this->rewind();
×
73

74
        while ($this->valid()) {
×
75
            yield $this->current();
×
76

77
            $this->next();
×
78
        }
79
    }
80
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc