Passed
Push — master ( 089a6d...7b13b9 )
by Bruno
06:38
created

Renderable_file::viewable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Formularium\Frontend\Bulma\Renderable;
4
5
use Formularium\Datatype;
6
use Formularium\Datatype\Datatype_file;
7
use Formularium\Field;
8
use Formularium\Frontend\Bulma\RenderableBulmaTrait;
9
use Formularium\Frontend\HTML\Framework;
10
use Formularium\Frontend\HTML\Renderable;
11
use Formularium\HTMLElement;
12
13
class Renderable_file extends Renderable
14
{
15
    use RenderableBulmaTrait;
16
    
17
    public function viewable($value, Field $field, HTMLElement $previous): HTMLElement
18
    {
19
        return $previous;
20
    }
21
22
    public function _editable($value, Field $field, HTMLElement $previous): HTMLElement
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

22
    public function _editable(/** @scrutinizer ignore-unused */ $value, Field $field, HTMLElement $previous): HTMLElement

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
23
    {
24
        $extensions = $field->getExtensions();
25
        $validators = $field->getValidators();
0 ignored issues
show
Unused Code introduced by
The assignment to $validators is dead and can be removed.
Loading history...
26
27
        $input = $previous->get('input')[0];
28
        $input->addAttribute('class', 'file-input');
29
30
        $content = HTMLElement::factory(
31
            'div',
32
            ['class' => "file has-name"],
33
            [
34
                HTMLElement::factory(
35
                    'label',
36
                    ['class' => "file-label"],
37
                    [
38
                        $input,
39
                        HTMLElement::factory(
40
                            'span',
41
                            ['class' => "file-cta"],
42
                            [
43
                                HTMLElement::factory(
44
                                    'span',
45
                                    ['class' => "file-icon"],
46
                                    HTMLElement::factory(
47
                                        'i',
48
                                        [ 'class' => "fas fa-upload" ]
49
                                    )
50
                                ),
51
                                HTMLElement::factory(
52
                                    'span',
53
                                    ['class' => "file-label"],
54
                                    $extensions[Renderable::COMMENT] ?? 'Pick file or drag-drop'
55
                                ),
56
                            ]
57
                        ),
58
                        HTMLElement::factory(
59
                            'span',
60
                            ['class' => "file-name"],
61
                            '' // TODO
62
                        )
63
                    ]
64
                ),
65
                HTMLElement::factory(
66
                    'label',
67
                    ['class' => "formularium-label"],
68
                    $extensions[Renderable::LABEL] ?? ''
69
                )
70
            ]
71
        );
72
73
        return $content;
74
    }
75
}
76