1 | <?php |
||
14 | class Branch implements Serializable { |
||
15 | |||
16 | /** |
||
17 | * @var double |
||
18 | */ |
||
19 | private $length; |
||
20 | |||
21 | /** |
||
22 | * @var Leaf[] |
||
23 | */ |
||
24 | private $leaves; |
||
25 | |||
26 | /** |
||
27 | * @return float |
||
28 | */ |
||
29 | public function getLength(): float { |
||
30 | return $this->length; |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * @param float $length |
||
35 | * @return Branch |
||
36 | */ |
||
37 | public function setLength(float $length): Branch { |
||
38 | $this->length = $length; |
||
39 | |||
40 | return $this; |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * @return Leaf[] |
||
45 | */ |
||
46 | public function getLeaves(): array { |
||
47 | return $this->leaves; |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * @param Leaf[] $leaves |
||
52 | * @return Branch |
||
53 | */ |
||
54 | public function setLeaves(array $leaves = []): Branch { |
||
55 | $this->leaves = $leaves; |
||
56 | |||
57 | return $this; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * @param float $length |
||
62 | * @param Leaf[] $leaves |
||
63 | */ |
||
64 | public function __construct(float $length = null, array $leaves = []) { |
||
65 | $this->length = $length; |
||
66 | $this->leaves = $leaves; |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * @return array |
||
71 | */ |
||
72 | public function jsonSerialize(): array { |
||
73 | return [ |
||
74 | 'length' => $this->getLength(), |
||
75 | 'leaves' => $this->getLeaves() |
||
76 | ]; |
||
77 | } |
||
78 | |||
79 | } |