With   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 48
ccs 0
cts 18
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A beforeScript() 0 6 1
A afterScript() 0 4 1
A compile() 0 3 1
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
14
/**
15
 * Class With
16
 *
17
 * @package Zicht\Tool\Script\Node\Script
18
 */
19
class With extends Branch implements Annotation
20
{
21
    /**
22
     * Construct the decorator with the specified expression as the first and only child node.
23
     *
24
     * @param \Zicht\Tool\Script\Node\Node $expr
25
     * @param string $name
26
     */
27
    public function __construct($expr, $name)
28
    {
29
        parent::__construct(array($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
     * Allows the annotation to modify the buffer before the script is compiled.
35
     *
36
     * @param Buffer $buffer
37
     * @return void
38
     */
39
    public function beforeScript(Buffer $buffer)
40
    {
41
        $buffer->write(sprintf('$z->push(\'%s\', ', $this->name));
42
        $this->nodes[0]->compile($buffer);
43
        $buffer->write(');');
44
    }
45
46
    /**
47
     * Allows the annotation to modify the buffer after the script is compiled.
48
     *
49
     * @param Buffer $buffer
50
     * @return void
51
     */
52
    public function afterScript(Buffer $buffer)
53
    {
54
        $buffer->write(sprintf('$z->pop(\'%s\');', $this->name));
55
    }
56
57
    /**
58
     * Compiles the node into the buffer.
59
     *
60
     * @param \Zicht\Tool\Script\Buffer $buffer
61
     * @return void
62
     */
63
    public function compile(Buffer $buffer)
64
    {
65
    }
66
}
67