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

api-platform / core / 10010837821

19 Jul 2024 03:54PM UTC coverage: 64.225% (-0.5%) from 64.689%
10010837821

push

github

web-flow
chore: missing deprecations (#6480)

50 of 228 new or added lines in 14 files covered. (21.93%)

186 existing lines in 31 files now uncovered.

11549 of 17982 relevant lines covered (64.23%)

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

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

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

53
        return ['parts' => $parts, 'parameters' => $parameters];
172✔
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
    {
61
        if (null !== $page && null !== $pageParameterName) {
108✔
62
            $parameters[$pageParameterName] = $page;
28✔
63
        }
64

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

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

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

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

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

NEW
89
            $url .= $parts['host'];
×
90

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

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

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

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

106
        return $url;
108✔
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

© 2026 Coveralls, Inc