Completed
Pull Request — master (#87)
by Sebastian
18:02 queued 13:56
created

HtmlBuilder::backToIndex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Services\Html;
4
5
use App\Services\Auth\User;
6
use Collective\Html\HtmlBuilder as BaseHtmlBuilder;
7
use Form;
8
use Session;
9
10
class HtmlBuilder extends BaseHtmlBuilder
11
{
12
    public function flashMessage(): string
13
    {
14
        if (! Session::has('flash_notification.message')) {
15
            return '';
16
        }
17
18
        $level = Session::get('flash_notification.level');
19
20
        return el("div.alert.-{$level}", Session::get('flash_notification.message'));
21
    }
22
23
    public function error($message, $name = ''): string
24
    {
25
        if (empty($message) && empty($name)) {
26
            return '';
27
        }
28
29
        $attributes = empty($name) ? [] : ['data-validation-error' => $name];
30
31
        return el(
32
            'div.alert.-danger',
33
            $attributes,
34
            $message
35
        );
36
    }
37
38
    public function message($message, string $classes = ''): string
39
    {
40
        if (empty($message)) {
41
            return '';
42
        }
43
44
        return el('div.alert.-success', ['class' => $classes], $message);
45
    }
46
47 View Code Duplication
    public function info($message, string $classes = ''): string
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
    {
49
        if (empty($message)) {
50
            return '';
51
        }
52
53
        return el(
54
            'div.alert.-info',
55
            ['class' => $classes],
56
            el('span.fa.fa-info-circle').' '.$message
57
        );
58
    }
59
60 View Code Duplication
    public function warning($message, string $classes = ''): string
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
    {
62
        if (empty($message)) {
63
            return '';
64
        }
65
66
        return el(
67
            'div.alert.-warning',
68
            ['class' => $classes],
69
            el('span.fa.fa-exclamation-triangle').' '.$message
70
        );
71
    }
72
73
    public function avatar(User $user, string $classes = ''): string
74
    {
75
        return el('span.avatar', [
76
            'class' => $classes,
77
            'style' => "background-image: url('{$user->avatar}')",
78
        ], '');
79
    }
80
81
    public function deleteButton(string $url): string
82
    {
83
        return Form::openButton(
84
            [
85
                'url' => $url,
86
                'method' => 'delete',
87
            ],
88
            [
89
                'class' => 'button -danger -small',
90
            ]
91
        ).el('span.fa.fa-remove').Form::closeButton();
92
    }
93
94
    public function onlineIndicator(bool $online): string
95
    {
96
        $state = $online ? 'on' : 'off';
97
        $icon = $online ? 'circle' : 'circle-o';
98
        $title = $online ? 'Online' : 'Offline';
99
100
        return el(
101
            "span.status.-{$state}",
102
            ['title' => $title],
103
            el("i.fa.fa-{$icon}")
104
        );
105
    }
106
107
    public function backToIndex(string $action, array $parameters = []): string
108
    {
109
        return el('a.breadcrumb--back', ['href' => action($action, $parameters)], fragment('back.backToIndex'));
110
    }
111
}
112