Completed
Push — master ( 6ed074...69a7c6 )
by Song
02:23
created

Navbar::render()   B

Complexity

Conditions 6
Paths 3

Size

Total Lines 22

Duplication

Lines 11
Ratio 50 %

Importance

Changes 0
Metric Value
cc 6
nc 3
nop 1
dl 11
loc 22
rs 8.9457
c 0
b 0
f 0
1
<?php
2
3
namespace Encore\Admin\Widgets;
4
5
use Encore\Admin\Widgets\Navbar\RefreshButton;
6
use Illuminate\Contracts\Support\Htmlable;
7
use Illuminate\Contracts\Support\Renderable;
8
9
class Navbar implements Renderable
10
{
11
    /**
12
     * @var array
13
     */
14
    protected $elements = [];
15
16
    /**
17
     * Navbar constructor.
18
     */
19
    public function __construct()
20
    {
21
        $this->elements = [
22
            'left'  => collect(),
23
            'right' => collect(),
24
        ];
25
    }
26
27
    /**
28
     * @param $element
29
     *
30
     * @return $this
31
     */
32
    public function left($element)
33
    {
34
        $this->elements['left']->push($element);
35
36
        return $this;
37
    }
38
39
    /**
40
     * @param $element
41
     *
42
     * @return $this
43
     */
44
    public function right($element)
45
    {
46
        $this->elements['right']->push($element);
47
48
        return $this;
49
    }
50
51
    /**
52
     * @param $element
53
     *
54
     * @return Navbar
55
     *
56
     * @deprecated
57
     */
58
    public function add($element)
59
    {
60
        return $this->right($element);
61
    }
62
63
    /**
64
     * @param string $part
65
     *
66
     * @return mixed
67
     */
68
    public function render($part = 'right')
69
    {
70
        if (!isset($this->elements[$part]) || $this->elements[$part]->isEmpty()) {
71
            return '';
72
        }
73
74
        if ($part == 'right') {
75
            $this->right(new RefreshButton());
76
        }
77
78 View Code Duplication
        return $this->elements[$part]->map(function ($element) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
79
            if ($element instanceof Htmlable) {
80
                return $element->toHtml();
81
            }
82
83
            if ($element instanceof Renderable) {
84
                return $element->render();
85
            }
86
87
            return (string) $element;
88
        })->implode('');
89
    }
90
}
91