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

AbstractCodeGenerator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1.0156

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 6
ccs 3
cts 4
cp 0.75
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 1.0156
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