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

api-platform / core / 18370496742

09 Oct 2025 08:35AM UTC coverage: 0.0% (-21.9%) from 21.92%
18370496742

push

github

soyuka
docs: changelog 4.2.2

0 of 56436 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/src/Hydra/State/Util/PaginationHelperTrait.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\Hydra\State\Util;
15

16
use ApiPlatform\Hydra\PartialCollectionView;
17
use ApiPlatform\Metadata\UrlGeneratorInterface;
18
use ApiPlatform\Metadata\Util\IriHelper;
19
use ApiPlatform\State\Pagination\PaginatorInterface;
20
use ApiPlatform\State\Pagination\PartialPaginatorInterface;
21

22
trait PaginationHelperTrait
23
{
24
    private function getPaginationIri(array $parsed, ?float $currentPage, ?float $lastPage, ?float $itemsPerPage, ?float $pageTotalItems, ?int $urlGenerationStrategy, string $pageParameterName): array
25
    {
26
        $first = $last = $previous = $next = null;
×
27

28
        if (null !== $lastPage) {
×
29
            $first = IriHelper::createIri($parsed['parts'], $parsed['parameters'], $pageParameterName, 1., $urlGenerationStrategy);
×
30
            $last = IriHelper::createIri($parsed['parts'], $parsed['parameters'], $pageParameterName, $lastPage, $urlGenerationStrategy);
×
31
        }
32

33
        if (1. !== $currentPage) {
×
34
            $previous = IriHelper::createIri($parsed['parts'], $parsed['parameters'], $pageParameterName, $currentPage - 1., $urlGenerationStrategy);
×
35
        }
36

37
        if ((null !== $lastPage && $currentPage < $lastPage) || (null === $lastPage && $pageTotalItems >= $itemsPerPage)) {
×
38
            $next = IriHelper::createIri($parsed['parts'], $parsed['parameters'], $pageParameterName, $currentPage + 1., $urlGenerationStrategy);
×
39
        }
40

41
        return [
×
42
            'first' => $first,
×
43
            'last' => $last,
×
44
            'previous' => $previous,
×
45
            'next' => $next,
×
46
        ];
×
47
    }
48

49
    private function getPartialCollectionView(mixed $object, string $requestUri, string $pageParameterName, string $enabledParameterName, ?int $urlGenerationStrategy = UrlGeneratorInterface::ABS_PATH): PartialCollectionView
50
    {
51
        $currentPage = $lastPage = $itemsPerPage = $pageTotalItems = null;
×
52
        $paginated = false;
×
53
        if ($object instanceof PartialPaginatorInterface) {
×
54
            $paginated = true;
×
55
            if ($object instanceof PaginatorInterface) {
×
56
                $paginated = 1. !== $lastPage = $object->getLastPage();
×
57
            } else {
58
                $itemsPerPage = $object->getItemsPerPage();
×
59
                $pageTotalItems = (float) \count($object);
×
60
            }
61
            $currentPage = $object->getCurrentPage();
×
62
        }
63

64
        $parsed = IriHelper::parseIri($requestUri, $pageParameterName);
×
65
        $appliedFilters = $parsed['parameters'];
×
66
        unset($appliedFilters[$enabledParameterName]);
×
67

68
        $id = IriHelper::createIri($parsed['parts'], $parsed['parameters'], $pageParameterName, $paginated ? $currentPage : null, $urlGenerationStrategy);
×
69

70
        if (!$paginated && $appliedFilters) {
×
71
            return new PartialCollectionView($id);
×
72
        }
73

74
        ['first' => $first, 'last' => $last, 'previous' => $previous, 'next' => $next] = $this->getPaginationIri($parsed, $currentPage, $lastPage, $itemsPerPage, $pageTotalItems, $urlGenerationStrategy, $pageParameterName);
×
75

76
        if (!$paginated) {
×
77
            $first = null;
×
78
            $last = null;
×
79
        }
80

81
        return new PartialCollectionView(
×
82
            $id,
×
83
            $first,
×
84
            $last,
×
85
            $previous,
×
86
            $next
×
87
        );
×
88
    }
89
}
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

© 2026 Coveralls, Inc