mirror of
https://github.com/danog/PHP-Parser.git
synced 2024-11-26 20:04:48 +01:00
Add a FunctionLike interface to Methods, Functions and Closures.
The elements listed above share common elements like parameters, possible return types and bodies.
This commit is contained in:
parent
69c00ebbe4
commit
bb2c5303ae
@ -4,8 +4,9 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
|
||||
class Closure extends Expr
|
||||
class Closure extends Expr implements FunctionLike
|
||||
{
|
||||
/** @var bool Whether the closure is static */
|
||||
public $static;
|
||||
@ -45,4 +46,20 @@ class Closure extends Expr
|
||||
public function getSubNodeNames() {
|
||||
return array('static', 'byRef', 'params', 'uses', 'returnType', 'stmts');
|
||||
}
|
||||
|
||||
public function returnsByRef() {
|
||||
return $this->byRef;
|
||||
}
|
||||
|
||||
public function getParams() {
|
||||
return $this->params;
|
||||
}
|
||||
|
||||
public function getReturnType() {
|
||||
return $this->returnType;
|
||||
}
|
||||
|
||||
public function getStmts() {
|
||||
return $this->stmts;
|
||||
}
|
||||
}
|
||||
|
36
lib/PhpParser/Node/FunctionLike.php
Normal file
36
lib/PhpParser/Node/FunctionLike.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace PhpParser\Node;
|
||||
|
||||
use PhpParser\Node;
|
||||
|
||||
interface FunctionLike extends Node
|
||||
{
|
||||
/**
|
||||
* Whether to return by reference
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function returnsByRef();
|
||||
|
||||
/**
|
||||
* List of parameters
|
||||
*
|
||||
* @return Node\Param[]
|
||||
*/
|
||||
public function getParams();
|
||||
|
||||
/**
|
||||
* Get the declared return type or null
|
||||
*
|
||||
* @return null|string|Node\Name[]
|
||||
*/
|
||||
public function getReturnType();
|
||||
|
||||
/**
|
||||
* The function body
|
||||
*
|
||||
* @return Node\Stmt[]
|
||||
*/
|
||||
public function getStmts();
|
||||
}
|
@ -3,9 +3,10 @@
|
||||
namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Error;
|
||||
|
||||
class ClassMethod extends Node\Stmt
|
||||
class ClassMethod extends Node\Stmt implements FunctionLike
|
||||
{
|
||||
/** @var int Type */
|
||||
public $type;
|
||||
@ -57,6 +58,22 @@ class ClassMethod extends Node\Stmt
|
||||
return array('type', 'byRef', 'name', 'params', 'returnType', 'stmts');
|
||||
}
|
||||
|
||||
public function returnsByRef() {
|
||||
return $this->byRef;
|
||||
}
|
||||
|
||||
public function getParams() {
|
||||
return $this->params;
|
||||
}
|
||||
|
||||
public function getReturnType() {
|
||||
return $this->returnType;
|
||||
}
|
||||
|
||||
public function getStmts() {
|
||||
return $this->stmts;
|
||||
}
|
||||
|
||||
public function isPublic() {
|
||||
return ($this->type & Class_::MODIFIER_PUBLIC) !== 0 || $this->type === 0;
|
||||
}
|
||||
|
@ -3,8 +3,9 @@
|
||||
namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
|
||||
class Function_ extends Node\Stmt
|
||||
class Function_ extends Node\Stmt implements FunctionLike
|
||||
{
|
||||
/** @var bool Whether function returns by reference */
|
||||
public $byRef;
|
||||
@ -40,4 +41,20 @@ class Function_ extends Node\Stmt
|
||||
public function getSubNodeNames() {
|
||||
return array('byRef', 'name', 'params', 'returnType', 'stmts');
|
||||
}
|
||||
|
||||
public function returnsByRef() {
|
||||
return $this->byRef;
|
||||
}
|
||||
|
||||
public function getParams() {
|
||||
return $this->params;
|
||||
}
|
||||
|
||||
public function getReturnType() {
|
||||
return $this->returnType;
|
||||
}
|
||||
|
||||
public function getStmts() {
|
||||
return $this->stmts;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user