Passed
Push — master ( 981639...0d07bf )
by Steve
47s
created

ChangeText::characters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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 DaisyDiff\Html;
12
13
use DaisyDiff\Xml\ContentHandlerInterface;
14
15
/**
16
 * ChangeText model.
17
 */
18
class ChangeText implements ContentHandlerInterface
19
{
20
    /** @var string */
21
    private $text = '';
22
23
    /**
24
     * @param string $qName
25
     * @param array  $attributes
26
     */
27 35
    public function startElement(string $qName, array $attributes = []): void
28
    {
29 35
        $this->text .= '<' . $qName;
30
31 35
        foreach ($attributes as $attr => $value) {
32 31
            $this->text .= \sprintf(' %s="%s"', $attr, $value);
33
        }
34
35 35
        $this->text .= '>';
36 35
    }
37
38
    /**
39
     * @param string $qName
40
     */
41 35
    public function endElement(string $qName): void
42
    {
43 35
        $this->text .= \sprintf('</%s>', $qName);
44 35
    }
45
46
    /**
47
     * @param string $chars
48
     */
49 28
    public function characters(string $chars): void
50
    {
51 28
        $this->text .= $chars;
52 28
    }
53
54
    /**
55
     * @return string
56
     */
57 33
    public function getText(): string
58
    {
59 33
        return $this->text;
60
    }
61
62
    /**
63
     * @return string
64
     */
65
    public function __toString(): string
66
    {
67
        return $this->getText();
68
    }
69
}
70