Button::getMetadata()   A
last analyzed

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 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Formularium\Frontend\Materialize\Element;
4
5
use Formularium\Element;
6
use Formularium\HTMLNode;
7
use Formularium\Frontend\HTML\Element\Button as HTMLButton;
8
use Formularium\Metadata;
9
10
class Button extends Element
11
{
12
    public function render(array $parameters, HTMLNode $previous): HTMLNode
13
    {
14
        $btnClass = 'btn';
15
        $size = $parameters[self::SIZE] ?? '';
16
        switch ($size) {
17
            case self::SIZE_LARGE:
18
                $btnClass = 'btn-large';
19
                break;
20
            case self::SIZE_SMALL:
21
                $btnClass = 'btn-small';
22
                break;
23
        }
24
        $previous->addAttribute('class', "$btnClass waves-effect waves-light");
25
26
        $icon = $parameters[self::ICON] ?? '';
27
        if ($icon) {
28
            $iconElement = HTMLNode::factory(
29
                'i',
30
                [ 'class' => "material-icons left" ],
31
                $icon
32
            );
33
            $previous->prependContent($iconElement);
34
        }
35
36
        return $previous;
37
    }
38
39
    public static function getMetadata(): Metadata
40
    {
41
        $metadata = HTMLButton::getMetadata();
42
        return $metadata;
43
    }
44
}
45