Completed
Push — master ( 81e1a1...0dbe46 )
by ARCANEDEV
30:13
created

SidebarComposer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 5
c 5
b 0
f 0
lcom 1
cbo 2
dl 0
loc 63
ccs 0
cts 19
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A compose() 0 12 3
A getSidebarItems() 0 4 1
1
<?php namespace Arcanesoft\Foundation\ViewComposers;
2
3
use Arcanesoft\Core\Helpers\Sidebar\Contracts\Sidebar;
4
use Illuminate\View\View;
5
6
/**
7
 * Class     SidebarComposer
8
 *
9
 * @package  Arcanesoft\Foundation\ViewComposers
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
class SidebarComposer
13
{
14
    /* ------------------------------------------------------------------------------------------------
15
     |  Properties
16
     | ------------------------------------------------------------------------------------------------
17
     */
18
    /**
19
     * The Sidebar Helper instance.
20
     *
21
     * @var \Arcanesoft\Core\Helpers\Sidebar\Contracts\Sidebar
22
     */
23
    protected $sidebar;
24
25
    /* ------------------------------------------------------------------------------------------------
26
     |  Constructor
27
     | ------------------------------------------------------------------------------------------------
28
     */
29
    /**
30
     * SidebarComposer constructor.
31
     *
32
     * @param  \Arcanesoft\Core\Helpers\Sidebar\Contracts\Sidebar  $sidebar
33
     */
34
    public function __construct(Sidebar $sidebar)
35
    {
36
        $this->sidebar = $sidebar;
37
    }
38
39
    /* ------------------------------------------------------------------------------------------------
40
     |  Main Functions
41
     | ------------------------------------------------------------------------------------------------
42
     */
43
    /**
44
     * Bind data to the view.
45
     *
46
     * @param  \Illuminate\View\View  $view
47
     */
48
    public function compose(View $view)
49
    {
50
        foreach ($this->getSidebarItems() as $sidebarKey) {
51
            if (config()->has($sidebarKey)) {
52
                $this->sidebar->add(config($sidebarKey));
53
            }
54
        }
55
56
        $this->sidebar->setCurrent(
57
            array_get($view->getData(), 'current_page', '')
58
        );
59
    }
60
61
    /* ------------------------------------------------------------------------------------------------
62
     |  Other Functions
63
     | ------------------------------------------------------------------------------------------------
64
     */
65
    /**
66
     * Get sidebar items.
67
     *
68
     * @return array
69
     */
70
    private function getSidebarItems()
71
    {
72
        return config('arcanesoft.foundation.sidebar.items', []);
73
    }
74
}
75