BreadcrumbsManager::initNewTrail()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace ByTIC\Navigation\Breadcrumbs;
4
5
use Nip\Utility\Traits\SingletonTrait;
6
7
/**
8
 * Class BreadcrumbsManager
9
 * @package ByTIC\Navigation\Breadcrumbs
10
 */
11
class BreadcrumbsManager
12
{
13
    use SingletonTrait;
14
15
    const DEFAULT_NAMESPACE = "default";
16
17
    /**
18
     * @var Trail[]
19
     */
20
    protected $trails = [];
21
22
    /**
23
     * BreadcrumbsManager constructor.
24
     */
25 1
    public function __construct()
26
    {
27 1
        $this->checkNewTrail(self::DEFAULT_NAMESPACE);
28 1
    }
29
30
    /**
31
     * @param string $name
32
     * @return mixed
33
     */
34 1
    public function trail($name = self::DEFAULT_NAMESPACE)
35
    {
36 1
        $this->checkNewTrail($name);
37 1
        return $this->trails[$name];
38
    }
39
40
    /**
41
     * @param string $name
42
     */
43 1
    protected function checkNewTrail($name)
44
    {
45 1
        if (!isset($this->trails[$name])) {
46 1
            $this->initNewTrail($name);
47
        }
48 1
    }
49
50
    /**
51
     * @param string $name
52
     */
53 1
    protected function initNewTrail($name)
54
    {
55 1
        $this->trails[$name] = $this->generateNewTrail();
56 1
    }
57
58
    /**
59
     * @return Trail
60
     */
61 1
    protected function generateNewTrail()
62
    {
63 1
        return new Trail();
64
    }
65
}