Debian Codegraph @

vendor/mck89/peast/lib/Peast/Syntax/Node/IfStatement.php

raw
1 <?php
2 /**
3 * This file is part of the Peast package
4 *
5 * (c) Marco Marchiò <[email protected]>
6 *
7 * For the full copyright and license information refer to the LICENSE file
8 * distributed with this source code
9 */
10 namespace Peast\Syntax\Node;
11
12 /**
13 * A node that represents an if statement.
14 * For example: if (test) {} else {}
15 *
16 * @author Marco Marchiò <[email protected]>
17 */
18 class IfStatement extends Node implements Statement
19 {
20 /**
21 * Map of node properties
22 *
23 * @var array
24 */
25 protected $propertiesMap = array(
26 "test" => true,
27 "consequent" => true,
28 "alternate" => true
29 );
30
31 /**
32 * The test expression
33 *
34 * @var Expression
35 */
36 protected $test;
37
38 /**
39 * The statement that is activated if the test expression is true
40 *
41 * @var Statement|FunctionDeclaration
42 */
43 protected $consequent;
44
45 /**
46 * The "else" statement
47 *
48 * @var Statement
49 */
50 protected $alternate;
51
52 /**
53 * Returns the test expression
54 *
55 * @return Expression
56 */
57 public function getTest()
58 {
59 return $this->test;
60 }
61
62 /**
63 * Sets the test expression
64 *
65 * @param Expression $test Test expression
66 *
67 * @return $this
68 */
69 public function setTest(Expression $test)
70 {
71 $this->test = $test;
72 return $this;
73 }
74
75 /**
76 * Returns the statement that is activated if the test expression is true
77 *
78 * @return Statement|FunctionDeclaration
79 */
80 public function getConsequent()
81 {
82 return $this->consequent;
83 }
84
85 /**
86 * Sets the statement that is activated if the test expression is true
87 *
88 * @param Statement|FunctionDeclaration $consequent The consequent expression
89 *
90 * @return $this
91 */
92 public function setConsequent($consequent)
93 {
94 $this->assertType(
95 $consequent,
96 array("Statement", "FunctionDeclaration"),
97 true
98 );
99 $this->consequent = $consequent;
100 return $this;
101 }
102
103 /**
104 * Returns the "else" statement
105 *
106 * @return Statement
107 */
108 public function getAlternate()
109 {
110 return $this->alternate;
111 }
112
113 /**
114 * Sets the "else" statement
115 *
116 * @param Statement|FunctionDeclaration $alternate The "else" statement
117 *
118 * @return $this
119 */
120 public function setAlternate($alternate)
121 {
122 $this->assertType(
123 $alternate,
124 array("Statement", "FunctionDeclaration"),
125 true
126 );
127 $this->alternate = $alternate;
128 return $this;
129 }
130 }