mirror of
https://github.com/danog/PHP-Parser.git
synced 2024-11-30 04:19:30 +01:00
add getTraitUses() method to ClassLike
This commit is contained in:
parent
005bb1dba7
commit
006acba066
@ -14,6 +14,19 @@ abstract class ClassLike extends Node\Stmt
|
||||
/** @var Node\Stmt[] Statements */
|
||||
public $stmts;
|
||||
|
||||
/**
|
||||
* @return TraitUse[]
|
||||
*/
|
||||
public function getTraitUses() : array {
|
||||
$traitUses = [];
|
||||
foreach ($this->stmts as $stmt) {
|
||||
if ($stmt instanceof TraitUse) {
|
||||
$traitUses[] = $stmt;
|
||||
}
|
||||
}
|
||||
return $traitUses;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ClassConst[]
|
||||
*/
|
||||
|
@ -22,6 +22,22 @@ class ClassTest extends \PHPUnit\Framework\TestCase
|
||||
$this->assertFalse($class->isFinal());
|
||||
}
|
||||
|
||||
public function testGetTraitUses() {
|
||||
$traitUses = [
|
||||
new TraitUse([new Trait_('foo')]),
|
||||
new TraitUse([new Trait_('bar')]),
|
||||
];
|
||||
$class = new Class_('Foo', [
|
||||
'stmts' => [
|
||||
$traitUses[0],
|
||||
new ClassMethod('fooBar'),
|
||||
$traitUses[1],
|
||||
]
|
||||
]);
|
||||
|
||||
$this->assertSame($traitUses, $class->getTraitUses());
|
||||
}
|
||||
|
||||
public function testGetMethods() {
|
||||
$methods = [
|
||||
new ClassMethod('foo'),
|
||||
|
Loading…
Reference in New Issue
Block a user