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

api-platform / core / 14635100171

24 Apr 2025 06:39AM UTC coverage: 8.271% (+0.02%) from 8.252%
14635100171

Pull #6904

github

web-flow
Merge c9cefd82e into a3e5e53ea
Pull Request #6904: feat(graphql): added support for graphql subscriptions to work for actions

0 of 73 new or added lines in 3 files covered. (0.0%)

1999 existing lines in 144 files now uncovered.

13129 of 158728 relevant lines covered (8.27%)

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

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

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

53
        return ['parts' => $parts, 'parameters' => $parameters];
455✔
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) {
364✔
62
            $parameters[$pageParameterName] = $page;
89✔
63
        }
64

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

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

UNCOV
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

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

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

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

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

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

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