Completed
Push — develop ( fd06a1...77abd3 )
by Jens
07:05
created

RoutingHelper   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 94.12%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 10
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 35
ccs 16
cts 17
cp 0.9412
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B handle() 0 13 5
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 = strtolower($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
        switch ($this->type) {
26 4
            case 'path':
27 2
                return $this->getPath($context, $options, $relative);
28 2
            case 'url':
29 2
                return $this->getUrl($context, $options, $relative);
30
            default:
31
                throw new \InvalidArgumentException();
32
        }
33
    }
34
35 2
    private function getPath($name, $parameters = array(), $relative = false)
36
    {
37 2
        return $this->generator->generate($name, $parameters, $relative ? UrlGeneratorInterface::RELATIVE_PATH : UrlGeneratorInterface::ABSOLUTE_PATH);
38
    }
39
40 2
    private function getUrl($name, $parameters = array(), $schemeRelative = false)
41
    {
42 2
        return $this->generator->generate($name, $parameters, $schemeRelative ? UrlGeneratorInterface::NETWORK_PATH : UrlGeneratorInterface::ABSOLUTE_URL);
43
    }
44
}
45