Renderable_file::viewable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

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
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\HTMLNode;
12
13
class Renderable_file extends Renderable
14
{
15
    use RenderableBulmaTrait;
16
    
17
    public function viewable($value, Field $field, HTMLNode $previous): HTMLNode
18
    {
19
        return $previous;
20
    }
21
22
    /**
23
     * Subcall of wrapper editable()
24
     *
25
     * @param mixed $value
26
     * @param Field $field
27
     * @param HTMLNode $previous
28
     * @return HTMLNode
29
     */
30
    public function _editable($value, Field $field, HTMLNode $previous): HTMLNode
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

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

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