Ternary::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
ccs 7
cts 7
cp 1
rs 9.4285
cc 1
eloc 6
nc 1
nop 4
crap 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\Expr\Op;
10
11
use Zicht\Tool\Script\Node\Branch;
12
use Zicht\Tool\Script\Node\Node;
13
use Zicht\Tool\Script\Buffer;
14
15
/**
16
 * Represents a ternary expression
17
 */
18
class Ternary extends Branch
19
{
20
    /**
21
     * Constructor.
22
     *
23
     * @param string $operator
24
     * @param Node $condition
25
     * @param Node $then
26
     * @param Node $else
27
     */
28 3
    public function __construct($operator, $condition, $then, $else)
29
    {
30 3
        parent::__construct();
31 3
        $this->operator = $operator;
0 ignored issues
show
Bug introduced by
The property operator 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...
32 3
        $this->nodes[0] = $condition;
33 3
        $this->nodes[1] = $then;
34 3
        $this->nodes[2] = $else;
35 3
    }
36
37
38
    /**
39
     * @{inheritDoc}
40
     */
41
    public function compile(Buffer $buffer)
42
    {
43
        $this->nodes[0]->compile($buffer);
44
        $buffer->raw('?');
45
        if ($this->nodes[1]) {
46
            $this->nodes[1]->compile($buffer);
47
        }
48
        $buffer->raw(':');
49
        if ($this->nodes[2]) {
50
            $this->nodes[2]->compile($buffer);
51
        } else {
52
            $buffer->raw('null');
53
        }
54
    }
55
}
56