Ternary   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 36.84%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 38
ccs 7
cts 19
cp 0.3684
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A compile() 0 14 3
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