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

api-platform / core / 14008635868

22 Mar 2025 12:39PM UTC coverage: 8.52% (+0.005%) from 8.515%
14008635868

Pull #7042

github

web-flow
Merge fdd88ef56 into 47a6dffbb
Pull Request #7042: Purge parent collections in inheritance cases

4 of 9 new or added lines in 1 file covered. (44.44%)

540 existing lines in 57 files now uncovered.

13394 of 157210 relevant lines covered (8.52%)

22.93 hits per line

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

80.0
/src/Doctrine/Orm/Paginator.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\Doctrine\Orm\Extension\DoctrinePaginatorFactory;
17
use ApiPlatform\State\Pagination\HasNextPagePaginatorInterface;
18
use ApiPlatform\State\Pagination\PaginatorInterface;
19
use Doctrine\ORM\Query;
20
use Doctrine\ORM\Tools\Pagination\Paginator as DoctrinePaginator;
21

22
/**
23
 * Decorates the Doctrine ORM paginator.
24
 *
25
 * @author Kévin Dunglas <dunglas@gmail.com>
26
 */
27
final class Paginator extends AbstractPaginator implements PaginatorInterface, QueryAwareInterface, HasNextPagePaginatorInterface
28
{
29
    private ?int $totalItems = null;
30
    private ?DoctrinePaginatorFactory $doctrinePaginatorFactory = null;
31

32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function getLastPage(): float
36
    {
37
        if (0 >= $this->maxResults) {
418✔
UNCOV
38
            return 1.;
2✔
39
        }
40

41
        return ceil($this->getTotalItems() / $this->maxResults) ?: 1.;
416✔
42
    }
43

44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function getTotalItems(): float
48
    {
49
        return (float) ($this->totalItems ?? $this->totalItems = \count($this->paginator));
423✔
50
    }
51

52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function getQuery(): Query
56
    {
57
        return $this->paginator->getQuery();
×
58
    }
59

60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function hasNextPage(): bool
64
    {
UNCOV
65
        if (isset($this->totalItems)) {
3✔
UNCOV
66
            return $this->totalItems > ($this->firstResult + $this->maxResults);
2✔
67
        }
68

UNCOV
69
        $cloneQuery = clone $this->paginator->getQuery();
1✔
70

UNCOV
71
        $cloneQuery->setParameters(clone $this->paginator->getQuery()->getParameters());
1✔
UNCOV
72
        $cloneQuery->setCacheable(false);
1✔
73

UNCOV
74
        foreach ($this->paginator->getQuery()->getHints() as $name => $value) {
1✔
75
            $cloneQuery->setHint($name, $value);
×
76
        }
77

UNCOV
78
        $cloneQuery
1✔
UNCOV
79
            ->setFirstResult($this->paginator->getQuery()->getFirstResult() + $this->paginator->getQuery()->getMaxResults())
1✔
UNCOV
80
            ->setMaxResults(1);
1✔
81

UNCOV
82
        if (null !== $this->doctrinePaginatorFactory) {
1✔
83
            $fakePaginator = $this->doctrinePaginatorFactory->getPaginator($cloneQuery, $this->paginator->getFetchJoinCollection());
×
84
        } else {
UNCOV
85
            $fakePaginator = new DoctrinePaginator($cloneQuery, $this->paginator->getFetchJoinCollection());
1✔
86
        }
87

UNCOV
88
        return iterator_count($fakePaginator->getIterator()) > 0;
1✔
89
    }
90

91
    public function setDoctrinePaginatorFactory(?DoctrinePaginatorFactory $doctrinePaginatorFactory = null): void
92
    {
93
        $this->doctrinePaginatorFactory = $doctrinePaginatorFactory;
×
94
    }
95
}
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