Widget::render()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 0
dl 0
loc 10
ccs 5
cts 5
cp 1
crap 3
rs 9.9332
c 0
b 0
f 0
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