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

api-platform / core / 15133993414

20 May 2025 09:30AM UTC coverage: 26.313% (-1.2%) from 27.493%
15133993414

Pull #7161

github

web-flow
Merge e2c03d45f into 5459ba375
Pull Request #7161: fix(metadata): infer parameter string type from schema

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

11019 existing lines in 363 files now uncovered.

12898 of 49018 relevant lines covered (26.31%)

34.33 hits per line

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

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

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

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

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

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

UNCOV
65
        $query = http_build_query($parameters, '', '&', \PHP_QUERY_RFC3986);
265✔
UNCOV
66
        $parts['query'] = preg_replace('/%5B\d+%5D/', '%5B%5D', $query);
265✔
67

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

79
            if (isset($parts['user'])) {
9✔
80
                $url .= $parts['user'];
×
81

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

86
                $url .= '@';
×
87
            }
88

89
            $url .= $parts['host'];
9✔
90

91
            if (isset($parts['port'])) {
9✔
92
                $url .= ':'.$parts['port'];
×
93
            }
94
        }
95

UNCOV
96
        $url .= $parts['path'];
265✔
97

UNCOV
98
        if ('' !== $parts['query']) {
265✔
UNCOV
99
            $url .= '?'.$parts['query'];
235✔
100
        }
101

UNCOV
102
        if (isset($parts['fragment'])) {
265✔
103
            $url .= '#'.$parts['fragment'];
×
104
        }
105

UNCOV
106
        return $url;
265✔
107
    }
108
}
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