Declaration::compileBody()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * For licensing information, please see the LICENSE file accompanied with this file.
4
 *
5
 * @author Gerard van Helden <[email protected]>
6
 * @copyright 2012 Gerard van Helden <http://melp.nl>
7
 */
8
9
namespace Zicht\Tool\Container;
10
11
use Zicht\Tool\Script\Buffer;
12
use Zicht\Tool\Script\Node\Node;
13
14
/**
15
 * Represents a value declaration in the container context.
16
 */
17
class Declaration implements Node
18
{
19
    protected $path;
20
    protected $expr;
21
22
    /**
23
     * Constructor.
24
     *
25
     * @param array $path
26
     * @param null|Node $value
27
     */
28
    public function __construct(array $path, Node $value = null)
29
    {
30
        $this->path = $path;
31
        $this->expr = $value;
32
    }
33
34
    /**
35
     * @{inheritDoc}
36
     */
37
    public function compile(Buffer $buffer)
38
    {
39
        $buffer
40
            ->write('$z->decl(')->asPhp($this->path)->raw(', function($z) {')->eol()
41
            ->indent(1);
42
        $this->compileBody($buffer);
43
        $buffer->eol()->indent(-1)->writeln('});');
44
    }
45
46
47
    /**
48
     * Compiles the definition body
49
     *
50
     * @param \Zicht\Tool\Script\Buffer $buffer
51
     * @return void
52
     */
53
    protected function compileBody(Buffer $buffer)
54
    {
55
        $buffer->write('return ');
56
        $this->expr->compile($buffer);
57
        $buffer->raw(';');
58
    }
59
}
60