Completed
Pull Request — master (#1281)
by
unknown
02:32
created

Navbar::right()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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