FunctionLike::makeReturnByRef()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace PhpParser\Builder;
4
5
use PhpParser;
6
use PhpParser\Node;
7
use PhpParser\Node\Stmt;
8
9
abstract class FunctionLike extends Declaration
10
{
11
    protected $returnByRef = false;
12
    protected $params = array();
13
14
    /**
15
     * Make the function return by reference.
16
     *
17
     * @return $this The builder instance (for fluid interface)
18
     */
19
    public function makeReturnByRef() {
20
        $this->returnByRef = true;
21
22
        return $this;
23
    }
24
25
    /**
26
     * Adds a parameter.
27
     *
28
     * @param Node\Param|Param $param The parameter to add
29
     *
30
     * @return $this The builder instance (for fluid interface)
31
     */
32
    public function addParam($param) {
33
        $param = $this->normalizeNode($param);
34
35
        if (!$param instanceof Node\Param) {
36
            throw new \LogicException(sprintf('Expected parameter node, got "%s"', $param->getType()));
37
        }
38
39
        $this->params[] = $param;
40
41
        return $this;
42
    }
43
44
    /**
45
     * Adds multiple parameters.
46
     *
47
     * @param array $params The parameters to add
48
     *
49
     * @return $this The builder instance (for fluid interface)
50
     */
51
    public function addParams(array $params) {
52
        foreach ($params as $param) {
53
            $this->addParam($param);
54
        }
55
56
        return $this;
57
    }
58
}