Url::getCompleteUrl()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 8
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 11
ccs 9
cts 9
cp 1
crap 3
rs 10
1
<?php
2
/**
3
 * Copyright (c) 2010–2019 Ryan Parman <http://ryanparman.com>.
4
 * Copyright (c) 2016–2019 Contributors.
5
 *
6
 * http://opensource.org/licenses/Apache2.0
7
 */
8
9
declare(strict_types=1);
10
11
namespace SimplePie\UtilityPack\Util;
12
13
use Psr\Http\Message\ServerRequestInterface as Request;
14
15
class Url
16
{
17
    /**
18
     * Gets the complete URL that was requested.
19
     *
20
     * @return string The complete URL that was requested.
21
     */
22 7
    public static function getCompleteUrl(Request $request): string
23
    {
24 7
        $uri = $request->getUri();
25
26 7
        return \sprintf(
27 7
            '%s://%s%s%s%s',
28 7
            $uri->getScheme(),
29 7
            $uri->getHost(),
30 7
            $uri->getPath(),
31 7
            ('' !== $uri->getQuery() ? '?' . $uri->getQuery() : ''),
32 7
            ('' !== $uri->getFragment() ? '#' . $uri->getFragment() : '')
33
        );
34
    }
35
}
36