Completed
Push — master ( 642ad1...6a6cfd )
by Vitaly
02:16
created

Node   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 5
c 2
b 0
f 2
lcom 1
cbo 0
dl 0
loc 52
ccs 13
cts 13
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 2
A getChild() 0 8 2
A __toString() 0 4 1
1
<?php
2
/**
3
 * Created by Vitaly Iegorov <[email protected]>.
4
 * on 15.04.16 at 12:47
5
 */
6
namespace samsonframework\html2less;
7
8
/**
9
 * LESS tree node.
10
 *
11
 * @author    Vitaly Egorov <[email protected]>
12
 * @copyright 2016 SamsonOS
13
 */
14
class Node
15
{
16
    /** @var string Selector for node */
17
    public $selector;
18
    /** @var $this Pointer to parent node */
19
    public $parent;
20
    /** @var $this [] Collection of nested nodes */
21
    public $children = array();
22
23
    /**
24
     * Create LESS Node
25
     *
26
     * @param string $selector Forced LESS node selector
27
     * @param        $this     $parent   Pointer to parent node
28
     */
29 1
    public function __construct($selector, self &$parent = null)
30
    {
31
        // Pointer to parent LESS Node
32 1
        $this->parent = &$parent;
33 1
        $this->selector = $selector;
34
35
        // Add this node to parent
36 1
        if (null !== $parent) {
37
            // Store child by selector to avoid duplication
38 1
            $parent->children[$this->selector] = $this;
39 1
        }
40 1
    }
41
42
    /**
43
     * Get child node by selector.
44
     *
45
     * @param string $selector Node selector
46
     *
47
     * @return null|$this Node or null if not found
48
     */
49 1
    public function getChild($selector)
50
    {
51 1
        if (array_key_exists($selector, $this->children)) {
52 1
            return $this->children[$selector];
53
        }
54
55 1
        return null;
56
    }
57
58
    /**
59
     * @return string Object string representation
60
     */
61 1
    public function __toString()
62
    {
63 1
        return $this->selector;
64
    }
65
}
66