BreadcrumbsRenderer   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Test Coverage

Coverage 96%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 77
ccs 24
cts 25
cp 0.96
rs 10
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getView() 0 6 2
A render() 0 4 1
A __construct() 0 3 1
A renderView() 0 5 1
A detectViewPath() 0 6 2
A setView() 0 4 1
A initView() 0 3 1
1
<?php
2
3
namespace ByTIC\Navigation\Breadcrumbs;
4
5
use ByTIC\Navigation\Utility\NavigationHelper;
6
use Nip\View\View;
7
8
/**
9
 * Class BreadcrumbsRenderer
10
 * @package ByTIC\Navigation\Breadcrumbs
11
 */
12
class BreadcrumbsRenderer
13
{
14
    /**
15
     * The breadcrumb trail.
16
     *
17
     * @var Breadcrumbs
18
     */
19
    protected $breadcrumbs;
20
21
    /**
22
     * @var View
23
     */
24
    protected $view = null;
25
26
    /**
27
     * BreadcrumbsRenderer constructor.
28
     * @param Breadcrumbs $breadcrumbs
29
     */
30 1
    public function __construct(Breadcrumbs $breadcrumbs)
31
    {
32 1
        $this->breadcrumbs = $breadcrumbs;
33 1
    }
34
35
    /**
36
     * @return string
37
     */
38 1
    public function render()
39
    {
40 1
        $path = $this->detectViewPath();
41 1
        return $this->renderView($path);
42
    }
43
44
    /**
45
     * @param $path
46
     * @return string
47
     */
48 1
    protected function renderView($path)
49
    {
50 1
        $view = $this->getView();
51 1
        $view->set('breadcrumbs', $this->breadcrumbs);
52 1
        return $view->load($path, ['breadcrumbs' => $this->breadcrumbs], true);
53
    }
54
55
    /**
56
     * @return View
57
     */
58 1
    public function getView(): View
59
    {
60 1
        if ($this->view === null) {
61 1
            $this->initView();
62
        }
63 1
        return $this->view;
64
    }
65
66
    /**
67
     * @param View $view
68
     */
69 1
    public function setView(View $view): void
70
    {
71 1
        $view->addPath(NavigationHelper::view('/breadcrumbs'), 'breadcrumbs');
72 1
        $this->view = $view;
73 1
    }
74
75 1
    protected function initView()
76
    {
77 1
        $this->setView(new View());
78 1
    }
79
80
    /**
81
     * @return string
82
     */
83 1
    protected function detectViewPath()
84
    {
85 1
        if ($this->getView()->existPath('breadcrumbs')) {
86
            return 'breadcrumbs';
87
        }
88 1
        return 'breadcrumbs::bootstrap4';
89
    }
90
91
}