mirror of
https://github.com/nikic/PHP-Parser.git
synced 2025-01-17 23:28:15 +01:00
Allow null in ClassMethod::getStmts()
This commit is contained in:
parent
b1af3d1f7d
commit
73dc35cbbd
@ -60,6 +60,7 @@ class Closure extends Expr implements FunctionLike
|
||||
return $this->returnType;
|
||||
}
|
||||
|
||||
/** @return Node\Stmt[] */
|
||||
public function getStmts() : array {
|
||||
return $this->stmts;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ interface FunctionLike extends Node
|
||||
/**
|
||||
* The function body
|
||||
*
|
||||
* @return Node\Stmt[]
|
||||
* @return Node\Stmt[]|null
|
||||
*/
|
||||
public function getStmts() : array;
|
||||
public function getStmts();
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ class ClassMethod extends Node\Stmt implements FunctionLike
|
||||
return $this->returnType;
|
||||
}
|
||||
|
||||
public function getStmts() : array {
|
||||
public function getStmts() {
|
||||
return $this->stmts;
|
||||
}
|
||||
|
||||
|
@ -58,6 +58,7 @@ class Function_ extends Node\Stmt implements FunctionLike
|
||||
return $this->returnType;
|
||||
}
|
||||
|
||||
/** @return Node\Stmt[] */
|
||||
public function getStmts() : array {
|
||||
return $this->stmts;
|
||||
}
|
||||
|
@ -2,6 +2,9 @@
|
||||
|
||||
namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Param;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ClassMethodTest extends TestCase
|
||||
@ -93,4 +96,29 @@ class ClassMethodTest extends TestCase
|
||||
array('__debuginfo'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testFunctionLike() {
|
||||
$param = new Param(new Variable('a'));
|
||||
$type = new Name('Foo');
|
||||
$return = new Return_(new Variable('a'));
|
||||
$method = new ClassMethod('test', [
|
||||
'byRef' => false,
|
||||
'params' => [$param],
|
||||
'returnType' => $type,
|
||||
'stmts' => [$return],
|
||||
]);
|
||||
|
||||
$this->assertFalse($method->returnsByRef());
|
||||
$this->assertSame([$param], $method->getParams());
|
||||
$this->assertSame($type, $method->getReturnType());
|
||||
$this->assertSame([$return], $method->getStmts());
|
||||
|
||||
$method = new ClassMethod('test', [
|
||||
'byRef' => true,
|
||||
'stmts' => null,
|
||||
]);
|
||||
|
||||
$this->assertTrue($method->returnsByRef());
|
||||
$this->assertNull($method->getStmts());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user