NumberNode   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
eloc 9
dl 0
loc 40
c 0
b 0
f 0
ccs 0
cts 19
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 3 1
A getValue() 0 3 1
A __construct() 0 5 1
A setValue() 0 7 3
1
<?php declare(strict_types=1);
2
3
namespace DaveRandom\Jom;
4
5
final class NumberNode extends Node
6
{
7
    private $value;
8
9
    /**
10
     * @param int|float $value
11
     */
12
    public function __construct($value = 0, ?Document $ownerDocument = null)
13
    {
14
        parent::__construct($ownerDocument);
15
16
        $this->setValue($value ?? 0);
17
    }
18
19
    /**
20
     * @return int|float
21
     */
22
    public function getValue()
23
    {
24
        return $this->value;
25
    }
26
27
    /**
28
     * @param int|float $value
29
     */
30
    public function setValue($value): void
31
    {
32
        if (!(\is_int($value) || \is_float($value))) {
33
            throw new \TypeError('Number node value must be an integer or a double');
34
        }
35
36
        $this->value = $value;
37
    }
38
39
    /**
40
     * @return int|float
41
     */
42
    public function jsonSerialize()
43
    {
44
        return $this->value;
45
    }
46
}
47