Menu

[r293]: / trunk / src / PHPCheckstyle / StatementStack.php  Maximize  Restore  History

Download this file

94 lines (85 with data), 1.9 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
namespace PHPCheckstyle;
/**
* Statement stack class.
* This object is used to store the current stack of nested statements.
*
* @package classes
*/
class StatementStack {
/**
* Stack of items.
*
* @var Array[StatementItem]
*/
var $statements = array();
/**
* Return the size of the stack.
*
* @return Integer
*/
function count() {
return count($this->statements);
}
/**
* Add a statement to the stack.
*
* @param StatementItem $item
*/
function push($item) {
array_push($this->statements, $item);
}
/**
* Get the top statement from the stack.
*
* @return StatementItem
*/
function pop() {
return array_pop($this->statements);
}
/**
* Display the current branching stack.
*
* @return String
*/
function getStackDump() {
$dump = "";
foreach ($this->statements as $item) {
$dump .= $item->type;
if ($item->type == "FUNCTION" || $item->type == "INTERFACE" || $item->type == "CLASS") {
$dump .= "(" . $item->name . ")";
}
$dump .= " -> ";
}
return $dump;
}
/**
* Return the top stack item.
*
* @return StatementItem
*/
function getCurrentStackItem() {
$topItem = end($this->statements);
if ($topItem != null) {
return $topItem;
} else {
// In case of a empty stack, we are at the root of a PHP file (with no class or function).
// We return the default values
return new StatementItem();
}
}
/**
* Return the parent stack item.
*
* @return StatementItem
*/
function getParentStackItem() {
if ($this->count() > 1) {
return $this->statements[$this->count() - 2];
} else {
// In case of a empty stack, we are at the root of a PHP file (with no class or function).
// We return the default values
return new StatementItem();
}
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.