Test Setup Failed
Push — master ( fcec52...178474 )
by Royall
02:20
created

ArbitraryEmpty   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 22
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A withAttribute() 0 10 2
1
<?php
2
3
namespace RoyallTheFourth\HtmlDocument\Element;
4
5
use RoyallTheFourth\HtmlDocument\Attribute\BooleanAttribute;
6
use RoyallTheFourth\HtmlDocument\Attribute\StandardAttribute;
7
use RoyallTheFourth\HtmlDocument\Set\AttributeSet;
8
use RoyallTheFourth\HtmlDocument\Tag\EmptyTag;
9
10
/**
11
 * Class Arbitrary
12
 * Any type of tag without a matching close tag.
13
 */
14
final class ArbitraryEmpty extends AbstractElement
15
{
16
    private $name;
17
18
    public function __construct(string $name, AttributeSet $attributes = null)
19
    {
20
        $this->name = $name;
21
        $this->attributes = $attributes ?? new AttributeSet();
22
        $this->tag = new EmptyTag($name, $attributes);
23
    }
24
25
    public function withAttribute(string $name, string $value = null): ArbitraryEmpty
26
    {
27
        if ($value) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $value of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
28
            $attribute = new StandardAttribute($name, $value);
29
        } else {
30
            $attribute = new BooleanAttribute($name);
31
        }
32
33
        return new ArbitraryEmpty($this->name, $this->attributes->add($attribute));
34
    }
35
}
36