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

Card::render()   A

Complexity

Conditions 5
Paths 12

Size

Total Lines 67
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 37
c 1
b 0
f 0
nc 12
nop 2
dl 0
loc 67
rs 9.0168

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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