BlazeRuntime::blaze()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 0
cts 13
cp 0
rs 9.7666
c 0
b 0
f 0
cc 3
nc 4
nop 3
crap 12
1
<?php
2
3
namespace Happyr\BlazeBundle\Twig;
4
5
use Happyr\BlazeBundle\Service\BlazeManagerInterface;
6
use Twig\Extension\RuntimeExtensionInterface;
7
8
/**
9
 * @author Tobias Nyholm <[email protected]>
10
 */
11
class BlazeRuntime implements RuntimeExtensionInterface
12
{
13
    /**
14
     * @var BlazeManagerInterface blaze
15
     */
16
    protected $blaze;
17
18
    /**
19
     * @param BlazeManagerInterface $blaze
20
     */
21
    public function __construct(BlazeManagerInterface $blaze)
22
    {
23
        $this->blaze = $blaze;
24
    }
25
26
    /**
27
     * Call the blaze service.
28
     *
29
     * @param mixed  $object
30
     * @param string $action
31
     * @param bool   $absolute
32
     *
33
     * @return string
34
     */
35
    public function blaze($object, $action, $absolute = false)
36
    {
37
        $compObjects = [];
38
39
        if (is_array($object)) {
40
            $compObjects = $object;
41
            $object = array_shift($compObjects);
42
        }
43
44
        if ($absolute) {
45
            return $this->blaze->getUrl($object, $action, $compObjects);
46
        } else {
47
            return $this->blaze->getPath($object, $action, $compObjects);
48
        }
49
    }
50
}
51