BreadcrumbsExtension   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 45
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getFunctions() 0 6 1
A breadcrumbs() 0 8 1
1
<?php
2
3
namespace BreadcrumbsBundle\Twig;
4
5
use BreadcrumbsBundle\Service\BreadcrumbsService;
6
use Symfony\Component\Templating\EngineInterface;
7
8
/**
9
 * Class BreadcrumbsExtension
10
 * @package BreadcrumbsBundle\Twig
11
 */
12
class BreadcrumbsExtension extends \Twig_Extension
13
{
14
    /**
15
     * @var BreadcrumbsService
16
     */
17
    protected $service;
18
19
    /**
20
     * @var EngineInterface
21
     */
22
    protected $engine;
23
24
    /**
25
     * BreadcrumbsExtension constructor.
26
     * @param BreadcrumbsService $service
27
     * @param EngineInterface $engine
28
     */
29
    public function __construct(BreadcrumbsService $service, EngineInterface $engine)
30
    {
31
        $this->service = $service;
32
        $this->engine = $engine;
33
    }
34
35
    /**
36
     * @return array
37
     */
38
    public function getFunctions(): array
39
    {
40
        return [
41
            new \Twig_SimpleFunction('breadcrumbs', [$this, 'breadcrumbs'], ['is_safe' => ['html']]),
42
        ];
43
    }
44
45
    /**
46
     * @return string
47
     */
48
    public function breadcrumbs(): string
49
    {
50
        return $this->engine->render($this->service->getTemplate(), [
51
            'separator' => $this->service->getSeparator(),
52
            'list' => $this->service->getList(),
53
            'breadcrumbs' => $this->service->getBreadcrumbs()
54
        ]);
55
    }
56
}