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

RoutingHelper::handle()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
cc 3
eloc 5
nc 4
nop 2
crap 3
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