BaseWidget   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 8
Bugs 0 Features 1
Metric Value
wmc 2
c 8
b 0
f 1
lcom 1
cbo 0
dl 0
loc 51
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 19 2
name() 0 1 ?
options() 0 1 ?
view() 0 1 ?
data() 0 1 ?
1
<?php namespace Modules\Dashboard\Foundation\Widgets;
2
3
abstract class BaseWidget
4
{
5
    /**
6
     * Boot the widget and add the data to the dashboard view composer
7
     */
8
    public function boot()
9
    {
10
        $widgetViewComposer = app('Modules\Dashboard\Composers\WidgetViewComposer');
11
        /** @var \Illuminate\Contracts\View\Factory $view */
12
        $view = app('Illuminate\Contracts\View\Factory');
13
14
        if ($view->exists($this->view())) {
15
            $html = $view->make($this->view())
16
                         ->with($this->data())
17
                         ->render();
18
19
            $sluggedName = str_slug($this->name());
20
21
            $widgetViewComposer
22
                ->setWidgetName($sluggedName)
23
                ->addSubView($sluggedName, $html)
24
                ->addWidgetOptions($sluggedName, $this->options());
25
        }
26
    }
27
28
    /**
29
     * Get the widget name
30
     * @return string
31
     */
32
    abstract protected function name();
33
34
    /**
35
     * Return an array of widget options
36
     * Possible options:
37
     *  x, y, width, height
38
     * @return array
39
     */
40
    abstract protected function options();
41
42
    /**
43
     * Get the widget view
44
     * @return string
45
     */
46
    abstract protected function view();
47
48
    /**
49
     * Get the widget data to send to the view
50
     * @return array
51
     */
52
    abstract protected function data();
53
}
54