Completed
Push — master ( 332a4c...198c54 )
by Kirill
02:13
created

CallStack   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A count() 0 4 1
A push() 0 6 1
A pop() 0 6 1
A getIterator() 0 8 2
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\SDL\Compiler;
11
12
use Railt\Lexer\Exception\LexerException;
13
use Railt\Parser\Exception\ParserException;
14
use Railt\Reflection\Contracts\Definition;
15
use Railt\Reflection\Exception\ReflectionException;
16
use Railt\Reflection\Exception\TypeNotFoundException as TypeNotFoundReflectionException;
17
use Railt\SDL\Exception\CompilerException;
18
use Railt\SDL\Exception\SemanticException;
19
use Railt\SDL\Exception\SyntaxException;
20
use Railt\SDL\Exception\TypeNotFoundException;
21
22
/**
23
 * Class CallStack
24
 */
25
class CallStack implements \IteratorAggregate, \Countable
26
{
27
    /**
28
     * @var \SplStack
29
     */
30
    private $stack;
31
32
    /**
33
     * CallStack constructor.
34
     */
35
    public function __construct()
36
    {
37
        $this->stack = new \SplStack();
38
    }
39
40
    /**
41
     * @return int
42
     */
43
    public function count(): int
44
    {
45
        return $this->stack->count();
46
    }
47
48
    /**
49
     * @param Definition $definition
50
     * @return CallStack
51
     */
52
    public function push(Definition $definition): self
53
    {
54
        $this->stack->push($definition);
55
56
        return $this;
57
    }
58
59
    /**
60
     * @return CallStack
61
     */
62
    public function pop(): self
63
    {
64
        $this->stack->pop();
65
66
        return $this;
67
    }
68
69
    /**
70
     * @return \Traversable|Definition[]
71
     */
72
    public function getIterator(): \Traversable
73
    {
74
        $copy = clone $this->stack;
75
76
        while ($copy->count() > 0) {
77
            yield $copy->pop();
78
        }
79
    }
80
}
81