Completed
Push — develop ( 49d173...fd06a1 )
by Jens
08:27
created

RoutingHelper   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 29
ccs 13
cts 13
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 7 3
A getPath() 0 4 2
A getUrl() 0 4 2
1
<?php
2
/**
3
 * @author @jayS-de <[email protected]>
4
 */
5
6
namespace JaySDe\HandlebarsBundle\Helper;
7
8
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
9
10
class RoutingHelper implements HelperInterface
11
{
12
    private $generator;
13
    private $type;
14
15 4
    public function __construct(UrlGeneratorInterface $generator, $type)
16
    {
17 4
        $this->generator = $generator;
18 4
        $this->type = $type;
19 4
    }
20
    
21 4
    public function handle($context, $options)
22
    {
23 4
        $options = isset($options['hash']) ? $options['hash'] : [];
24 4
        $relative = isset($options['relative']) ? $options['relative'] : false;
25 4
        $method = 'get' . ucfirst($this->type);
26 4
        return $this->$method($context, $options, $relative);
27
    }
28
29 2
    private function getPath($name, $parameters = array(), $relative = false)
30
    {
31 2
        return $this->generator->generate($name, $parameters, $relative ? UrlGeneratorInterface::RELATIVE_PATH : UrlGeneratorInterface::ABSOLUTE_PATH);
32
    }
33
34 2
    private function getUrl($name, $parameters = array(), $schemeRelative = false)
35
    {
36 2
        return $this->generator->generate($name, $parameters, $schemeRelative ? UrlGeneratorInterface::NETWORK_PATH : UrlGeneratorInterface::ABSOLUTE_URL);
37
    }
38
}
39