Builder::peekStack()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php namespace Mbh\Tree;
2
3
/**
4
 * MBHFramework
5
 *
6
 * @link      https://github.com/MBHFramework/mbh-framework
7
 * @copyright Copyright (c) 2017 Ulises Jeremias Cornejo Fandos
8
 * @license   https://github.com/MBHFramework/mbh-framework/blob/master/LICENSE (MIT License)
9
 */
10
11
use Mbh\Tree\Interfaces\Node as NodeInterface;
12
use Mbh\Tree\Interfaces\Builder as BuilderInterface;
13
use Mbh\Collection\Stack;
14
15
class Builder
16
{
17
    use \Mbh\Tree\Traits\Builder;
18
19
    /**
20
     * @var Stack
21
     */
22
    protected $nodeStack = null;
23
24
    /**
25
     * @param NodeInterface $node
26
     */
27
    public function __construct(NodeInterface $node = null)
28
    {
29
        $this->nodeStack = new Stack;
30
        $this->setNode($node ?: $this->nodeInstanceByValue());
31
    }
32
33
    protected function peekStack(): NodeInterface
34
    {
35
        return $this->nodeStack->peek();
36
    }
37
38
    protected function emptyStack()
39
    {
40
        $this->nodeStack->clear();
41
        return $this;
42
    }
43
44
    protected function pushNode(NodeInterface $node)
45
    {
46
        $this->nodeStack->push($node);
47
        return $this;
48
    }
49
50
    protected function popNode()
51
    {
52
        return $this->nodeStack->pop();
53
    }
54
}
55