Widget   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 47
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1
ccs 9
cts 9
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
content() 0 1 ?
A authorize() 0 4 1
A notAuthorizedContent() 0 4 1
A render() 0 10 3
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