mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-11-27 04:24:43 +01:00
Merge branch '1.x'
This commit is contained in:
commit
0ef15c111a
@ -10,6 +10,11 @@ abstract class ClassLike extends Node\Stmt {
|
|||||||
/** @var Node[] Statements */
|
/** @var Node[] Statements */
|
||||||
public $stmts;
|
public $stmts;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all methods defined directly in this class/interface/trait
|
||||||
|
*
|
||||||
|
* @return ClassMethod[]
|
||||||
|
*/
|
||||||
public function getMethods() {
|
public function getMethods() {
|
||||||
$methods = array();
|
$methods = array();
|
||||||
foreach ($this->stmts as $stmt) {
|
foreach ($this->stmts as $stmt) {
|
||||||
@ -19,4 +24,21 @@ abstract class ClassLike extends Node\Stmt {
|
|||||||
}
|
}
|
||||||
return $methods;
|
return $methods;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets method with the given name defined directly in this class/interface/trait.
|
||||||
|
*
|
||||||
|
* @param string $name Name of the method (compared case-insensitively)
|
||||||
|
*
|
||||||
|
* @return ClassMethod|null Method node or null if the method does not exist
|
||||||
|
*/
|
||||||
|
public function getMethod($name) {
|
||||||
|
$lowerName = strtolower($name);
|
||||||
|
foreach ($this->stmts as $stmt) {
|
||||||
|
if ($stmt instanceof ClassMethod && $lowerName === strtolower($stmt->name)) {
|
||||||
|
return $stmt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,4 +39,21 @@ class ClassTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->assertSame($methods, $class->getMethods());
|
$this->assertSame($methods, $class->getMethods());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetMethod() {
|
||||||
|
$methodConstruct = new ClassMethod('__CONSTRUCT');
|
||||||
|
$methodTest = new ClassMethod('test');
|
||||||
|
$class = new Class_('Foo', array(
|
||||||
|
'stmts' => array(
|
||||||
|
new ClassConst(array()),
|
||||||
|
$methodConstruct,
|
||||||
|
new Property(0, array()),
|
||||||
|
$methodTest,
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertSame($methodConstruct, $class->getMethod('__construct'));
|
||||||
|
$this->assertSame($methodTest, $class->getMethod('test'));
|
||||||
|
$this->assertNull($class->getMethod('nonExisting'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user