Passed
Push — master ( 0d07bf...dd4616 )
by Steve
35s
created

ImageNode   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 33
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAttributes() 0 3 1
A __construct() 0 4 1
A isSameText() 0 7 2
1
<?php
2
/**
3
 * (c) Steve Nebes <[email protected]>
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
declare(strict_types=1);
10
11
namespace SN\DaisyDiff\Html\Dom;
12
13
/**
14
 * Represents an image in HTML. Even though images do not contain any text they are single visible objects on the page.
15
 * They are logically a TextNode.
16
 */
17
class ImageNode extends TextNode
18
{
19
    /** @var array */
20
    private $attributes = [];
21
22
    /**
23
     * @param TagNode|null $parent
24
     * @param array        $attributes
25
     */
26 12
    public function __construct(?TagNode $parent, array $attributes = [])
27
    {
28 12
        parent::__construct($parent, \sprintf('<img>%s</img>', $attributes['src'] ?? ''));
29 12
        $this->attributes = $attributes;
30 12
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 1
    public function isSameText(?Node $other): bool
36
    {
37 1
        if (!$other instanceof ImageNode) {
38 1
            return false;
39
        }
40
41 1
        return $this->getText() === $other->getText();
42
    }
43
44
    /**
45
     * @return array
46
     */
47 10
    public function getAttributes(): array
48
    {
49 10
        return $this->attributes;
50
    }
51
}
52