GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

TagRenderer   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 53
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 4 1
A __construct() 0 6 1
A renderTag() 0 8 2
A renderOpeningTag() 0 6 2
A renderClosingTag() 0 4 1
A isSelfClosingTag() 0 8 1
1
<?php
2
3
namespace Spatie\HtmlElement;
4
5
class TagRenderer
6
{
7
    /** @var string */
8
    protected $element;
9
10
    /** @var \Spatie\HtmlElement\Attributes */
11
    protected $attributes;
12
13
    /** @var string */
14
    protected $contents;
15
16
    public static function render(string $element, Attributes $attributes, string $contents) : string
17
    {
18
        return (new static($element, $attributes, $contents))->renderTag();
19
    }
20
21
    protected function __construct(string $element, Attributes $attributes, string $contents)
22
    {
23
        $this->element = $element;
24
        $this->attributes = $attributes;
25
        $this->contents = $contents;
26
    }
27
28
    protected function renderTag() : string
29
    {
30
        if ($this->isSelfClosingTag()) {
31
            return $this->renderOpeningTag();
32
        }
33
34
        return "{$this->renderOpeningTag()}{$this->contents}{$this->renderClosingTag()}";
35
    }
36
37
    protected function renderOpeningTag() : string
38
    {
39
        return $this->attributes->isEmpty() ?
40
            "<{$this->element}>" :
41
            "<{$this->element} {$this->attributes}>";
42
    }
43
44
    protected function renderClosingTag() : string
45
    {
46
        return "</{$this->element}>";
47
    }
48
49
    protected function isSelfClosingTag() : bool
50
    {
51
        return in_array(strtolower($this->element), [
52
            'area', 'base', 'br', 'col', 'embed', 'hr',
53
            'img', 'input', 'keygen', 'link', 'menuitem',
54
            'meta', 'param', 'source', 'track', 'wbr',
55
        ]);
56
    }
57
}
58