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

api-platform / core / 15133993414

20 May 2025 09:30AM UTC coverage: 26.313% (-1.2%) from 27.493%
15133993414

Pull #7161

github

web-flow
Merge e2c03d45f into 5459ba375
Pull Request #7161: fix(metadata): infer parameter string type from schema

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

11019 existing lines in 363 files now uncovered.

12898 of 49018 relevant lines covered (26.31%)

34.33 hits per line

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

15.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
    {
UNCOV
37
        if (0 >= $this->maxResults) {
102✔
38
            return 1.;
×
39
        }
40

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

44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function getTotalItems(): float
48
    {
UNCOV
49
        return (float) ($this->totalItems ?? $this->totalItems = \count($this->paginator));
102✔
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
    {
65
        if (isset($this->totalItems)) {
×
66
            return $this->totalItems > ($this->firstResult + $this->maxResults);
×
67
        }
68

69
        $cloneQuery = clone $this->paginator->getQuery();
×
70

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

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

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

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

88
        return iterator_count($fakePaginator->getIterator()) > 0;
×
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