HtmlBuilder::warning()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 2
dl 12
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Services\Html;
4
5
use Form;
6
use Session;
7
use App\Services\Auth\User;
8
use Collective\Html\HtmlBuilder as BaseHtmlBuilder;
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}')",
0 ignored issues
show
Documentation introduced by
The property avatar does not exist on object<App\Services\Auth\User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
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--delete-row',
90
            ]
91
        ).el('span.fa.fa-trash').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