| 1 |
<?php |
| 2 |
// phpcs:ignoreFile -- Bundled third-party (Mozart) dependency; exempt from plugin coding standards. |
| 3 |
|
| 4 |
namespace WPDeveloper\BetterDocs\Dependencies\PhpParser\Builder; |
| 5 |
|
| 6 |
use WPDeveloper\BetterDocs\Dependencies\PhpParser; |
| 7 |
use WPDeveloper\BetterDocs\Dependencies\PhpParser\Node; |
| 8 |
|
| 9 |
abstract class FunctionLike extends Declaration |
| 10 |
{ |
| 11 |
protected $returnByRef = false; |
| 12 |
protected $params = array(); |
| 13 |
|
| 14 |
/** @var string|Node\Name|Node\NullableType|null */ |
| 15 |
protected $returnType = null; |
| 16 |
|
| 17 |
/** |
| 18 |
* Make the function return by reference. |
| 19 |
* |
| 20 |
* @return $this The builder instance (for fluid interface) |
| 21 |
*/ |
| 22 |
public function makeReturnByRef() { |
| 23 |
$this->returnByRef = true; |
| 24 |
|
| 25 |
return $this; |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Adds a parameter. |
| 30 |
* |
| 31 |
* @param Node\Param|Param $param The parameter to add |
| 32 |
* |
| 33 |
* @return $this The builder instance (for fluid interface) |
| 34 |
*/ |
| 35 |
public function addParam($param) { |
| 36 |
$param = $this->normalizeNode($param); |
| 37 |
|
| 38 |
if (!$param instanceof Node\Param) { |
| 39 |
throw new \LogicException(sprintf('Expected parameter node, got "%s"', $param->getType())); |
| 40 |
} |
| 41 |
|
| 42 |
$this->params[] = $param; |
| 43 |
|
| 44 |
return $this; |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Adds multiple parameters. |
| 49 |
* |
| 50 |
* @param array $params The parameters to add |
| 51 |
* |
| 52 |
* @return $this The builder instance (for fluid interface) |
| 53 |
*/ |
| 54 |
public function addParams(array $params) { |
| 55 |
foreach ($params as $param) { |
| 56 |
$this->addParam($param); |
| 57 |
} |
| 58 |
|
| 59 |
return $this; |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Sets the return type for PHP 7. |
| 64 |
* |
| 65 |
* @param string|Node\Name|Node\NullableType $type One of array, callable, string, int, float, bool, iterable, |
| 66 |
* or a class/interface name. |
| 67 |
* |
| 68 |
* @return $this The builder instance (for fluid interface) |
| 69 |
*/ |
| 70 |
public function setReturnType($type) |
| 71 |
{ |
| 72 |
$this->returnType = $this->normalizeType($type); |
| 73 |
|
| 74 |
return $this; |
| 75 |
} |
| 76 |
} |
| 77 |
|