Passed
Push — master ( d98c91...5c9a86 )
by Bruno
08:10
created

Card   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 43
c 1
b 0
f 0
dl 0
loc 81
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getMetadata() 0 4 1
B render() 0 73 5
1
<?php declare(strict_types=1);
2
3
namespace Formularium\Frontend\Bulma\Element;
4
5
use Formularium\Element;
6
use Formularium\HTMLNode;
7
use Formularium\Metadata;
8
use Formularium\Frontend\HTML\Element\Card as HTMLCard;
9
10
class Card extends Element
11
{
12
    public function render(array $parameters, HTMLNode $previous): HTMLNode
13
    {
14
        $base = HTMLNode::factory(
15
            'div',
16
            [
17
                'class' => 'formularium-card card'
18
            ]
19
        );
20
21
        if ($parameters[HTMLCard::IMAGE] ?? false) {
22
            $image = HTMLNode::factory(
23
                'div',
24
                [
25
                    'class' => 'card-image',
26
                ],
27
                HTMLNode::factory(
28
                    'figure',
29
                    [
30
                        'class' => 'image',
31
                    ],
32
                    HTMLNode::factory(
33
                        'img',
34
                        [
35
                            'src' => $parameters[HTMLCard::IMAGE],
36
                            'alt' => '' // TODO
37
                        ]
38
                    )
39
                )
40
            );
41
            $base->appendContent($image);
42
        }
43
44
        $body = HTMLNode::factory(
45
            'div',
46
            [
47
                'class' => 'card-content'
48
            ]
49
        );
50
        $base->appendContent($body);
51
52
        // title
53
        if ($parameters[HTMLCard::TITLE] ?? false) {
54
            $titleData = null;
55
            if ($parameters[HTMLCard::LINK] ?? false) {
56
                $titleData = HTMLNode::factory(
57
                    'a',
58
                    [ 'href' => $parameters[HTMLCard::LINK] ],
59
                    $parameters[HTMLCard::TITLE]
60
                );
61
            } else {
62
                $titleData = $parameters[HTMLCard::TITLE];
63
            }
64
            $title = HTMLNode::factory(
65
                'p',
66
                [
67
                    'class' => 'title is-4'
68
                ],
69
                $titleData
70
            );
71
            $body->appendContent($title);
72
        }
73
74
        if ($parameters[HTMLCard::CONTENT] ?? false) {
75
            $content = HTMLNode::factory(
76
                'div',
77
                [
78
                    'class' => 'content'
79
                ],
80
                $parameters[HTMLCard::CONTENT]
81
            );
82
            $body->appendContent($content);
83
        }
84
        return $base;
85
    }
86
87
    public static function getMetadata(): Metadata
88
    {
89
        $metadata = HTMLCard::getMetadata();
90
        return $metadata;
91
    }
92
}
93