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

api-platform / core / 15955912273

29 Jun 2025 01:51PM UTC coverage: 22.057% (-0.03%) from 22.082%
15955912273

Pull #7249

github

web-flow
Merge d9904d788 into a42034dc3
Pull Request #7249: chore: solve some phpstan issues

0 of 9 new or added lines in 8 files covered. (0.0%)

11540 existing lines in 372 files now uncovered.

11522 of 52237 relevant lines covered (22.06%)

11.08 hits per line

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

0.0
/src/Doctrine/Common/CollectionPaginator.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\Doctrine\Common;
15

16
use ApiPlatform\State\Pagination\PaginatorInterface;
17
use Doctrine\Common\Collections\ReadableCollection;
18

19
/**
20
 * @template T of object
21
 *
22
 * @implements PaginatorInterface<T>
23
 * @implements \IteratorAggregate<T>
24
 */
25
final class CollectionPaginator implements \IteratorAggregate, PaginatorInterface
26
{
27
    /**
28
     * @var array<array-key,T>
29
     */
30
    private readonly array $items;
31
    private readonly float $totalItems;
32

33
    /**
34
     * @param ReadableCollection<array-key,T> $collection
35
     */
36
    public function __construct(
37
        readonly ReadableCollection $collection,
38
        private readonly float $currentPage,
39
        private readonly float $itemsPerPage,
40
    ) {
41
        $this->items = $collection->slice((int) (($currentPage - 1) * $itemsPerPage), $itemsPerPage > 0 ? (int) $itemsPerPage : null);
×
42
        $this->totalItems = $collection->count();
×
43
    }
44

45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function getCurrentPage(): float
49
    {
50
        return $this->currentPage;
×
51
    }
52

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

62
        return max(ceil($this->totalItems / $this->itemsPerPage) ?: 1., 1.);
×
63
    }
64

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

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

81
    /**
82
     * {@inheritdoc}
83
     */
84
    public function count(): int
85
    {
86
        return \count($this->items);
×
87
    }
88

89
    /**
90
     * {@inheritdoc}
91
     *
92
     * @return \Traversable<T>
93
     */
94
    public function getIterator(): \Traversable
95
    {
96
        yield from $this->items;
×
97
    }
98
}
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