Completed
Push — develop ( fd2db3...d57094 )
by Jens
03:05
created

RoutingHelper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 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
    public function __construct(UrlGeneratorInterface $generator, $type)
16
    {
17
        $this->generator = $generator;
18
        $this->type = $type;
19
    }
20
    
21
    public function handle($context, $options)
22
    {
23
        $options = isset($options['hash']) ? $options['hash'] : [];
24
        $method = 'get' . ucfirst($this->type);
25
        return $this->$method($context, $options);
26
    }
27
28
    private function getPath($name, $parameters = array(), $relative = false)
29
    {
30
        return $this->generator->generate($name, $parameters, $relative ? UrlGeneratorInterface::RELATIVE_PATH : UrlGeneratorInterface::ABSOLUTE_PATH);
31
    }
32
33
    private function getUrl($name, $parameters = array(), $schemeRelative = false)
34
    {
35
        return $this->generator->generate($name, $parameters, $schemeRelative ? UrlGeneratorInterface::NETWORK_PATH : UrlGeneratorInterface::ABSOLUTE_URL);
36
    }
37
}
38