Passed
Push — master ( e98e31...880950 )
by Bruno
06:29
created

Button::render()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 25
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 4
eloc 18
c 1
b 0
f 1
nc 6
nop 2
dl 0
loc 25
rs 9.6666
1
<?php declare(strict_types=1);
2
3
namespace Formularium\Frontend\Materialize\Element;
4
5
use Formularium\Element;
6
use Formularium\HTMLNode;
7
8
class Button extends Element
9
{
10
    public function render(array $parameters, HTMLNode $previous): HTMLNode
11
    {
12
        $btnClass = 'btn';
13
        $size = $parameters[self::SIZE] ?? '';
14
        switch ($size) {
15
            case self::SIZE_LARGE:
16
                $btnClass = 'btn-large';
17
                break;
18
            case self::SIZE_SMALL:
19
                $btnClass = 'btn-small';
20
                break;
21
        }
22
        $previous->addAttribute('class', "$btnClass waves-effect waves-light");
23
24
        $icon = $parameters[self::ICON] ?? '';
25
        if ($icon) {
26
            $iconElement = HTMLNode::factory(
27
                'i',
28
                [ 'class' => "material-icons left" ],
29
                $icon
30
            );
31
            $previous->prependContent($iconElement);
32
        }
33
34
        return $previous;
35
    }
36
}
37