Passed
Push — 1.x ( e8be9e...0f3e2e )
by Ulises Jeremias
02:31
created

Builder::peekStack()   A

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
14
class Builder
15
{
16
    use Traits\Builder;
17
18
    /**
19
     * @var NodeInterface[]
20
     */
21
    protected $nodeStack = [];
22
23
    /**
24
     * @param NodeInterface $node
25
     */
26
    public function __construct(NodeInterface $node = null)
27
    {
28
        $this->setNode($node ?: $this->nodeInstanceByValue());
0 ignored issues
show
Bug introduced by
It seems like $node ?: $this->nodeInstanceByValue() can also be of type Mbh\Tree\Traits\Node; however, parameter $node of Mbh\Tree\Builder::setNode() does only seem to accept Mbh\Tree\Interfaces\Node, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

28
        $this->setNode(/** @scrutinizer ignore-type */ $node ?: $this->nodeInstanceByValue());
Loading history...
29
    }
30
31
    protected function peekStack(): NodeInterface
32
    {
33
        return $this->nodeStack[count($this->nodeStack) - 1];
34
    }
35
36
    protected function emptyStack()
37
    {
38
        $this->nodeStack = [];
39
        return $this;
40
    }
41
42
    protected function pushNode(NodeInterface $node)
43
    {
44
        array_push($this->nodeStack, $node);
45
        return $this;
46
    }
47
48
    protected function popNode()
49
    {
50
        return array_pop($this->nodeStack);
51
    }
52
}
53