comparison vendor/nikic/php-parser/lib/PhpParser/Builder/FunctionLike.php @ 0:4c8ae668cc8c

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