CodeGenerator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 2
dl 0
loc 55
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A configure() 0 9 3
A getConfig() 0 3 1
A generate() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace gossi\codegen\generator;
5
6
use gossi\codegen\config\CodeGeneratorConfig;
7
use gossi\codegen\model\GenerateableInterface;
8
9
/**
10
 * Code generator
11
 *
12
 * Generates code for any generateable model
13
 *
14
 * @author Thomas Gossmann
15
 */
16
class CodeGenerator {
17
18
	const SORT_USESTATEMENTS_DEFAULT = 'default';
19
20
	const SORT_CONSTANTS_DEFAULT = 'default';
21
22
	const SORT_PROPERTIES_DEFAULT = 'default';
23
24
	const SORT_METHODS_DEFAULT = 'default';
25
26
	/** @var CodeGeneratorConfig */
27
	protected $config;
28
29
	/** @var ModelGenerator */
30
	protected $generator;
31
32
	/**
33
	 *
34
	 * @param CodeGeneratorConfig|array $config
35
	 */
36 10
	public function __construct($config = null) {
37 10
		$this->configure($config);
38 10
		$this->generator = new ModelGenerator($this->config);
39 10
	}
40
41 2
	protected function configure($config = null) {
42 2
		if (is_array($config)) {
43 1
			$this->config = new CodeGeneratorConfig($config);
44 1
		} else if ($config instanceof CodeGeneratorConfig) {
45 1
			$this->config = $config;
46
		} else {
47 1
			$this->config = new CodeGeneratorConfig();
48
		}
49 2
	}
50
51
	/**
52
	 * Returns the used configuration
53
	 *
54
	 * @return CodeGeneratorConfig
55
	 */
56 1
	public function getConfig() {
57 1
		return $this->config;
58
	}
59
60
	/**
61
	 * Generates code from a given model
62
	 *
63
	 * @param GenerateableInterface $model
64
	 * @return string the generated code
65
	 */
66 8
	public function generate(GenerateableInterface $model): string {
67 8
		return $this->generator->generate($model);
68
	}
69
70
}
71