Assign   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 55
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getAssigns() 0 4 1
A __toString() 0 11 1
A evaluate() 0 12 1
1
<?php
2
3
namespace PeacefulBit\Slate\Parser\Nodes;
4
5
use PeacefulBit\Slate\Core\Evaluator;
6
use PeacefulBit\Slate\Core\Frame;
7
8
class Assign extends Node
9
{
10
    /**
11
     * @var array
12
     */
13
    private $assigns;
14
15
    /**
16
     * @param array $assigns
17
     */
18
    public function __construct(array $assigns)
19
    {
20
        $this->assigns = $assigns;
21
    }
22
23
    /**
24
     * @return array
25
     */
26
    public function getAssigns(): array
27
    {
28
        return $this->assigns;
29
    }
30
31
    /**
32
     * @return string
33
     */
34
    public function __toString()
35
    {
36
        $prefix = '(def ';
37
        $suffix = ')';
38
39
        $groups = array_map(function ($assign) {
40
            return implode(' ', array_map('strval', $assign));
41
        }, $this->getAssigns());
42
43
        return $prefix . implode(' ', $groups) . $suffix;
44
    }
45
46
    /**
47
     * @param Frame $frame
48
     * @return null
49
     */
50
    public function evaluate(Frame $frame)
51
    {
52
        $pairs = $this->getAssigns();
53
54
        array_walk($pairs, function ($pair) use ($frame) {
55
            $value = $frame->evaluate($pair[1]);
56
            $key = $pair[0]->getName();
57
            $frame->set($key, $value);
58
        });
59
60
        return null;
61
    }
62
}
63