Skip to content

Commit c6cc9dd

Browse files
committed
- Fixed #189: Invalid Start/End Line/Column for object method invocation.
1 parent debb5fa commit c6cc9dd

10 files changed

+258
-26
lines changed

PHP/Depend/Parser.php

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3475,18 +3475,40 @@ private function _parseMethodOrPropertyPostfix(PHP_Depend_Code_ASTNode $node)
34753475
switch ($this->tokenizer->peek()) {
34763476

34773477
case self::T_PARENTHESIS_OPEN:
3478-
$postfix = $this->_builder->buildASTMethodPostfix($node->getImage());
3479-
$postfix->addChild($node);
3480-
$postfix->addChild($this->_parseArguments());
3481-
3482-
return $this->_parseOptionalMemberPrimaryPrefix($postfix);
3478+
$postfix = $this->_parseMethodPostfix($node);
3479+
break;
34833480

34843481
default:
34853482
$postfix = $this->_builder->buildASTPropertyPostfix($node->getImage());
34863483
$postfix->addChild($node);
3487-
3488-
return $this->_parseOptionalMemberPrimaryPrefix($postfix);
3484+
break;
34893485
}
3486+
return $this->_parseOptionalMemberPrimaryPrefix($postfix);
3487+
}
3488+
3489+
/**
3490+
* Parses a method postfix node instance.
3491+
*
3492+
* @param PHP_Depend_Code_ASTNode $node Node that represents the image of
3493+
* the method postfix node.
3494+
*
3495+
* @return PHP_Depend_Code_ASTMethodPostfix
3496+
* @since 0.11.0
3497+
*/
3498+
private function _parseMethodPostfix(PHP_Depend_Code_ASTNode $node)
3499+
{
3500+
$args = $this->_parseArguments();
3501+
3502+
$postfix = $this->_builder->buildASTMethodPostfix($node->getImage());
3503+
$postfix->addChild($node);
3504+
$postfix->addChild($args);
3505+
3506+
$postfix->setEndLine($args->getEndLine());
3507+
$postfix->setEndColumn($args->getEndColumn());
3508+
$postfix->setStartLine($node->getStartLine());
3509+
$postfix->setStartColumn($node->getStartColumn());
3510+
3511+
return $postfix;
34903512
}
34913513

