Card   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 62 5
A getMetadata() 0 4 1
1
<?php declare(strict_types=1);
2
3
namespace Formularium\Frontend\Bootstrap\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
                'img',
24
                [
25
                    'class' => 'card-img-top',
26
                    'src' => $parameters[HTMLCard::IMAGE],
27
                    'alt' => '' // TODO
28
                ]
29
            );
30
            $base->appendContent($image);
31
        }
32
33
        $body = HTMLNode::factory(
34
            'div',
35
            [
36
                'class' => 'card-body'
37
            ]
38
        );
39
        $base->appendContent($body);
40
41
        // title
42
        if ($parameters[HTMLCard::TITLE] ?? false) {
43
            $titleData = null;
44
            if ($parameters[HTMLCard::LINK] ?? false) {
45
                $titleData = HTMLNode::factory(
46
                    'a',
47
                    [ 'href' => $parameters[HTMLCard::LINK] ],
48
                    $parameters[HTMLCard::TITLE]
49
                );
50
            } else {
51
                $titleData = $parameters[HTMLCard::TITLE];
52
            }
53
            $title = HTMLNode::factory(
54
                'h5',
55
                [
56
                    'class' => 'card-title'
57
                ],
58
                $titleData
59
            );
60
            $body->appendContent($title);
61
        }
62
63
        if ($parameters[HTMLCard::CONTENT] ?? false) {
64
            $content = HTMLNode::factory(
65
                'div',
66
                [
67
                    'class' => 'card-text'
68
                ],
69
                $parameters[HTMLCard::CONTENT]
70
            );
71
            $body->appendContent($content);
72
        }
73
        return $base;
74
    }
75
76
    public static function getMetadata(): Metadata
77
    {
78
        $metadata = HTMLCard::getMetadata();
79
        return $metadata;
80
    }
81
}
82