Passed
Push — master ( 5e4c5e...9eef8c )
by Bruno
07:32
created

Upload::getMetadata()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 15
rs 9.9
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Formularium\Frontend\HTML\Element;
4
5
use Formularium\Element;
6
use Formularium\HTMLNode;
7
use Formularium\Metadata;
8
use Formularium\MetadataParameter;
9
use Formularium\Frontend\HTML\Framework;
10
11
class Upload extends Element
12
{
13
    public function render(array $parameters, HTMLNode $previous): HTMLNode
14
    {
15
        $id = 'upload' . Framework::counter();
16
        return HTMLNode::factory(
17
            'div',
18
            [
19
                'class' => 'formularium-upload'
20
            ],
21
            [
22
                HTMLNode::factory(
23
                    'label',
24
                    [
25
                        'class' => 'formularium-label',
26
                        'for' => $id
27
                    ],
28
                    $parameters[self::LABEL] ?? 'Upload file'
29
                ),
30
                HTMLNode::factory(
31
                    'input',
32
                    [
33
                        'id' => $id,
34
                        'class' => 'formularium-input',
35
                        'type' => 'file'
36
                    ]
37
                ),
38
                HTMLNode::factory(
39
                    'div',
40
                    ['class' => 'formularium-comment'],
41
                    $parameters[self::COMMENT] ?? ''
42
                )
43
            ]
44
        );
45
    }
46
47
    public static function getMetadata(): Metadata
48
    {
49
        return new Metadata(
50
            'Upload',
51
            'Creates an upload field',
52
            [
53
                new MetadataParameter(
54
                    static::LABEL,
55
                    'string',
56
                    'Label for this upload field'
57
                ),
58
                new MetadataParameter(
59
                    static::COMMENT,
60
                    'string',
61
                    'Comment for this upload field'
62
                ),
63
            ]
64
        );
65
    }
66
}
67