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

api-platform / core / 18089937549

29 Sep 2025 07:56AM UTC coverage: 21.764% (-0.3%) from 22.093%
18089937549

Pull #7416

github

web-flow
Merge 061bcc790 into abe0438be
Pull Request #7416: fix(laravel): serializer attributes on Eloquent methods

0 of 151 new or added lines in 11 files covered. (0.0%)

5028 existing lines in 173 files now uncovered.

11889 of 54626 relevant lines covered (21.76%)

25.32 hits per line

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

51.43
/src/Metadata/Util/IriHelper.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\Metadata\Util;
15

16
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
17
use ApiPlatform\Metadata\UrlGeneratorInterface;
18
use ApiPlatform\State\Util\RequestParser;
19

20
/**
21
 * Parses and creates IRIs.
22
 *
23
 * @author Kévin Dunglas <dunglas@gmail.com>
24
 *
25
 * @internal
26
 */
27
final class IriHelper
28
{
29
    private function __construct()
30
    {
31
    }
×
32

33
    /**
34
     * Parses and standardizes the request IRI.
35
     *
36
     * @throws InvalidArgumentException
37
     */
38
    public static function parseIri(string $iri, string $pageParameterName): array
39
    {
40
        $parts = parse_url($iri);
294✔
41
        if (false === $parts) {
294✔
42
            throw new InvalidArgumentException(\sprintf('The request URI "%s" is malformed.', $iri));
×
43
        }
44

45
        $parameters = [];
294✔
46
        if (isset($parts['query'])) {
294✔
47
            $parameters = RequestParser::parseRequestParams($parts['query']);
236✔
48

49
            // Remove existing page parameter
50
            unset($parameters[$pageParameterName]);
236✔
51
        }
52

53
        return ['parts' => $parts, 'parameters' => $parameters];
294✔
54
    }
55

56
    /**
57
     * Gets a collection IRI for the given parameters.
58
     *
59
     * @param int $urlGenerationStrategy
60
     */
61
    public static function createIri(array $parts, array $parameters, ?string $pageParameterName = null, ?float $page = null, $urlGenerationStrategy = UrlGeneratorInterface::ABS_PATH): string
62
    {
63
        if (null !== $page && null !== $pageParameterName) {
256✔
64
            $parameters[$pageParameterName] = $page;
12✔
65
        }
66

67
        $query = http_build_query($parameters, '', '&', \PHP_QUERY_RFC3986);
256✔
68
        $parts['query'] = preg_replace('/%5B\d+%5D/', '%5B%5D', $query);
256✔
69

70
        $url = '';
256✔
71
        if ((UrlGeneratorInterface::ABS_URL === $urlGenerationStrategy || UrlGeneratorInterface::NET_PATH === $urlGenerationStrategy) && isset($parts['host'])) {
256✔
72
            if (isset($parts['scheme'])) {
×
73
                $scheme = $parts['scheme'];
×
UNCOV
74
            } elseif (isset($parts['port']) && 443 === $parts['port']) {
×
75
                $scheme = 'https';
×
76
            } else {
77
                $scheme = 'http';
×
78
            }
79
            $url .= UrlGeneratorInterface::NET_PATH === $urlGenerationStrategy ? '//' : "$scheme://";
×
80

UNCOV
81
            if (isset($parts['user'])) {
×
82
                $url .= $parts['user'];
×
83

UNCOV
84
                if (isset($parts['pass'])) {
×
UNCOV
85
                    $url .= ':'.$parts['pass'];
×
86
                }
87

UNCOV
88
                $url .= '@';
×
89
            }
90

91
            $url .= $parts['host'];
×
92

UNCOV
93
            if (isset($parts['port'])) {
×
UNCOV
94
                $url .= ':'.$parts['port'];
×
95
            }
96
        }
97

98
        $url .= $parts['path'];
256✔
99

100
        if ('' !== $parts['query']) {
256✔
101
            $url .= '?'.$parts['query'];
236✔
102
        }
103

104
        if (isset($parts['fragment'])) {
256✔
UNCOV
105
            $url .= '#'.$parts['fragment'];
×
106
        }
107

108
        return $url;
256✔
109
    }
110
}
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