Test Failed
Push — master ( e97986...2933e0 )
by Bruno
19:41 queued 09:43
created

Button::render()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 21
rs 9.8333
cc 4
nc 6
nop 2
1
<?php declare(strict_types=1);
2
3
namespace Formularium\Frontend\Vuetify\Element;
4
5
use Formularium\Element;
6
use Formularium\Exception\Exception;
7
use Formularium\HTMLNode;
8
use Formularium\Frontend\HTML\Element\Button as HTMLButton;
9
use Formularium\Metadata;
10
use Formularium\MetadataParameter;
11
12
class Button extends VuetifyElement
13
{
14
    public function render(array $parameters, HTMLNode $previous): HTMLNode
15
    {
16
        $previous->setTag('v-btn');
17
18
        $this->color($parameters, $previous);
19
20
        $size = $parameters[self::SIZE] ?? '';
21
        switch ($size) {
22
            case self::SIZE_LARGE:
23
                $previous->addAttribute('large');
24
                break;
25
            case self::SIZE_SMALL:
26
                $previous->addAttribute('small');
27
                break;
28
        }
29
30
        if ($parameters[self::ICON] ?? '') {
31
            $previous->addContent('<v-icon>' . $parameters[self::ICON] . '</v-icon>');
32
        }
33
34
        return $previous;
35
    }
36
37
    public static function getMetadata(): Metadata
38
    {
39
        $metadata = HTMLButton::getMetadata();
40
        $metadata->appendParameter(
41
            new MetadataParameter(
42
                HTMLButton::COLOR,
43
                'string',
44
                'Button color. Supports all vuetify colors. Default: primary.'
45
            )
46
        );
47
        return $metadata;
48
    }
49
}
50