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

api-platform / core / 18343625207

08 Oct 2025 11:48AM UTC coverage: 24.542% (-0.02%) from 24.561%
18343625207

push

github

web-flow
fix(state): object mapper on delete operation (#7447)

fixes #7434

1 of 49 new or added lines in 2 files covered. (2.04%)

7084 existing lines in 207 files now uncovered.

14004 of 57061 relevant lines covered (24.54%)

26.01 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;
12✔
27

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

UNCOV
33
        if (1. !== $currentPage) {
12✔
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)) {
12✔
UNCOV
38
            $next = IriHelper::createIri($parsed['parts'], $parsed['parameters'], $pageParameterName, $currentPage + 1., $urlGenerationStrategy);
12✔
39
        }
40

UNCOV
41
        return [
12✔
UNCOV
42
            'first' => $first,
12✔
UNCOV
43
            'last' => $last,
12✔
UNCOV
44
            'previous' => $previous,
12✔
UNCOV
45
            'next' => $next,
12✔
UNCOV
46
        ];
12✔
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;
238✔
UNCOV
52
        $paginated = false;
238✔
UNCOV
53
        if ($object instanceof PartialPaginatorInterface) {
238✔
UNCOV
54
            $paginated = true;
214✔
UNCOV
55
            if ($object instanceof PaginatorInterface) {
214✔
UNCOV
56
                $paginated = 1. !== $lastPage = $object->getLastPage();
214✔
57
            } else {
58
                $itemsPerPage = $object->getItemsPerPage();
×
59
                $pageTotalItems = (float) \count($object);
×
60
            }
UNCOV
61
            $currentPage = $object->getCurrentPage();
214✔
62
        }
63

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

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

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

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

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

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