Uri   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 59
rs 10
c 1
b 1
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFunctions() 0 8 1
A baseUrl() 0 12 4
A currentPath() 0 4 1
A currentUrl() 0 4 1
1
<?php
2
3
namespace Resilient\Twig\Extension;
4
5
use \Psr\Http\Message\UriInterface;
6
7
/**
8
* Twig Router Extension for psr 6  UriInterface
9
*/
10
class Uri extends \Twig_Extension
11
{
12
    private $uri;
13
14
    public function __construct(UriInterface $uri)
15
    {
16
        $this->uri = $uri;
17
    }
18
19
    public function getFunctions()
20
    {
21
        return [
22
            new \Twig_SimpleFunction('base_url', array($this, 'baseUrl')),
23
            new \Twig_SimpleFunction('current_path', array($this, 'currentPath')),
24
            new \Twig_SimpleFunction('current_url', array($this, 'currentUrl')),
25
        ];
26
    }
27
28
    /**
29
     * baseUrl function.
30
     *
31
     * @access public
32
     * @return string uri
33
     */
34
    public function baseUrl()
35
    {
36
        if (is_string($this->uri)) {
37
            return $this->uri;
38
        }
39
40
        $scheme = $this->uri->getScheme();
41
        $authority = $this->uri->getAuthority();
42
43
        return ($scheme ? $scheme . ':' : '')
44
            . ($authority ? '//' . $authority : '');
45
    }
46
47
    /**
48
     * currentPath function.
49
     *
50
     * @access public
51
     * @return string
52
     */
53
    public function currentPath()
54
    {
55
        return $this->uri->getPath();
56
    }
57
58
    /**
59
     * currentUrl function.
60
     *
61
     * @access public
62
     * @return string
63
     */
64
    public function currentUrl()
65
    {
66
        return (string) $this->uri;
67
    }
68
}
69