Completed
Push — master ( a1c8e7...7d2da4 )
by Thomas
04:30
created

CodeFileGenerator::generate()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 5.7874

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 26
ccs 13
cts 19
cp 0.6842
rs 8.439
cc 5
eloc 15
nc 16
nop 1
crap 5.7874
1
<?php
2
namespace gossi\codegen\generator;
3
4
use gossi\codegen\model\GenerateableInterface;
5
use gossi\codegen\config\CodeFileGeneratorConfig;
6
use gossi\docblock\Docblock;
7
8
class CodeFileGenerator extends CodeGenerator {
9
10
	/**
11
	 * @param CodeFileGeneratorConfig|array $config
12
	 */
13 4 View Code Duplication
	public function __construct($config = null) {
14 4
		if (is_array($config)) {
15 3
			$this->config = new CodeFileGeneratorConfig($config);
16 4
		} else if ($config instanceof CodeFileGeneratorConfig) {
17
			$this->config = $config;
18
		} else {
19 1
			$this->config = new CodeFileGeneratorConfig();
20
		}
21
22 4
		$this->init();
23 4
	}
24
25
	/**
26
	 * @return CodeFileGeneratorConfig
27
	 */
28
	public function getConfig() {
29
		return $this->config;
30
	}
31
32 4
	public function generate(GenerateableInterface $model) {
33 4
		$content = "<?php\n";
34
35 4
		$comment = $this->config->getHeaderComment();
36 4
		if (!empty($comment)) {
37
			$docblock = new Docblock();
38
			$docblock->setLongDescription($comment);
39
			$content .= str_replace('/**', '/*', $docblock->toString()) . "\n";
40
		}
41
42 4
		if ($this->config->getHeaderDocblock() instanceof Docblock) {
43
			$content .= $this->config->getHeaderDocblock()->toString() . "\n";
44
		}
45
46 4
		if ($this->config->getDeclareStrictTypes()) {
47 1
			$content .= "declare(strict_types=1);\n\n";
48 1
		}
49
50 4
		$content .= parent::generate($model);
51
52 4
		if ($this->config->getBlankLineAtEnd()) {
53 4
			$content .= "\n";
54 4
		}
55
56 4
		return $content;
57
	}
58
}
59