Completed
Push — master ( aba289...58e266 )
by Ventaquil
02:10
created

Node::move()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 3
1
<?php
2
3
namespace PHPAlgorithms\GraphTools\Graph;
4
5
use JsonSerializable;
6
use PHPAlgorithms\GraphTools\Abstracts\BuildableAbstract;
7
8
/**
9
 * Class Point
10
 * @package PHPAlgorithms\GraphTools\Graph
11
 * @method integer getId()
12
 * @method float|null getX()
13
 * @method float|null getY()
14
 * @method float|null getZ()
15
 * @property-read integer $id
16
 * @property-read float|null $x
17
 * @property-read float|null $y
18
 * @property-read float|null $z
19
 */
20
class Node extends BuildableAbstract implements JsonSerializable
21
{
22
    /**
23
     * @var string[] $allowedGet
24
     */
25
    protected $allowedGet = array('id', 'x', 'y', 'z');
26
27
    /**
28
     * @var integer $increment
29
     */
30
    private static $increment = 0;
31
32
    /**
33
     * @var integer $id
34
     */
35
    protected $id;
36
37
    /**
38
     * @var float|null $x
39
     */
40
    protected $x;
41
42
    /**
43
     * @var float|null $y
44
     */
45
    protected $y;
46
47
    /**
48
     * @var float|null $z
49
     */
50
    protected $z;
51
52
    /**
53
     * Point constructor.
54
     * @param float|null $x
55
     * @param float|null $y
56
     * @param float|null $z
57
     */
58
    public function __construct(?float $x = null, ?float $y = null, ?float $z = null)
59
    {
60
        $this->id = $this::$increment++;
61
62
        $this->x = $x;
63
        $this->y = $y;
64
        $this->z = $z;
65
    }
66
67
    /**
68
     * @return array
69
     */
70
    public function jsonSerialize() : array
71
    {
72
        $serialize = array();
73
74
        foreach ($this->allowedGet as $variable) {
75
            /**
76
             * @var string $variable
77
             */
78
79
            if (!is_null($variable)) {
80
                $serialize[$variable] = $this->{$variable};
81
            }
82
        }
83
84
        return $serialize;
85
    }
86
87
    /**
88
     * @param float|null $x
89
     * @param float|null $y
90
     * @param float|null $z
91
     * @return Node
92
     */
93
    public function move(float $x = null, float $y = null, float $z = null) : Node
94
    {
95
        $this->x += $x;
96
        $this->y += $y;
97
        $this->z += $z;
98
99
        return $this;
100
    }
101
}