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

AbstractCodeGenerator::loadClass()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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