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

AbsoluteUrlGenerator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 26
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 18 3
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