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

api-platform / core / 14635100171

24 Apr 2025 06:39AM UTC coverage: 8.271% (+0.02%) from 8.252%
14635100171

Pull #6904

github

web-flow
Merge c9cefd82e into a3e5e53ea
Pull Request #6904: feat(graphql): added support for graphql subscriptions to work for actions

0 of 73 new or added lines in 3 files covered. (0.0%)

1999 existing lines in 144 files now uncovered.

13129 of 158728 relevant lines covered (8.27%)

13.6 hits per line

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

100.0
/src/State/Pagination/ArrayPaginator.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\State\Pagination;
15

16
/**
17
 * Paginator for arrays.
18
 *
19
 * @author Alan Poulain <contact@alanpoulain.eu>
20
 */
21
final class ArrayPaginator implements \IteratorAggregate, PaginatorInterface, HasNextPagePaginatorInterface
22
{
23
    private \Traversable $iterator;
24
    private readonly int $firstResult;
25
    private readonly int $maxResults;
26
    private readonly int $totalItems;
27

28
    public function __construct(array $results, int $firstResult, int $maxResults)
29
    {
30
        $this->firstResult = $firstResult;
13✔
31
        $this->maxResults = $maxResults;
13✔
32
        $this->totalItems = \count($results);
13✔
33

34
        if ($maxResults > 0 && $firstResult < $this->totalItems) {
13✔
35
            $this->iterator = new \LimitIterator(new \ArrayIterator($results), $firstResult, $maxResults);
6✔
36
        } else {
37
            $this->iterator = new \EmptyIterator();
7✔
38
        }
39
    }
40

41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function getCurrentPage(): float
45
    {
46
        if (0 >= $this->maxResults) {
10✔
47
            return 1.;
2✔
48
        }
49

50
        return floor($this->firstResult / $this->maxResults) + 1.;
8✔
51
    }
52

53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function getLastPage(): float
57
    {
58
        if (0 >= $this->maxResults) {
10✔
59
            return 1.;
2✔
60
        }
61

62
        return ceil($this->totalItems / $this->maxResults) ?: 1.;
8✔
63
    }
64

65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function getItemsPerPage(): float
69
    {
70
        return (float) $this->maxResults;
10✔
71
    }
72

73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function getTotalItems(): float
77
    {
78
        return (float) $this->totalItems;
10✔
79
    }
80

81
    /**
82
     * {@inheritdoc}
83
     */
84
    public function count(): int
85
    {
86
        return iterator_count($this->iterator);
10✔
87
    }
88

89
    /**
90
     * {@inheritdoc}
91
     */
92
    public function getIterator(): \Traversable
93
    {
UNCOV
94
        return $this->iterator;
2✔
95
    }
96

97
    /**
98
     * {@inheritdoc}
99
     */
100
    public function hasNextPage(): bool
101
    {
102
        return $this->getCurrentPage() < $this->getLastPage();
10✔
103
    }
104
}
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