Conditional::beforeScript()   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 6
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\Script\Node\Script;
10
11
use Zicht\Tool\Script\Buffer;
12
use Zicht\Tool\Script\Node\Branch;
13
use Zicht\Tool\Script\Node\Node;
14
15
/**
16
 * Represents a conditional for a script node.
17
 */
18
class Conditional extends Branch implements Annotation
19
{
20
    /**
21
     * Constructor.
22
     *
23
     * @param Node $node
24
     */
25
    public function __construct($node)
26
    {
27
        parent::__construct();
28
        $this->nodes[0] = $node;
29
    }
30
31
    /**
32
     * @{inheritDoc}
33
     */
34
    public function compile(Buffer $buffer)
35
    {
36
        $this->nodes[0]->compile($buffer);
37
    }
38
39
40
    /**
41
     * @{inheritDoc}
42
     */
43
    public function beforeScript(Buffer $buffer)
44
    {
45
        $buffer->write('if (');
46
        $this->compile($buffer);
47
        $buffer->raw(') {')->eol()->indent(1);
48
    }
49
50
51
    /**
52
     * @{inheritDoc}
53
     */
54
    public function afterScript(Buffer $buffer)
55
    {
56
        $buffer->indent(-1)->writeln('}');
57
    }
58
}
59