Area::withAttribute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 6
nc 2
nop 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 Area
12
 * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/area
13
 */
14
final class Area extends AbstractElement
15
{
16
    public function __construct(AttributeSet $attributes = null)
17
    {
18
        $this->attributes = $attributes ?? new AttributeSet();
19
        $this->tag = new EmptyTag('area', $attributes);
20
    }
21
22
    public function withAttribute(string $name, string $value = null): Area
23
    {
24
        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...
25
            $attribute = new StandardAttribute($name, $value);
26
        } else {
27
            $attribute = new BooleanAttribute($name);
28
        }
29
30
        return new Area($this->attributes->add($attribute));
31
    }
32
33
    public function withAlt($text): Area
34
    {
35
        return $this->withAttribute('alt', $text);
36
    }
37
38
    public function withCoords($coords): Area
39
    {
40
        return $this->withAttribute('coords', $coords);
41
    }
42
43
    public function withDownload($filename = null): Area
44
    {
45
        return $this->withAttribute('download', $filename);
46
    }
47
48
    public function withHref($href): Area
49
    {
50
        return $this->withAttribute('href', $href);
51
    }
52
53
    public function withHrefLang($lang): Area
54
    {
55
        return $this->withAttribute('hreflang', $lang);
56
    }
57
58
    public function withMedia($media): Area
59
    {
60
        return $this->withAttribute('media', $media);
61
    }
62
63
    public function withRel($rel): Area
64
    {
65
        return $this->withAttribute('rel', $rel);
66
    }
67
68
    public function withShape($shape): Area
69
    {
70
        return $this->withAttribute('shape', $shape);
71
    }
72
73
    public function withTarget($target): Area
74
    {
75
        return $this->withAttribute('target', $target);
76
    }
77
78
    public function withType($type): Anchor
79
    {
80
        return $this->withAttribute('type', $type);
81
    }
82
}
83