Completed
Pull Request — master (#33)
by
unknown
33:52 queued 30:06
created

LayoutManager::initStaticPart()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 19
ccs 13
cts 13
cp 1
rs 9.9332
cc 3
nc 3
nop 1
crap 3
1
<?php namespace Distilleries\Expendable\Layouts;
2
3
use Closure;
4
use Distilleries\Expendable\Contracts\LayoutManagerContract;
5
use Distilleries\Expendable\Contracts\StateDisplayerContract;
6
use Illuminate\Contracts\View\Factory;
7
use Illuminate\Filesystem\Filesystem;
8
9
class LayoutManager implements LayoutManagerContract {
10
11
12
    protected $config;
13
    protected $view;
14
    protected $state;
15
    protected $filesystem;
16
    protected $items = [];
17
    protected $layout = null;
18
19 150
    public function __construct(array $config, Factory $view, Filesystem $filesystem, StateDisplayerContract $state)
20
    {
21 150
        $this->config     = $config;
22 150
        $this->view       = $view;
23 150
        $this->filesystem = $filesystem;
24 150
        $this->state      = $state;
25
    }
26
27
28 150
    public function setupLayout($layout)
29
    {
30 150
        $this->layout = $layout;
31
    }
32
33 150
    public function initInterfaces(array $interfaces, $class)
34
    {
35
36 150
        foreach ($interfaces as $interface)
37
        {
38 120
            if (strpos($interface, 'StateContract') !== false)
39
            {
40 120
                $this->state->setState($interface);
41
            }
42
        }
43
44 150
        $this->state->setClass($class);
0 ignored issues
show
Bug introduced by
The method setClass() does not exist on Distilleries\Expendable\...\StateDisplayerContract. Since it exists in all sub-types, consider adding an abstract or default implementation to Distilleries\Expendable\...\StateDisplayerContract. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
        $this->state->/** @scrutinizer ignore-call */ setClass($class);
Loading history...
45
    }
46
47 150
    public function initStaticPart(Closure $closure = null)
48
    {
49 150
        if (!is_null($this->layout))
50
        {
51 150
            $header = $this->view->make('expendable::admin.part.header')->with([
52 75
                'title'   => ''
53 75
            ]);
54 150
            $footer = $this->view->make('expendable::admin.part.footer')->with([
55 75
                'title'   => ''
56 75
            ]);
57
58 150
            $this->add([
59 150
                'header' => $header,
60 150
                'footer' => $footer,
61
            ]);
62
63 150
            if (!empty($closure))
64
            {
65 120
                $closure($this);
66
            }
67
68
        }
69
    }
70
71 150
    public function add(array $items)
72
    {
73 150
        $this->items = array_merge($this->items, $items);
74
    }
75
76 46
    public function render()
77
    {
78 46
        return $this->view->make($this->layout, $this->items);
79
    }
80
81
    /**
82
     * @return array
83
     */
84
    public function getConfig()
85
    {
86
        return $this->config;
87
    }
88
89
    /**
90
     * @return Factory
91
     */
92 120
    public function getView()
93
    {
94 120
        return $this->view;
95
    }
96
97
    /**
98
     * @return StateDisplayerContract
99
     */
100 120
    public function getState()
101
    {
102 120
        return $this->state;
103
    }
104
105
    /**
106
     * @return Filesystem
107
     */
108
    public function getFilesystem()
109
    {
110
        return $this->filesystem;
111
    }
112
113
114
}