SetNode::__construct()   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 2
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\Task;
10
11
use Zicht\Tool\Script\Buffer;
12
use Zicht\Tool\Script\Node\Branch;
13
use Zicht\Tool\Util;
14
15
/**
16
 * A node for the "args" section of a task
17
 */
18
class SetNode extends Branch
19
{
20
    /**
21
     * Constructor.
22
     *
23
     * @param string $name
24
     * @param \Zicht\Tool\Script\Node\Node $expr
25
     */
26
    public function __construct($name, $expr)
27
    {
28
        parent::__construct();
29
        $this->nodes[0] = $expr;
30
        $this->name = $name;
0 ignored issues
show
Bug introduced by
The property name does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
31
    }
32
33
34
    /**
35
     * Compiles the arg node.
36
     *
37
     * @param \Zicht\Tool\Script\Buffer $buffer
38
     * @return void
39
     */
40
    public function compile(Buffer $buffer)
41
    {
42
        $name = explode('.', $this->name);
43
        $phpName = Util::toPhp($name);
44
45
        $buffer->write('$z->set(')->raw($phpName)->raw(', ');
46
        $buffer->raw('$z->value(');
47
        $this->nodes[0]->compile($buffer);
48
        $buffer->raw('));')->eol();
49
    }
50
}
51