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

api-platform / core / 18060089452

27 Sep 2025 12:57PM UTC coverage: 0.0% (-21.8%) from 21.793%
18060089452

Pull #7397

github

web-flow
Merge 479f46b8d into abe0438be
Pull Request #7397: fix(jsonschema/jsonld): make `@id` and `@type` properties required only in the JSON-LD schema for output

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

11967 existing lines in 393 files now uncovered.

0 of 53914 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/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
    {
UNCOV
40
        $parts = parse_url($iri);
×
UNCOV
41
        if (false === $parts) {
×
42
            throw new InvalidArgumentException(\sprintf('The request URI "%s" is malformed.', $iri));
×
43
        }
44

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

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

UNCOV
53
        return ['parts' => $parts, 'parameters' => $parameters];
×
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
    {
UNCOV
63
        if (null !== $page && null !== $pageParameterName) {
×
UNCOV
64
            $parameters[$pageParameterName] = $page;
×
65
        }
66

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

UNCOV
70
        $url = '';
×
UNCOV
71
        if ((UrlGeneratorInterface::ABS_URL === $urlGenerationStrategy || UrlGeneratorInterface::NET_PATH === $urlGenerationStrategy) && isset($parts['host'])) {
×
72
            if (isset($parts['scheme'])) {
×
73
                $scheme = $parts['scheme'];
×
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

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

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

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

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

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

UNCOV
98
        $url .= $parts['path'];
×
99

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

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

UNCOV
108
        return $url;
×
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

© 2025 Coveralls, Inc