1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-12-04 18:28:25 +01:00
PHP-Parser/lib/PhpParser/Node/Stmt/Function_.php

66 lines
2.1 KiB
PHP
Raw Normal View History

<?php
namespace PhpParser\Node\Stmt;
use PhpParser\Node;
use PhpParser\Node\FunctionLike;
/**
* @property Node\Name $namespacedName Namespaced name (if using NameResolver)
*/
class Function_ extends Node\Stmt implements FunctionLike
{
/** @var bool Whether function returns by reference */
public $byRef;
/** @var Node\Identifier Name */
public $name;
/** @var Node\Param[] Parameters */
public $params;
/** @var null|Node\Identifier|Node\Name|Node\NullableType Return type */
public $returnType;
/** @var Node\Stmt[] Statements */
public $stmts;
/**
* Constructs a function node.
*
* @param string|Node\Identifier $name Name
* @param array $subNodes Array of the following optional subnodes:
* 'byRef' => false : Whether to return by reference
* 'params' => array(): Parameters
* 'returnType' => null : Return type
* 'stmts' => array(): Statements
* @param array $attributes Additional attributes
*/
public function __construct($name, array $subNodes = array(), array $attributes = array()) {
2015-05-02 22:17:34 +02:00
parent::__construct($attributes);
2017-04-24 22:32:40 +02:00
$this->byRef = $subNodes['byRef'] ?? false;
$this->name = \is_string($name) ? new Node\Identifier($name) : $name;
2017-04-24 22:32:40 +02:00
$this->params = $subNodes['params'] ?? array();
$returnType = $subNodes['returnType'] ?? null;
$this->returnType = \is_string($returnType) ? new Node\Identifier($returnType) : $returnType;
2017-04-24 22:32:40 +02:00
$this->stmts = $subNodes['stmts'] ?? array();
}
2017-04-28 21:40:59 +02:00
public function getSubNodeNames() : array {
return array('byRef', 'name', 'params', 'returnType', 'stmts');
}
2017-04-28 21:40:59 +02:00
public function returnsByRef() : bool {
return $this->byRef;
}
2017-04-28 21:40:59 +02:00
public function getParams() : array {
return $this->params;
}
public function getReturnType() {
return $this->returnType;
}
2017-05-07 19:54:32 +02:00
/** @return Node\Stmt[] */
2017-04-28 21:40:59 +02:00
public function getStmts() : array {
return $this->stmts;
}
}