Completed
Push — master ( 485481...cf02a9 )
by Vitaly
02:11
created

TreeNode::toArray()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 19
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 4
nop 0
1
<?php declare(strict_types = 1);
2
/**
3
 * Created by Vitaly Iegorov <[email protected]>.
4
 * on 31.03.17 at 09:23
5
 */
6
namespace samsonframework\stringconditiontree;
7
8
/**
9
 * Class TreeNode
10
 *
11
 * @author Vitaly Egorov <[email protected]>
12
 */
13
class TreeNode extends IterableTreeNode
14
{
15
    /** @var self Pointer to parent node */
16
    public $parent;
17
18
    /** @var string Tree node value */
19
    public $value;
20
21
    /** @var string Tree node full value */
22
    public $fullValue;
23
24
    /**
25
     * TreeNode constructor.
26
     *
27
     * @param string   $value  Node value
28
     * @param string   $identifier Node identifier
29
     * @param TreeNode $parent Pointer to parent node
30
     */
31
    public function __construct(string $value = '', string $identifier = '', TreeNode $parent = null)
32
    {
33
        $this->value = $value;
34
        $this->parent = $parent;
35
        $this->identifier = $identifier;
36
        $this->fullValue = $parent !== null ? $parent->fullValue . $value : '';
37
    }
38
39
    /**
40
     * Append new node instance and return it.
41
     *
42
     * @param string $value Node value
43
     * @param string $identifier Node identifier
44
     *
45
     * @return TreeNode New created node instance
46
     */
47
    public function append(string $value, string $identifier): TreeNode
48
    {
49
        return $this->children[$value] = new self($value, $identifier, $this);
50
    }
51
}
52