34923514
/**

tests/PHP/Depend/Code/ASTMethodPostfixTest.php

Lines changed: 165 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@
4848

4949
require_once dirname(__FILE__) . '/ASTNodeTest.php';
5050

51-
require_once 'PHP/Depend/Code/ASTMethodPostfix.php';
52-
require_once 'PHP/Depend/ConstantsI.php';
53-
5451
/**
5552
* Test case for the {@link PHP_Depend_Code_ASTMethodPostfix} class.
5653
*
@@ -65,6 +62,142 @@
6562
*/
6663
class PHP_Depend_Code_ASTMethodPostfixTest extends PHP_Depend_Code_ASTNodeTest
6764
{
65+
/**
66+
* testObjectMethodPostfixHasExpectedStartLine
67+
*
68+
* @return void
69+
* @covers PHP_Depend_Parser
70+
* @covers PHP_Depend_Builder_Default
71+
* @covers PHP_Depend_Code_ASTMethodPostfix
72+
* @group pdepend
73+
* @group pdepend::ast
74+
* @group unittest
75+
*/
76+
public function testObjectMethodPostfixHasExpectedStartLine()
77+
{
78+
$postfix = $this->_getFirstMethodPostfixInFunction();
79+
self::assertEquals(6, $postfix->getStartLine());
80+
}
81+
82+
/**
83+
* testObjectMethodPostfixHasExpectedStartColumn
84+
*
85+
* @return void
86+
* @covers PHP_Depend_Parser
87+
* @covers PHP_Depend_Builder_Default
88+
* @covers PHP_Depend_Code_ASTMethodPostfix
89+
* @group pdepend
90+
* @group pdepend::ast
91+
* @group unittest
92+
*/
93+
public function testObjectMethodPostfixHasExpectedStartColumn()
94+
{
95+
$postfix = $this->_getFirstMethodPostfixInFunction();
96+
self::assertEquals(13, $postfix->getStartColumn());
97+
}
98+
99+
/**
100+
* testObjectMethodPostfixHasExpectedEndLine
101+
*
102+
* @return void
103+
* @covers PHP_Depend_Parser
104+
* @covers PHP_Depend_Builder_Default
105+
* @covers PHP_Depend_Code_ASTMethodPostfix
106+
* @group pdepend
107+
* @group pdepend::ast
108+
* @group unittest
109+
*/
110+
public function testObjectMethodPostfixHasExpectedEndLine()
111+
{
112+
$postfix = $this->_getFirstMethodPostfixInFunction();
113+
self::assertEquals(7, $postfix->getEndLine());
114+
}
115+
116+
/**
117+
* testObjectMethodPostfixHasExpectedEndColumn
118+
*
119+
* @return void
120+
* @covers PHP_Depend_Parser
121+
* @covers PHP_Depend_Builder_Default
122+
* @covers PHP_Depend_Code_ASTMethodPostfix
123+
* @group pdepend
124+
* @group pdepend::ast
125+
* @group unittest
126+
*/
127+
public function testObjectMethodPostfixHasExpectedEndColumn()
128+
{
129+
$postfix = $this->_getFirstMethodPostfixInFunction();
130+
self::assertEquals(17, $postfix->getEndColumn());
131+
}
132+
133+
/**
134+
* testClassMethodPostfixHasExpectedStartLine
135+
*
136+
* @return void
137+
* @covers PHP_Depend_Parser
138+
* @covers PHP_Depend_Builder_Default
139+
* @covers PHP_Depend_Code_ASTMethodPostfix
140+
* @group pdepend
141+
* @group pdepend::ast
142+
* @group unittest
143+
*/
144+
public function testClassMethodPostfixHasExpectedStartLine()
145+
{
146+
$postfix = $this->_getFirstMethodPostfixInFunction();
147+
self::assertEquals(6, $postfix->getStartLine());
148+
}
149+
150+
/**
151+
* testClassMethodPostfixHasExpectedStartColumn
152+
*
153+
* @return void
154+
* @covers PHP_Depend_Parser
155+
* @covers PHP_Depend_Builder_Default
156+
* @covers PHP_Depend_Code_ASTMethodPostfix
157+
* @group pdepend
158+
* @group pdepend::ast
159+
* @group unittest
160+
*/
161+
public function testClassMethodPostfixHasExpectedStartColumn()
162+
{
163+
$postfix = $this->_getFirstMethodPostfixInFunction();
164+
self::assertEquals(13, $postfix->getStartColumn());
165+
}
166+
167+
/**
168+
* testClassMethodPostfixHasExpectedEndLine
169+
*
170+
* @return void
171+
* @covers PHP_Depend_Parser
172+
* @covers PHP_Depend_Builder_Default
173+
* @covers PHP_Depend_Code_ASTMethodPostfix
174+
* @group pdepend
175+
* @group pdepend::ast
176+
* @group unittest
177+
*/
178+
public function testClassMethodPostfixHasExpectedEndLine()
179+
{
180+
$postfix = $this->_getFirstMethodPostfixInFunction();
181+
self::assertEquals(7, $postfix->getEndLine());
182+
}
183+
184+
/**
185+
* testClassMethodPostfixHasExpectedEndColumn
186+
*
187+
* @return void
188+
* @covers PHP_Depend_Parser
189+
* @covers PHP_Depend_Builder_Default
190+
* @covers PHP_Depend_Code_ASTMethodPostfix
191+
* @group pdepend
192+
* @group pdepend::ast
193+
* @group unittest
194+
*/
195+
public function testClassMethodPostfixHasExpectedEndColumn()
196+
{
197+
$postfix = $this->_getFirstMethodPostfixInFunction();
198+
self::assertEquals(17, $postfix->getEndColumn());
199+
}
200+
68201
/**
69202
* testAcceptInvokesVisitOnGivenVisitor
70203
*
@@ -129,7 +262,7 @@ public function testMethodPostfixStructureForSimpleInvocation()
129262
PHP_Depend_Code_ASTArguments::CLAZZ
130263
);
131264

132-
$this->assertGraphEquals($prefix, $expected);
265+
self::assertGraphEquals($prefix, $expected);
133266
}
134267

135268
/**
@@ -153,7 +286,7 @@ public function testMethodPostfixStructureForVariableInvocation()
153286
PHP_Depend_Code_ASTArguments::CLAZZ
154287
);
155288

156-
$this->assertGraphEquals($prefix, $expected);
289+
self::assertGraphEquals($prefix, $expected);
157290
}
158291

159292
/**
@@ -178,7 +311,7 @@ public function testMethodPostfixStructureForVariableVariableInvocation()
178311
PHP_Depend_Code_ASTArguments::CLAZZ
179312
);
180313

181-
$this->assertGraphEquals($prefix, $expected);
314+
self::assertGraphEquals($prefix, $expected);
182315
}
183316

184317
/**
@@ -203,7 +336,7 @@ public function testMethodPostfixStructureForCompoundVariableInvocation()
203336
PHP_Depend_Code_ASTArguments::CLAZZ
204337
);
205338

206-
$this->assertGraphEquals($prefix, $expected);
339+
self::assertGraphEquals($prefix, $expected);
207340
}
208341

209342
/**
@@ -227,7 +360,7 @@ public function testMethodPostfixStructureForSimpleStaticInvocation()
227360
PHP_Depend_Code_ASTArguments::CLAZZ
228361
);
229362

230-
$this->assertGraphEquals($prefix, $expected);
363+
self::assertGraphEquals($prefix, $expected);
231364
}
232365

233366
/**
@@ -251,7 +384,7 @@ public function testMethodPostfixStructureForVariableStaticInvocation()
251384
PHP_Depend_Code_ASTArguments::CLAZZ
252385
);
253386

254-
$this->assertGraphEquals($prefix, $expected);
387+
self::assertGraphEquals($prefix, $expected);
255388
}
256389

257390
/**
@@ -276,7 +409,7 @@ public function testMethodPostfixStructureForVariableVariableStaticInvocation()
276409
PHP_Depend_Code_ASTArguments::CLAZZ
277410
);
278411

279-
$this->assertGraphEquals($prefix, $expected);
412+
self::assertGraphEquals($prefix, $expected);
280413
}
281414

282415
/**
@@ -301,7 +434,7 @@ public function testMethodPostfixStructureForCompoundVariableStaticInvocation()
301434
PHP_Depend_Code_ASTArguments::CLAZZ,
302435
);
303436

304-
$this->assertGraphEquals($prefix, $expected);
437+
self::assertGraphEquals($prefix, $expected);
305438
}
306439

307440
/**
@@ -328,7 +461,7 @@ public function testMethodPostfixStructureForVariableCompoundVariableStaticInvoc
328461
PHP_Depend_Code_ASTArguments::CLAZZ,
329462
);
330463

331-
$this->assertGraphEquals($prefix, $expected);
464+
self::assertGraphEquals($prefix, $expected);
332465
}
333466

334467
/**
@@ -356,7 +489,7 @@ public function testMethodPostfixStructureForStaticInvocationWithConsecutiveInvo
356489
PHP_Depend_Code_ASTArguments::CLAZZ
357490
);
358491

359-
$this->assertGraphEquals($prefix, $expected);
492+
self::assertGraphEquals($prefix, $expected);
360493
}
361494

362495
/**
@@ -380,7 +513,7 @@ public function testMethodPostfixStructureForStaticInvocationOnVariable()
380513
PHP_Depend_Code_ASTArguments::CLAZZ
381514
);
382515

383-
$this->assertGraphEquals($prefix, $expected);
516+
self::assertGraphEquals($prefix, $expected);
384517
}
385518

386519
/**
@@ -404,7 +537,7 @@ public function testMethodPostfixStructureForSelfInvocation()
404537
PHP_Depend_Code_ASTArguments::CLAZZ,
405538
);
406539

407-
$this->assertGraphEquals($prefix, $expected);
540+
self::assertGraphEquals($prefix, $expected);
408541
}
409542

410543
/**
@@ -428,7 +561,7 @@ public function testMethodPostfixStructureForParentInvocation()
428561
PHP_Depend_Code_ASTArguments::CLAZZ,
429562
);
430563

431-
$this->assertGraphEquals($prefix, $expected);
564+
self::assertGraphEquals($prefix, $expected);
432565
}
433566

434567
/**
@@ -452,7 +585,7 @@ public function testMethodPostfixGraphForStaticReferenceInvocation()
452585
PHP_Depend_Code_ASTArguments::CLAZZ,
453586
);
454587

455-
$this->assertGraphEquals($prefix, $expected);
588+
self::assertGraphEquals($prefix, $expected);
456589
}
457590

458591
/**
@@ -482,7 +615,7 @@ public function testMethodPostfixGraphForVariableArrayElementInvocation()
482615
PHP_Depend_Code_ASTArguments::CLAZZ,
483616
);
484617

485-
$this->assertGraphEquals($prefix, $expected);
618+
self::assertGraphEquals($prefix, $expected);
486619
}
487620

488621
/**
@@ -512,7 +645,20 @@ public function testMethodPostfixGraphForPropertyArrayElementInvocation()
512645
PHP_Depend_Code_ASTArguments::CLAZZ,
513646
);
514647

515-
$this->assertGraphEquals($prefix, $expected);
648+
self::assertGraphEquals($prefix, $expected);
649+
}
650+
651+
/**
652+
* Returns a node instance for the currently executed test case.
653+
*
654+
* @return PHP_Depend_Code_ASTMethodPostfix
655+
*/
656+
private function _getFirstMethodPostfixInFunction()
657+
{
658+
return $this->getFirstNodeOfTypeInFunction(
659+
self::getCallingTestMethod(),
660+
PHP_Depend_Code_ASTMethodPostfix::CLAZZ
661+
);
516662
}
517663

518664
/**
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
function testClassMethodPostfixHasExpectedEndColumn()
3+
{
4+
return ClassMethodPostfix
5+
::
6+
foo(
7+
);
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
function testClassMethodPostfixHasExpectedEndLine()
3+
{
4+
return ClassMethodPostfix
5+
::
6+
foo(
7+
);
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
function testClassMethodPostfixHasExpectedStartColumn()
3+
{
4+
return ClassMethodPostfix
5+
::
6+
foo(
7+
);
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
function testClassMethodPostfixHasExpectedStartLine()
3+
{
4+
return ClassMethodPostfix
5+
::
6+
foo(
7+
);
8+
}

0 commit comments

Comments
 (0)