Skip to content

Commit 8cd2611

Browse files
committed
Added support for "(new|extends|implements) namespace\MyClass"
Signed-off-by: Jan Pecha <[email protected]>
1 parent 60a3591 commit 8cd2611

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

src/PhpDepend.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ private function prev()
269269
*/
270270
private function readName()
271271
{
272-
return $this->expandName($this->readIdentifier());
272+
return $this->expandName($this->readIdentifier(TRUE));
273273
}
274274

275275

@@ -299,9 +299,10 @@ private function readImplements()
299299

300300

301301
/**
302+
* @param bool
302303
* @return string
303304
*/
304-
private function readIdentifier()
305+
private function readIdentifier($readNamespaceKeyword = FALSE)
305306
{
306307
$name = FALSE;
307308
while($token = $this->next())
@@ -311,11 +312,18 @@ private function readIdentifier()
311312
$this->prev();
312313
break;
313314
}
315+
316+
if($readNamespaceKeyword && $token[0] === T_NAMESPACE)
317+
{
318+
$name = '\\' . $this->namespace;
319+
continue;
320+
}
314321

315322
switch($token[0])
316323
{
317324
case T_STRING:
318325
case self::$T_NS_SEPARATOR:
326+
$readNamespaceKeyword = FALSE;
319327
$name .= $token[1];
320328

321329
case T_WHITESPACE:

tests/PhpDepend/PhpDepend.basic-dependencies.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ $phpdepend->parse("<?php
2121
namespace Foo\\Bar;
2222
\$foo = new Foo;
2323
\$bar = new Bar;
24+
\$barfoo = new namespace\BarFoo;
2425
");
2526

2627
Assert::same(array(), $phpdepend->getClasses());
2728
Assert::same(array(
2829
'Foo\\Bar\\Foo',
2930
'Foo\\Bar\\Bar',
31+
'Foo\\Bar\\BarFoo',
3032
), $phpdepend->getDependencies());
3133

3234

tests/PhpDepend/PhpDepend.basic.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,16 @@ Assert::same(array('Foo\\Bar\\MyClass'), $phpdepend->getClasses());
3232
Assert::same(array(), $phpdepend->getDependencies());
3333

3434

35+
// Class definition
36+
$phpdepend->parse("<?php
37+
namespace Foo\\Bar;
38+
class MyClass extends namespace\MyParent implements namespace\MyInterface {
39+
40+
}
41+
");
3542

43+
Assert::same(array('Foo\\Bar\\MyClass'), $phpdepend->getClasses());
44+
Assert::same(array(
45+
'Foo\Bar\MyParent',
46+
'Foo\Bar\MyInterface',
47+
), $phpdepend->getDependencies());

0 commit comments

Comments
 (0)