Completed
Push — master ( 159932...f1c264 )
by Thomas
08:09
created

AbstractCodeGenerator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 55.56%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
c 3
b 0
f 0
lcom 1
cbo 8
dl 0
loc 36
ccs 5
cts 9
cp 0.5556
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getTemplateFolder() 0 3 1
A getService() 0 3 1
A loadClass() 0 10 2
1
<?php
2
namespace keeko\tools\generator;
3
4
use gossi\codegen\model\PhpClass;
5
use keeko\tools\helpers\ServiceLoaderTrait;
6
use keeko\tools\services\CommandService;
7
use phootwork\file\File;
8
9
abstract class AbstractCodeGenerator {
10
	
11
	use ServiceLoaderTrait;
12
13
	/** @var \Twig_Environment */
14 12
	protected $twig;
15 12
16
	public function __construct(CommandService $service) {
17 12
		$this->loadServices($service);
18 12
		
19 12
		$loader = new \Twig_Loader_Filesystem($this->service->getConfig()->getTemplateRoot() . '/' . $this->getTemplateFolder());
20
		$this->twig = new \Twig_Environment($loader);
21
	}
22
	
23
	protected function getTemplateFolder() {
24
		return '';
25
	}
26
27
	/**
28
	 * @return CommandService
29
	 */
30
	protected function getService() {
31
		return $this->service;
32
	}
33
34
	protected function loadClass(PhpClass $class) {
35
		$file = new File($this->codegenService->getFilename($class));
36
		
37
		// load from file, if exists
38
		if ($file->exists()) {
39
			return PhpClass::fromFile($file->getPathname());
40
		}
41
		
42
		return $class;
43
	}
44
}
45