Completed
Push — master ( 7e75f8...53d3fb )
by Ryan
10:44 queued 05:05
created

ControlPanelBuilder::addNavigation()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 3
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php namespace Anomaly\Streams\Platform\Ui\ControlPanel;
2
3
use Anomaly\Streams\Platform\Ui\ControlPanel\Command\BuildControlPanel;
4
use Anomaly\Streams\Platform\Ui\ControlPanel\Component\Button\ButtonHandler;
5
use Anomaly\Streams\Platform\Ui\ControlPanel\Component\Navigation\NavigationHandler;
6
use Anomaly\Streams\Platform\Ui\ControlPanel\Component\Section\SectionHandler;
7
use Illuminate\Foundation\Bus\DispatchesJobs;
8
9
/**
10
 * Class ControlPanelBuilder
11
 *
12
 * @link   http://pyrocms.com/
13
 * @author PyroCMS, Inc. <[email protected]>
14
 * @author Ryan Thompson <[email protected]>
15
 */
16
class ControlPanelBuilder
17
{
18
19
    use DispatchesJobs;
20
21
    /**
22
     * The section buttons.
23
     *
24
     * @var array
25
     */
26
    protected $buttons = ButtonHandler::class;
27
28
    /**
29
     * The module sections.
30
     *
31
     * @var array
32
     */
33
    protected $sections = SectionHandler::class;
34
35
    /**
36
     * The navigation links.
37
     *
38
     * @var array
39
     */
40
    protected $navigation = NavigationHandler::class;
41
42
    /**
43
     * The control_panel object.
44
     *
45
     * @var ControlPanel
46
     */
47
    protected $controlPanel;
48
49
    /**
50
     * Create a new ControlPanelBuilder instance.
51
     *
52
     * @param ControlPanel $controlPanel
53
     */
54
    public function __construct(ControlPanel $controlPanel)
55
    {
56
        $this->controlPanel = $controlPanel;
57
    }
58
59
    /**
60
     * Build the control_panel.
61
     */
62
    public function build()
63
    {
64
        $this->dispatch(new BuildControlPanel($this));
65
66
        return $this->controlPanel;
67
    }
68
69
    /**
70
     * Get the control_panel.
71
     *
72
     * @return ControlPanel
73
     */
74
    public function getControlPanel()
75
    {
76
        return $this->controlPanel;
77
    }
78
79
    /**
80
     * Get the section buttons.
81
     *
82
     * @return array
83
     */
84
    public function getButtons()
85
    {
86
        return $this->buttons;
87
    }
88
89
    /**
90
     * Set the section buttons.
91
     *
92
     * @param array $buttons
93
     */
94
    public function setButtons($buttons)
95
    {
96
        $this->buttons = $buttons;
97
    }
98
99
    /**
100
     * Get the module sections.
101
     *
102
     * @return array
103
     */
104
    public function getSections()
105
    {
106
        return $this->sections;
107
    }
108
109
    /**
110
     * Set the sections.
111
     *
112
     * @param array $sections
113
     * @return $this
114
     */
115
    public function setSections($sections)
116
    {
117
        $this->sections = $sections;
118
119
        return $this;
120
    }
121
122
    /**
123
     * Get the module navigation.
124
     *
125
     * @return array
126
     */
127
    public function getNavigation()
128
    {
129
        return $this->navigation;
130
    }
131
132
    /**
133
     * Set the navigation.
134
     *
135
     * @param array $navigation
136
     * @return $this
137
     */
138
    public function setNavigation($navigation)
139
    {
140
        $this->navigation = $navigation;
141
142
        return $this;
143
    }
144
145
    /**
146
     * Add a navigation.
147
     *
148
     * @param        $slug
149
     * @param  array $navigation
150
     * @param null   $position
151
     * @return $this
152
     */
153 View Code Duplication
    public function addNavigation($slug, array $navigation, $position = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
154
    {
155
        if ($position === null) {
156
            $position = count($this->navigation) + 1;
157
        }
158
159
        $front = array_slice($this->navigation, 0, $position, true);
160
        $back  = array_slice($this->navigation, $position, count($this->navigation) - $position, true);
161
162
        $this->navigation = $front + [$slug => $navigation] + $back;
163
164
        return $this;
165
    }
166
167
    /**
168
     * Return the active control panel section.
169
     *
170
     * @return Component\Section\Contract\SectionInterface|null
171
     */
172
    public function getControlPanelActiveSection()
173
    {
174
        $sections = $this->getControlPanelSections();
175
176
        return $sections->active();
177
    }
178
179
    /**
180
     * Get the control panel sections.
181
     *
182
     * @return Component\Section\SectionCollection
183
     */
184
    public function getControlPanelSections()
185
    {
186
        return $this->controlPanel->getSections();
187
    }
188
189
    /**
190
     * Get the control panel navigation.
191
     *
192
     * @return Component\Navigation\NavigationCollection
193
     */
194
    public function getControlPanelNavigation()
195
    {
196
        return $this->controlPanel->getNavigation();
197
    }
198
}
199