| 69 |
69 |
* Tests the start line value. |
| 70 |
70 |
* |
| 71 |
71 |
* @return void |
| 72 |
|
- * @group ast |
|
72 |
+ * @covers PHP_Depend_Code_ASTForeachStatement |
|
73 |
+ * @covers PHP_Depend_Parser |
|
74 |
+ * @group pdepend |
|
75 |
+ * @group pdepend::ast |
|
76 |
+ * @group unittest |
| 73 |
77 |
*/ |
| 74 |
78 |
public function testForeachStatementHasExpectedStartLine() |
| 75 |
79 |
{ |
| 76 |
80 |
$statement = $this->_getFirstForeachStatementInFunction(__METHOD__); |
| 77 |
|
- $this->assertSame(4, $statement->getStartLine()); |
|
81 |
+ $this->assertEquals(4, $statement->getStartLine()); |
| 78 |
82 |
} |
| 79 |
83 |
|
| 80 |
84 |
/** |
| 81 |
85 |
* Tests the start column value. |
| 82 |
86 |
* |
| 83 |
87 |
* @return void |
| 84 |
|
- * @group ast |
|
88 |
+ * @covers PHP_Depend_Code_ASTForeachStatement |
|
89 |
+ * @covers PHP_Depend_Parser |
|
90 |
+ * @group pdepend |
|
91 |
+ * @group pdepend::ast |
|
92 |
+ * @group unittest |
| 85 |
93 |
*/ |
| 86 |
94 |
public function testForeachStatementHasExpectedStartColumn() |
| 87 |
95 |
{ |
| 88 |
96 |
$statement = $this->_getFirstForeachStatementInFunction(__METHOD__); |
| 89 |
|
- $this->assertSame(5, $statement->getStartColumn()); |
|
97 |
+ $this->assertEquals(5, $statement->getStartColumn()); |
| 90 |
98 |
} |
| 91 |
99 |
|
| 92 |
100 |
/** |
| 93 |
101 |
* Tests the end line value. |
| 94 |
102 |
* |
| 95 |
103 |
* @return void |
| 96 |
|
- * @group ast |
|
104 |
+ * @covers PHP_Depend_Code_ASTForeachStatement |
|
105 |
+ * @covers PHP_Depend_Parser |
|
106 |
+ * @group pdepend |
|
107 |
+ * @group pdepend::ast |
|
108 |
+ * @group unittest |
| 97 |
109 |
*/ |
| 98 |
110 |
public function testForeachStatementHasExpectedEndLine() |
| 99 |
111 |
{ |
| 100 |
112 |
$statement = $this->_getFirstForeachStatementInFunction(__METHOD__); |
| 101 |
|
- $this->assertSame(4, $statement->getEndLine()); |
|
113 |
+ $this->assertEquals(4, $statement->getEndLine()); |
| 102 |
114 |
} |
| 103 |
115 |
|
| 104 |
116 |
/** |
| 105 |
117 |
* Tests the end column value. |
| 106 |
118 |
* |
| 107 |
119 |
* @return void |
| 108 |
|
- * @group ast |
|
120 |
+ * @covers PHP_Depend_Code_ASTForeachStatement |
|
121 |
+ * @covers PHP_Depend_Parser |
|
122 |
+ * @group pdepend |
|
123 |
+ * @group pdepend::ast |
|
124 |
+ * @group unittest |
| 109 |
125 |
*/ |
| 110 |
126 |
public function testForeachStatementHasExpectedEndColumn() |
| 111 |
127 |
{ |
| 112 |
128 |
$statement = $this->_getFirstForeachStatementInFunction(__METHOD__); |
| 113 |
|
- $this->assertSame(11, $statement->getEndColumn()); |
|
129 |
+ $this->assertEquals(26, $statement->getEndColumn()); |
| 114 |
130 |
} |
| 115 |
131 |
|
| 116 |
132 |
/** |
|
133 |
+ * testForeachStatementContainsListExpressionAsFirstChild |
|
134 |
+ * |
|
135 |
+ * @return void |
|
136 |
+ * @covers PHP_Depend_Code_ASTForeachStatement |
|
137 |
+ * @covers PHP_Depend_Parser |
|
138 |
+ * @group pdepend |
|
139 |
+ * @group pdepend::ast |
|
140 |
+ * @group unittest |
|
141 |
+ */ |
|
142 |
+ public function testForeachStatementContainsExpressionAsFirstChild() |
|
143 |
+ { |
|
144 |
+ $statement = $this->_getFirstForeachStatementInFunction(__METHOD__); |
|
145 |
+ $this->assertType(PHP_Depend_Code_ASTExpression::CLAZZ, $statement->getChild(0)); |
|
146 |
+ } |
|
147 |
+ |
|
148 |
+ /** |
|
149 |
+ * testForeachStatementWithoutKeyAndWithValue |
|
150 |
+ * |
|
151 |
+ * @return void |
|
152 |
+ * @covers PHP_Depend_Code_ASTForeachStatement |
|
153 |
+ * @covers PHP_Depend_Parser |
|
154 |
+ * @group pdepend |
|
155 |
+ * @group pdepend::ast |
|
156 |
+ * @group unittest |
|
157 |
+ */ |
|
158 |
+ public function testForeachStatementWithoutKeyAndWithValue() |
|
159 |
+ { |
|
160 |
+ $statement = $this->_getFirstForeachStatementInFunction(__METHOD__); |
|
161 |
+ $this->assertType(PHP_Depend_Code_ASTVariable::CLAZZ, $statement->getChild(1)); |
|
162 |
+ } |
|
163 |
+ |
|
164 |
+ /** |
|
165 |
+ * testForeachStatementWithoutKeyAndWithValueByReference |
|
166 |
+ * |
|
167 |
+ * @return void |
|
168 |
+ * @covers PHP_Depend_Code_ASTForeachStatement |
|
169 |
+ * @covers PHP_Depend_Parser |
|
170 |
+ * @group pdepend |
|
171 |
+ * @group pdepend::ast |
|
172 |
+ * @group unittest |
|
173 |
+ */ |
|
174 |
+ public function testForeachStatementWithoutKeyAndWithValueByReference() |
|
175 |
+ { |
|
176 |
+ $statement = $this->_getFirstForeachStatementInFunction(__METHOD__); |
|
177 |
+ $this->assertType(PHP_Depend_Code_ASTUnaryExpression::CLAZZ, $statement->getChild(1)); |
|
178 |
+ } |
|
179 |
+ |
|
180 |
+ /** |
|
181 |
+ * testForeachStatementWithKeyAndValue |
|
182 |
+ * |
|
183 |
+ * @return void |
|
184 |
+ * @covers PHP_Depend_Code_ASTForeachStatement |
|
185 |
+ * @covers PHP_Depend_Parser |
|
186 |
+ * @group pdepend |
|
187 |
+ * @group pdepend::ast |
|
188 |
+ * @group unittest |
|
189 |
+ */ |
|
190 |
+ public function testForeachStatementWithKeyAndValue() |
|
191 |
+ { |
|
192 |
+ $statement = $this->_getFirstForeachStatementInFunction(__METHOD__); |
|
193 |
+ $this->assertType(PHP_Depend_Code_ASTVariable::CLAZZ, $statement->getChild(2)); |
|
194 |
+ } |
|
195 |
+ |
|
196 |
+ /** |
|
197 |
+ * testForeachStatementWithKeyAndValueByReference |
|
198 |
+ * |
|
199 |
+ * @return void |
|
200 |
+ * @covers PHP_Depend_Code_ASTForeachStatement |
|
201 |
+ * @covers PHP_Depend_Parser |
|
202 |
+ * @group pdepend |
|
203 |
+ * @group pdepend::ast |
|
204 |
+ * @group unittest |
|
205 |
+ */ |
|
206 |
+ public function testForeachStatementWithKeyAndValueByReference() |
|
207 |
+ { |
|
208 |
+ $statement = $this->_getFirstForeachStatementInFunction(__METHOD__); |
|
209 |
+ $this->assertType(PHP_Depend_Code_ASTUnaryExpression::CLAZZ, $statement->getChild(2)); |
|
210 |
+ } |
|
211 |
+ |
|
212 |
+ /** |
|
213 |
+ * testForeachStatementThrowsExpectedExceptionForKeyByReference |
|
214 |
+ * |
|
215 |
+ * @return void |
|
216 |
+ * @covers PHP_Depend_Code_ASTForeachStatement |
|
217 |
+ * @covers PHP_Depend_Parser |
|
218 |
+ * @group pdepend |
|
219 |
+ * @group pdepend::ast |
|
220 |
+ * @group unittest |
|
221 |
+ * @expectedException PHP_Depend_Parser_UnexpectedTokenException |
|
222 |
+ */ |
|
223 |
+ public function testForeachStatementThrowsExpectedExceptionForKeyByReference() |
|
224 |
+ { |
|
225 |
+ $this->_getFirstForeachStatementInFunction(__METHOD__); |
|
226 |
+ } |
|
227 |
+ |
|
228 |
+ /** |
| 117 |
229 |
* Returns a node instance for the currently executed test case. |
| 118 |
230 |
* |
| 119 |
231 |
* @param string $testCase Name of the calling test case. |
| 1702 |
1702 |
{ |
| 1703 |
1703 |
$this->_tokenStack->push(); |
| 1704 |
1704 |
$token = $this->_consumeToken(self::T_FOREACH); |
|
1705 |
+ |
|
1706 |
+ $foreach = $this->_builder->buildASTForeachStatement($token->image); |
|
1707 |
+ |
|
1708 |
+ $this->_consumeComments(); |
|
1709 |
+ $this->_consumeToken(self::T_PARENTHESIS_OPEN); |
|
1710 |
+ |
|
1711 |
+ $foreach->addChild($this->_parseExpressionUntil(self::T_AS)); |
|
1712 |
+ |
|
1713 |
+ $this->_consumeToken(self::T_AS); |
|
1714 |
+ $this->_consumeComments(); |
|
1715 |
+ |
|
1716 |
+ if ($this->_tokenizer->peek() === self::T_BITWISE_AND) { |
|
1717 |
+ $foreach->addChild($this->_parseVariableByReference()); |
|
1718 |
+ } else { |
|
1719 |
+ $foreach->addChild($this->_parseVariable()); |
|
1720 |
+ |
|
1721 |
+ if ($this->_tokenizer->peek() === self::T_DOUBLE_ARROW) { |
|
1722 |
+ $this->_consumeToken(self::T_DOUBLE_ARROW); |
|
1723 |
+ $foreach->addChild($this->_parseVariableOptionalByReference()); |
|
1724 |
+ } |
|
1725 |
+ } |
| 1705 |
1726 |
|
| 1706 |
|
- return $this->_setNodePositionsAndReturn( |
| 1707 |
|
- $this->_builder->buildASTForeachStatement($token->image) |
| 1708 |
|
- ); |
|
1727 |
+ $this->_consumeToken(self::T_PARENTHESIS_CLOSE); |
|
1728 |
+ |
|
1729 |
+ return $this->_setNodePositionsAndReturn($foreach); |
| 1709 |
1730 |
} |
| 1710 |
1731 |
|
| 1711 |
1732 |
/** |
| 1724 |
1745 |
|
| 1725 |
1746 |
return $this->_setNodePositionsAndReturn($while); |
| 1726 |
1747 |
} |
|
1748 |
+ |
|
1749 |
+ /** |
|
1750 |
+ * Parses an expression until the first token of <b>$stopTokenType</b> |
|
1751 |
+ * occures. |
|
1752 |
+ * |
|
1753 |
+ * This method is temporary solution until the parser supports the complete |
|
1754 |
+ * PHP syntax, so that this method will/must be removed in future versions |
|
1755 |
+ * of PHP_Depend. |
|
1756 |
+ * |
|
1757 |
+ * @param integer $stopTokenType The stop token which will not be part of |
|
1758 |
+ * the parsed and returns ASTExpression node. |
|
1759 |
+ * |
|
1760 |
+ * @return PHP_Depend_Code_ASTExpression |
|
1761 |
+ * @since 0.9.11 |
|
1762 |
+ * @todo Remove this method when PHP_Depend supports the complete PHP syntax |
|
1763 |
+ */ |
|
1764 |
+ private function _parseExpressionUntil($stopTokenType) |
|
1765 |
+ { |
|
1766 |
+ $this->_tokenStack->push(); |
|
1767 |
+ |
|
1768 |
+ $expression = $this->_builder->buildASTExpression(); |
|
1769 |
+ |
|
1770 |
+ $tokenType = $this->_tokenizer->peek(); |
|
1771 |
+ while ($tokenType !== self::T_EOF) { |
|
1772 |
+ if ($stopTokenType === $tokenType) { |
|
1773 |
+ return $this->_setNodePositionsAndReturn($expression); |
|
1774 |
+ } |
|
1775 |
+ if (is_object($expr = $this->_parseOptionalExpression())) { |
|
1776 |
+ $expression->addChild($expr); |
|
1777 |
+ } else { |
|
1778 |
+ $this->_consumeToken($tokenType); |
|
1779 |
+ } |
|
1780 |
+ $tokenType = $this->_tokenizer->peek(); |
|
1781 |
+ } |
|
1782 |
+ throw new PHP_Depend_Parser_TokenStreamEndException($this->_tokenizer); |
|
1783 |
+ } |
| 1727 |
1784 |
|
| 1728 |
1785 |
/** |
| 1729 |
1786 |
* Parses any expression that is surrounded by an opening and a closing |
| 2350 |
2407 |
} |
| 2351 |
2408 |
return $this->_builder->buildASTConstant($token->image); |
| 2352 |
2409 |
} |
|
2410 |
+ |
|
2411 |
+ /** |
|
2412 |
+ * Parses a variable node, optionally prefixed by an unary expression that |
|
2413 |
+ * represents php's by reference operator. |
|
2414 |
+ * |
|
2415 |
+ * @return PHP_Depend_Code_ASTNode |
|
2416 |
+ * @since 0.9.11 |
|
2417 |
+ */ |
|
2418 |
+ private function _parseVariableOptionalByReference() |
|
2419 |
+ { |
|
2420 |
+ $this->_consumeComments(); |
|
2421 |
+ if ($this->_tokenizer->peek() === self::T_BITWISE_AND) { |
|
2422 |
+ return $this->_parseVariableByReference(); |
|
2423 |
+ } |
|
2424 |
+ return $this->_parseVariable(); |
|
2425 |
+ } |
|
2426 |
+ |
|
2427 |
+ /** |
|
2428 |
+ * Parses a unary expression which represents php's by reference operator, |
|
2429 |
+ * that is followed by a variable node. |
|
2430 |
+ * |
|
2431 |
+ * @return PHP_Depend_Code_ASTUnaryExpression |
|
2432 |
+ * @since 0.9.11 |
|
2433 |
+ */ |
|
2434 |
+ private function _parseVariableByReference() |
|
2435 |
+ { |
|
2436 |
+ $this->_consumeComments(); |
|
2437 |
+ |
|
2438 |
+ $this->_tokenStack->push(); |
|
2439 |
+ |
|
2440 |
+ $token = $this->_consumeToken(self::T_BITWISE_AND); |
| 2353 |
2441 |
|
|
2442 |
+ $expression = $this->_builder->buildASTUnaryExpression($token->image); |
|
2443 |
+ $expression->addChild($this->_parseVariable()); |
|
2444 |
+ |
|
2445 |
+ return $this->_setNodePositionsAndReturn($expression); |
|
2446 |
+ } |
|
2447 |
+ |
| 2354 |
2448 |
/** |
| 2355 |
2449 |
* This method parses a simple PHP variable. |
| 2356 |
2450 |
* |
|
2 |
+<?php |
|
3 |
+/** |
|
4 |
+ * This file is part of PHP_Depend. |
|
5 |
+ * |
|
6 |
+ * PHP Version 5 |
|
7 |
+ * |
|
8 |
+ * Copyright (c) 2008-2010, Manuel Pichler <mapi@pdepend.org>. |
|
9 |
+ * All rights reserved. |
|
10 |
+ * |
|
11 |
+ * Redistribution and use in source and binary forms, with or without |
|
12 |
+ * modification, are permitted provided that the following conditions |
|
13 |
+ * are met: |
|
14 |
+ * |
|
15 |
+ * * Redistributions of source code must retain the above copyright |
|
16 |
+ * notice, this list of conditions and the following disclaimer. |
|
17 |
+ * |
|
18 |
+ * * Redistributions in binary form must reproduce the above copyright |
|
19 |
+ * notice, this list of conditions and the following disclaimer in |
|
20 |
+ * the documentation and/or other materials provided with the |
|
21 |
+ * distribution. |
|
22 |
+ * |
|
23 |
+ * * Neither the name of Manuel Pichler nor the names of his |
|
24 |
+ * contributors may be used to endorse or promote products derived |
|
25 |
+ * from this software without specific prior written permission. |
|
26 |
+ * |
|
27 |
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
28 |
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
29 |
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
30 |
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
31 |
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
32 |
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
33 |
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
34 |
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
35 |
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
36 |
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
37 |
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
38 |
+ * POSSIBILITY OF SUCH DAMAGE. |
|
39 |
+ * |
|
40 |
+ * @category PHP |
|
41 |
+ * @package PHP_Depend |
|
42 |
+ * @subpackage Code |
|
43 |
+ * @author Manuel Pichler <mapi@pdepend.org> |
|
44 |
+ * @copyright 2008-2010 Manuel Pichler. All rights reserved. |
|
45 |
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
46 |
+ * @version SVN: $Id$ |
|
47 |
+ * @link http://www.pdepend.org/ |
|
48 |
+ * @since 0.9.11 |
|
49 |
+ */ |
|
50 |
+ |
|
51 |
+/** |
|
52 |
+ * This class represents an unary expression node. |
|
53 |
+ * |
|
54 |
+ * <code> |
|
55 |
+ * // - |
|
56 |
+ * -$foo |
|
57 |
+ * // - |
|
58 |
+ * |
|
59 |
+ * // - |
|
60 |
+ * +$foo |
|
61 |
+ * // - |
|
62 |
+ * |
|
63 |
+ * // - |
|
64 |
+ * &$foo |
|
65 |
+ * // - |
|
66 |
+ * </code> |
|
67 |
+ * |
|
68 |
+ * @category PHP |
|
69 |
+ * @package PHP_Depend |
|
70 |
+ * @subpackage Code |
|
71 |
+ * @author Manuel Pichler <mapi@pdepend.org> |
|
72 |
+ * @copyright 2008-2010 Manuel Pichler. All rights reserved. |
|
73 |
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
74 |
+ * @version Release: @package_version@ |
|
75 |
+ * @link http://www.pdepend.org/ |
|
76 |
+ * @since 0.9.11 |
|
77 |
+ */ |
|
78 |
+class PHP_Depend_Code_ASTUnaryExpression extends PHP_Depend_Code_ASTNode |
|
79 |
+{ |
|
80 |
+ /** |
|
81 |
+ * Type of this node class. |
|
82 |
+ */ |
|
83 |
+ const CLAZZ = __CLASS__; |
|
84 |
+} |