Passed
Pull Request — master (#11)
by Steve
01:59
created

WhiteSpaceNode::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 3
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 2
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 SN\DaisyDiff\Html\Dom;
12
13
/**
14
 * Represents whitespace in the HTML file.
15
 */
16
class WhiteSpaceNode extends TextNode
17
{
18
    /**
19
     * @param TagNode|null $parent
20
     * @param string       $s
21
     * @param Node|null     $like
22
     */
23 14
    public function __construct(?TagNode $parent, string $s, ?Node $like)
24
    {
25 14
        parent::__construct($parent, $s);
26
27 14
        if ($like instanceof TextNode) {
28 14
            $newModification = clone $like->getModification();
29 14
            $newModification->setFirstOfId(false);
30 14
            $this->setModification($newModification);
31
        }
32 14
    }
33
34
    /**
35
     * @param string $c
36
     * @return bool
37
     */
38 23
    public static function isWhiteSpace(string $c): bool
39
    {
40 23
        switch ($c) {
41 23
            case ' ':
42 23
            case "\t":
43 23
            case "\r":
44 23
            case "\n":
45 16
                return true;
46
            default:
47 23
                return false;
48
        }
49
    }
50
}
51