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

api-platform / core / 13897184482

17 Mar 2025 10:29AM UTC coverage: 17.371% (+8.6%) from 8.768%
13897184482

Pull #7027

github

web-flow
Merge 6b496c593 into ba5cea729
Pull Request #7027: fix(laravel): json api default parameters

0 of 18 new or added lines in 2 files covered. (0.0%)

545 existing lines in 58 files now uncovered.

4729 of 27224 relevant lines covered (17.37%)

78.16 hits per line

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

75.0
/src/Doctrine/Orm/AbstractPaginator.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\Orm;
15

16
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
17
use ApiPlatform\State\Pagination\PartialPaginatorInterface;
18
use Doctrine\ORM\Query;
19
use Doctrine\ORM\Tools\Pagination\Paginator as DoctrinePaginator;
20

21
abstract class AbstractPaginator implements \IteratorAggregate, PartialPaginatorInterface
22
{
23
    protected DoctrinePaginator $paginator;
24
    protected array|\Traversable $iterator;
25
    protected ?int $firstResult;
26
    protected ?int $maxResults;
27

28
    /**
29
     * @throws InvalidArgumentException
30
     */
31
    public function __construct(DoctrinePaginator $paginator)
32
    {
33
        $query = $paginator->getQuery();
200✔
34

35
        if (null === ($firstResult = $query->getFirstResult()) || $firstResult < 0 || null === $maxResults = $query->getMaxResults()) { // @phpstan-ignore-line
200✔
36
            throw new InvalidArgumentException(\sprintf('"%1$s::setFirstResult()" or/and "%1$s::setMaxResults()" was/were not applied to the query.', Query::class));
×
37
        }
38

39
        $this->paginator = $paginator;
200✔
40
        $this->firstResult = $firstResult;
200✔
41
        $this->maxResults = $maxResults;
200✔
42
    }
43

44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function getCurrentPage(): float
48
    {
49
        if (0 >= $this->maxResults) {
198✔
UNCOV
50
            return 1.;
×
51
        }
52

53
        return floor($this->firstResult / $this->maxResults) + 1.;
198✔
54
    }
55

56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function getItemsPerPage(): float
60
    {
61
        return (float) $this->maxResults;
8✔
62
    }
63

64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function getIterator(): \Traversable
68
    {
69
        return $this->iterator ?? $this->iterator = $this->paginator->getIterator();
200✔
70
    }
71

72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function count(): int
76
    {
UNCOV
77
        return iterator_count($this->getIterator());
×
78
    }
79
}
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