Standard   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 32
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A render() 0 7 1
A renderChildren() 0 10 2
1
<?php
2
3
namespace RoyallTheFourth\HtmlDocument\Tag;
4
5
use RoyallTheFourth\HtmlDocument\Set\AttributeSet;
6
use RoyallTheFourth\HtmlDocument\Set\ElementSet;
7
8
final class Standard implements TagInterface
9
{
10
    private $attributes;
11
    private $name;
12
    private $children;
13
14
    public function __construct(string $name, AttributeSet $attributes = null, ElementSet $children = null)
15
    {
16
        $this->attributes = $attributes ?? new AttributeSet();
17
        $this->children = $children ?? new ElementSet();
18
        $this->name = $name;
19
    }
20
21
    public function render(): string
22
    {
23
        $attributes = $this->attributes->render();
24
        $children = $this->renderChildren();
25
26
        return "<{$this->name}{$attributes}>{$children}\n</{$this->name}>\n";
27
    }
28
29
    private function renderChildren(): string
30
    {
31
        $out = '';
32
33
        foreach ($this->children->iterate() as $child) {
34
            $out .= "\n" . $child->render();
35
        }
36
37
        return $out;
38
    }
39
}
40