ModuleController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 32
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 10 1
process() 0 1 ?
A setParams() 0 10 3
1
<?php
2
namespace Frameworkless\Controllers;
3
4
/**
5
 * Description of ModuleController
6
 *
7
 * @author d.lanec
8
 */
9
abstract class ModuleController extends BaseController implements \Frameworkless\ModuleInterface{
10
11
    protected function render($view, array $data = array()){
12
13
	$ref = new \ReflectionClass($this);
14
15
	$tpl = (new \SplFileInfo($ref->getFileName()))->getPath() . DIRECTORY_SEPARATOR . 'tpl';
16
17
	$twig = new \Twig_Environment(new \Twig_Loader_Filesystem($tpl));
18
19
	return $twig->render($view . '.twig', $data);
20
    }
21
22
    abstract public function process();
23
24
    /**
25
     * set module params
26
     * @param array $params
27
     * @return $this
28
     * @throws \Exception
29
     */
30
    public function setParams(array $params = array()){
31
32
	foreach($params as $param => $value){
33
	    if((new \ReflectionClass($this))->hasProperty($param) === false)
34
		throw new \Exception(sprintf("param '%s' not found in module '%s'", $param, self::class));
35
36
	    $this->{$param} = $value;
37
	}
38
	return $this;
39
    }
40
}
41