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

AbstractGenerator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 8
dl 0
loc 36
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 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