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

ValueBuilderPart   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 25
ccs 12
cts 12
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A writeValue() 0 13 3
A exportVar() 0 8 2
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
}