Completed
Push — master ( a19a47...15bbc5 )
by Arjay
15:59
created

CategoryPresenter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 55
rs 10
c 2
b 0
f 0
wmc 5
lcom 1
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A indentedTitle() 0 4 1
A slug() 0 4 1
A alias() 0 9 1
A slugList() 0 11 2
1
<?php
2
3
namespace Yajra\CMS\Presenters;
4
5
use Illuminate\Support\HtmlString;
6
use Illuminate\Support\Str;
7
use Laracasts\Presenter\Presenter;
8
use Yajra\CMS\Entities\Category;
9
10
class CategoryPresenter extends Presenter
11
{
12
    /**
13
     * Indented title against depth.
14
     *
15
     * @param int $pad
16
     * @return string
17
     */
18
    public function indentedTitle($pad = 1)
19
    {
20
        return str_repeat('— ', $this->entity->depth - $pad) . $this->entity->title;
21
    }
22
23
    /**
24
     * Category's slug.
25
     *
26
     * @return string
27
     */
28
    public function slug()
29
    {
30
        return $this->alias();
31
    }
32
33
    /**
34
     * Get the nested alias on the category.
35
     *
36
     * @return string
37
     */
38
    public function alias()
39
    {
40
        $alias = [];
41
        $this->entity->getAncestorsAndSelfWithoutRoot()->each(function (Category $cat) use (&$alias) {
42
            $alias[] = $cat->alias;
43
        });
44
45
        return implode('/', $alias);
46
    }
47
48
    /**
49
     * Display nested categories of the article.
50
     *
51
     * @return \Illuminate\Support\HtmlString
52
     */
53
    public function slugList()
54
    {
55
        $categories = explode('/', $this->alias());
56
        $html       = [];
57
58
        foreach ($categories as $category) {
59
            $html[] = new HtmlString('<span class="label label-info">' . e(Str::title($category)) . '</span>&nbsp;');
60
        }
61
62
        return new HtmlString(implode('', $html));
63
    }
64
}
65