Completed
Push — master ( 55b21a...aec22b )
by Thomas
06:20
created

AbstractBuilder::generate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 4
cts 4
cp 1
rs 10
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
namespace gossi\codegen\generator\builder;
3
4
use gossi\codegen\generator\ModelGenerator;
5
use gossi\codegen\generator\utils\Writer;
6
use gossi\codegen\model\AbstractModel;
7
use gossi\docblock\Docblock;
8
use gossi\codegen\config\CodeGeneratorConfig;
9
use gossi\codegen\model\DocblockInterface;
10
11
abstract class AbstractBuilder {
12
13
	/** @var ModelGenerator */
14
	protected $generator;
15
	
16
	/** @var Writer */
17
	protected $writer;
18
	
19
	/** @var CodeGeneratorConfig */
20
	protected $config;
21
	
22 39
	public function __construct(ModelGenerator $generator) {
23 39
		$this->generator = $generator;
24 39
		$this->writer = $generator->getWriter();
25 39
		$this->config = $generator->getConfig();
26 39
	}
27
	
28
	public abstract function build(AbstractModel $model);
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
29
	
30 6
	protected function generate(AbstractModel $model) {
31 6
		$builder = $this->generator->getFactory()->getBuilder($model);
32 6
		$builder->build($model);
33 6
	}
34
	
35 32
	protected function ensureBlankLine() {
36 32
		if (!$this->writer->endsWith("\n\n") && strlen($this->writer->rtrim()->getContent()) > 0) {
37 5
			$this->writer->writeln();
38
		} 
39 32
	}
40
	
41 32
	protected function buildDocblock(DocblockInterface $model) {
42 32
		$this->ensureBlankLine();
43 32
		if ($this->config->getGenerateDocblock()) {
44 3
			$model->generateDocblock();
45
		}
46 32
		$docblock = $model->getDocblock();
47 32
		if (!$docblock->isEmpty() || $this->config->getGenerateEmptyDocblock()) {
48 3
			$this->writer->writeln($docblock->toString());
49
		}
50 32
	}
51
	
52
}