NumberNode::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
c 0
b 0
f 0
ccs 0
cts 4
cp 0
rs 10
cc 1
nc 1
nop 2
crap 2
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