Widget::content()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
ccs 0
cts 0
cp 0
c 0
b 0
f 0
nc 1
1
<?php
2
3
namespace Tequilarapido\SimpleWidget;
4
5
use Illuminate\View\View;
6
7
abstract class Widget implements WidgetInterface
8
{
9
    /**
10
     * Whether or not user is authorized to view widget content.
11
     *
12
     * Widget child is authorized by default.
13
     *
14
     * @return bool
15
     */
16 3
    public function authorize()
17
    {
18 3
        return true;
19
    }
20
21
    /**
22
     * String or content to display when the widget is not authorized.
23
     *
24
     * @return string
25
     */
26 1
    public function notAuthorizedContent()
27
    {
28 1
        return '<!-- Not authorized. -->';
29
    }
30
31
    /**
32
     * Method to echo out the widget result.
33
     *
34
     * @return mixed
35
     */
36 5
    public function render()
37
    {
38 5
        if (! $this->authorize()) {
39 1
            return $this->notAuthorizedContent();
40
        }
41
42 4
        $content = $this->content();
43
44 4
        return $content instanceof View ? $content->render() : $content;
45
    }
46
47
    /**
48
     * Generate widget content.
49
     *
50
     * @return mixed
51
     */
52
    abstract protected function content();
53
}
54