ValueBuilderPart   A
last analyzed

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
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