ValueBuilderPart::writeValue()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

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