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

CodeFileGenerator   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 51
Duplicated Lines 21.57 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 66.67%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 9
c 4
b 0
f 1
lcom 1
cbo 3
dl 11
loc 51
ccs 20
cts 30
cp 0.6667
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfig() 0 3 1
B generate() 0 26 5
A __construct() 11 11 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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