Completed
Push — master ( bbdfc2...ebac7c )
by Thomas
05:30
created

AbstractGenerator::loadClass()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
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 AbstractGenerator {
10
	
11
	use ServiceLoaderTrait;
12
13
	/** @var \Twig_Environment */
14
	protected $twig;
15
16
	public function __construct(CommandService $service) {
17
		$this->loadServices($service);
18
		
19
		$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 = $this->codeService->getFile($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