Breadcrumbs::clear()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php namespace Humweb\Breadcrumbs;
2
3
use Illuminate\Support\Collection;
4
use Illuminate\Support\Str;
5
6
class Breadcrumbs extends Collection
7
{
8
9
    /**
10
     * Add crumb to collection
11
     *
12
     * @param string $label label for link
13
     * @param string $url
14
     */
15
    public function add($label, $url = '')
16
    {
17
        $key = Str::slug($label);
18
        $this->put($key, ['label' => $label, 'url' => $url]);
19
20
        return $this;
21
    }
22
23
24
    /**
25
     * Clear all breadcrumbs
26
     *
27
     * @return Breadcrumb
28
     */
29
    public function clear()
30
    {
31
        $this->items = array();
32
33
        return $this;
34
    }
35
36
37
    /**
38
     * Render breadcrumbs
39
     *
40
     * @param  string $presenter
41
     *
42
     * @return string
43
     */
44
    public function render($presenter = null)
45
    {
46
        $presenter = strtolower($presenter);
47
48
        if (strtolower($presenter) === 'foundation') {
49
            $presenter = new FoundationPresenter($this);
50
        } elseif (strtolower($presenter) === 'bs4') {
51
            $presenter = new Bootstrap4Presenter($this);
52
        } else {
53
            $presenter = new Presenter($this);
54
        }
55
56
        return $presenter->render();
57
    }
58
}
59