From bb2c5303ae1149dabcde9709ece6abca4850057b Mon Sep 17 00:00:00 2001 From: Suralc Date: Mon, 1 Jun 2015 18:32:25 +0200 Subject: [PATCH] Add a FunctionLike interface to Methods, Functions and Closures. The elements listed above share common elements like parameters, possible return types and bodies. --- lib/PhpParser/Node/Expr/Closure.php | 19 ++++++++++++- lib/PhpParser/Node/FunctionLike.php | 36 +++++++++++++++++++++++++ lib/PhpParser/Node/Stmt/ClassMethod.php | 19 ++++++++++++- lib/PhpParser/Node/Stmt/Function_.php | 19 ++++++++++++- 4 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 lib/PhpParser/Node/FunctionLike.php diff --git a/lib/PhpParser/Node/Expr/Closure.php b/lib/PhpParser/Node/Expr/Closure.php index f8ace6b..c9264d6 100644 --- a/lib/PhpParser/Node/Expr/Closure.php +++ b/lib/PhpParser/Node/Expr/Closure.php @@ -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; + } } diff --git a/lib/PhpParser/Node/FunctionLike.php b/lib/PhpParser/Node/FunctionLike.php new file mode 100644 index 0000000..f111cde --- /dev/null +++ b/lib/PhpParser/Node/FunctionLike.php @@ -0,0 +1,36 @@ +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; } diff --git a/lib/PhpParser/Node/Stmt/Function_.php b/lib/PhpParser/Node/Stmt/Function_.php index 8e81b70..e1e27ab 100644 --- a/lib/PhpParser/Node/Stmt/Function_.php +++ b/lib/PhpParser/Node/Stmt/Function_.php @@ -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; + } }