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

api-platform / core / 18089958695

29 Sep 2025 07:57AM UTC coverage: 21.569% (-0.2%) from 21.797%
18089958695

push

github

web-flow
fix(openapi): define items type for HydraCollectionBaseSchema hydra:member (#7419)

Co-authored-by: Thibaut Cholley <thibaut.cholley@elsie-sante.fr>

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

12063 existing lines in 401 files now uncovered.

11765 of 54545 relevant lines covered (21.57%)

12.57 hits per line

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

87.5
/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
    {
UNCOV
26
        $first = $last = $previous = $next = null;
6✔
27

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

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

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

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

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

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

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

UNCOV
70
        if (!$paginated && $appliedFilters) {
118✔
UNCOV
71
            return new PartialCollectionView($id);
113✔
72
        }
73

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

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

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