Completed
Push — master ( 55b21a...aec22b )
by Thomas
06:20
created

ValueBuilderPart::writeValue()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 13
ccs 8
cts 8
cp 1
rs 9.4285
cc 3
eloc 9
nc 3
nop 1
crap 3
1
<?php
2
namespace gossi\codegen\generator\builder\parts;
3
4
use gossi\codegen\model\ValueInterface;
5
use gossi\codegen\model\PhpConstant;
6
7
trait ValueBuilderPart {
8
9 6
	private function writeValue(ValueInterface $model) {
10 6
		if ($model->isExpression()) {
11 4
			$this->writer->write($model->getExpression());
1 ignored issue
show
Bug introduced by
The property writer 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...
12
		} else {
13 6
			$value = $model->getValue();
14
15 6
			if ($value instanceof PhpConstant) {
16 3
				$this->writer->write($value->getName());
17
			} else {
18 6
				$this->writer->write($this->exportVar($value));
19
			}
20
		}
21 6
	}
22
	
23 6
	private function exportVar($value) {
24
		// Simply to be sure a null value is displayed in lowercase.
25 6
		if (is_null($value)) {
26 3
			return 'null';
27
		}
28
		
29 6
		return var_export($value, true);
30
	}
31
}