Completed
Push — master ( 68c2b9...8b636a )
by Alex
02:24
created

AbsoluteUrlGenerator::__invoke()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 10
nc 3
nop 1
1
<?php
2
3
namespace AlexMasterov\TwigExtension;
4
5
use Psr\Http\Message\UriInterface;
6
7
final class AbsoluteUrlGenerator
8
{
9
    /**
10
     * @param UriInterface $uri
11
     *
12
     * @return string
13
     */
14
    public function __invoke(UriInterface $uri)
15
    {
16
        $host = $uri->getHost();
17
        $path = $uri->getPath();
18
19
        if (empty($host)) {
20
            return $path;
21
        }
22
23
        $port = $uri->getPort();
24
        if (!empty($port)) {
25
            $host .= ":{$port}";
26
        }
27
28
        $scheme = $uri->getScheme();
29
30
        return "{$scheme}://{$host}{$path}";
31
    }
32
}
33