CallExpression::close()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace PeacefulBit\Slate\Parser\Nodes;
4
5
use function Nerd\Common\Strings\toString;
6
7
use PeacefulBit\Slate\Core\Frame;
8
use PeacefulBit\Slate\Exceptions\EvaluatorException;
9
10
class CallExpression extends Node
11
{
12
    /**
13
     * @var Node
14
     */
15
    private $callee;
16
17
    /**
18
     * @var Node[]
19
     */
20
    private $arguments;
21
22
    /**
23
     * @param Node $callee
24
     * @param Node[] $arguments
25
     */
26
    public function __construct(Node $callee, array $arguments)
27
    {
28
        $this->callee = $callee;
29
        $this->arguments = $arguments;
30
    }
31
32
    /**
33
     * @return Node
34
     */
35
    public function getCallee(): Node
36
    {
37
        return $this->callee;
38
    }
39
40
    /**
41
     * @return Node[]
42
     */
43
    public function getArguments(): array
44
    {
45
        return $this->arguments;
46
    }
47
48
    /**
49
     * @return string
50
     */
51
    public function __toString()
52
    {
53
        $prefix = '(' . strval($this->getCallee()) . ' ';
54
        $suffix = ')';
55
56
        $arguments = array_map('strval', $this->getArguments());
57
58
        return $prefix . implode(' ', $arguments) . $suffix;
59
    }
60
61
    /**
62
     * @param Frame $frame
63
     * @return mixed
64
     * @throws EvaluatorException
65
     */
66
    public function evaluate(Frame $frame)
67
    {
68
        $callee = $frame->evaluate($this->getCallee());
69
70
        if (!$callee instanceof CallableNode) {
71
            throw new EvaluatorException(sprintf("%s is not callable", toString($callee)));
72
        }
73
74
        return $callee->call($frame, $this->getArguments());
75
    }
76
77
    /**
78
     * @param Frame $frame
79
     * @return CallExpression
80
     */
81
    public function close(Frame $frame)
0 ignored issues
show
Unused Code introduced by
The parameter $frame is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
82
    {
83
//        $closedArgs = array_map(function (Node $argument) use ($frame) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
84
//            return $argument instanceof Identifier ? $argument->evaluate($frame) : $argument;
85
//        }, $this->getArguments());
86
87
        return new self($this->getCallee(), $this->getArguments());
88
    }
89
}
90