2017-08-18 22:57:27 +02:00
|
|
|
<?php declare(strict_types=1);
|
2011-05-27 18:20:44 +02:00
|
|
|
|
2014-02-06 14:44:16 +01:00
|
|
|
namespace PhpParser\Node\Stmt;
|
|
|
|
|
|
|
|
use PhpParser\Node;
|
2015-06-01 18:32:25 +02:00
|
|
|
use PhpParser\Node\FunctionLike;
|
2014-02-06 14:44:16 +01:00
|
|
|
|
2022-08-28 22:57:06 +02:00
|
|
|
class Function_ extends Node\Stmt implements FunctionLike {
|
2015-02-28 18:44:28 +01:00
|
|
|
/** @var bool Whether function returns by reference */
|
2023-08-16 21:18:30 +02:00
|
|
|
public bool $byRef;
|
2017-04-28 19:09:39 +02:00
|
|
|
/** @var Node\Identifier Name */
|
2023-08-16 21:18:30 +02:00
|
|
|
public Node\Identifier $name;
|
2015-02-28 18:44:28 +01:00
|
|
|
/** @var Node\Param[] Parameters */
|
2023-08-16 21:18:30 +02:00
|
|
|
public array $params;
|
2021-09-02 18:35:05 +02:00
|
|
|
/** @var null|Node\Identifier|Node\Name|Node\ComplexType Return type */
|
2023-08-17 21:35:48 +02:00
|
|
|
public ?Node $returnType;
|
2017-01-19 22:46:28 +01:00
|
|
|
/** @var Node\Stmt[] Statements */
|
2023-08-16 21:18:30 +02:00
|
|
|
public array $stmts;
|
2020-09-13 21:01:17 +02:00
|
|
|
/** @var Node\AttributeGroup[] PHP attribute groups */
|
2023-08-16 21:18:30 +02:00
|
|
|
public array $attrGroups;
|
2015-02-28 18:44:28 +01:00
|
|
|
|
2021-12-06 21:21:44 +01:00
|
|
|
/** @var Node\Name|null Namespaced name (if using NameResolver) */
|
2023-08-16 21:18:30 +02:00
|
|
|
public ?Node\Name $namespacedName;
|
2021-11-27 21:02:58 +01:00
|
|
|
|
2011-10-28 19:06:24 +02:00
|
|
|
/**
|
|
|
|
* Constructs a function node.
|
|
|
|
*
|
2017-04-28 19:09:39 +02:00
|
|
|
* @param string|Node\Identifier $name Name
|
2022-09-17 17:12:55 +02:00
|
|
|
* @param array{
|
|
|
|
* byRef?: bool,
|
|
|
|
* params?: Node\Param[],
|
2023-05-20 22:12:04 +02:00
|
|
|
* returnType?: null|Node\Identifier|Node\Name|Node\ComplexType,
|
2022-09-17 17:12:55 +02:00
|
|
|
* stmts?: Node\Stmt[],
|
|
|
|
* attrGroups?: Node\AttributeGroup[],
|
|
|
|
* } $subNodes Array of the following optional subnodes:
|
|
|
|
* 'byRef' => false : Whether to return by reference
|
|
|
|
* 'params' => array(): Parameters
|
|
|
|
* 'returnType' => null : Return type
|
|
|
|
* 'stmts' => array(): Statements
|
|
|
|
* 'attrGroups' => array(): PHP attribute groups
|
2022-09-11 20:51:31 +02:00
|
|
|
* @param array<string, mixed> $attributes Additional attributes
|
2011-10-28 19:06:24 +02:00
|
|
|
*/
|
2017-08-13 14:06:08 +02:00
|
|
|
public function __construct($name, array $subNodes = [], array $attributes = []) {
|
2019-05-12 14:55:21 +02:00
|
|
|
$this->attributes = $attributes;
|
2017-04-24 22:32:40 +02:00
|
|
|
$this->byRef = $subNodes['byRef'] ?? false;
|
2017-04-28 19:09:39 +02:00
|
|
|
$this->name = \is_string($name) ? new Node\Identifier($name) : $name;
|
2017-08-13 14:06:08 +02:00
|
|
|
$this->params = $subNodes['params'] ?? [];
|
2023-05-20 22:12:04 +02:00
|
|
|
$this->returnType = $subNodes['returnType'] ?? null;
|
2017-08-13 14:06:08 +02:00
|
|
|
$this->stmts = $subNodes['stmts'] ?? [];
|
2020-09-13 21:01:17 +02:00
|
|
|
$this->attrGroups = $subNodes['attrGroups'] ?? [];
|
2015-02-28 18:44:28 +01:00
|
|
|
}
|
|
|
|
|
2022-08-28 22:57:06 +02:00
|
|
|
public function getSubNodeNames(): array {
|
2020-09-13 21:01:17 +02:00
|
|
|
return ['attrGroups', 'byRef', 'name', 'params', 'returnType', 'stmts'];
|
2011-10-28 19:06:24 +02:00
|
|
|
}
|
2015-06-01 18:32:25 +02:00
|
|
|
|
2022-08-28 22:57:06 +02:00
|
|
|
public function returnsByRef(): bool {
|
2015-06-01 18:32:25 +02:00
|
|
|
return $this->byRef;
|
|
|
|
}
|
|
|
|
|
2022-08-28 22:57:06 +02:00
|
|
|
public function getParams(): array {
|
2015-06-01 18:32:25 +02:00
|
|
|
return $this->params;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getReturnType() {
|
|
|
|
return $this->returnType;
|
|
|
|
}
|
|
|
|
|
2022-08-28 22:57:06 +02:00
|
|
|
public function getAttrGroups(): array {
|
2020-09-13 21:01:17 +02:00
|
|
|
return $this->attrGroups;
|
|
|
|
}
|
|
|
|
|
2017-05-07 19:54:32 +02:00
|
|
|
/** @return Node\Stmt[] */
|
2022-08-28 22:57:06 +02:00
|
|
|
public function getStmts(): array {
|
2015-06-01 18:32:25 +02:00
|
|
|
return $this->stmts;
|
|
|
|
}
|
2020-09-13 21:01:17 +02:00
|
|
|
|
2022-08-28 22:57:06 +02:00
|
|
|
public function getType(): string {
|
2017-11-12 21:25:57 +01:00
|
|
|
return 'Stmt_Function';
|
|
|
|
}
|
2015-02-28 18:44:28 +01:00
|
|
|
}
|