Passed
Push — master ( 794fa7...a398e6 )
by Atanas
01:57
created

Php   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 35
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A render() 0 14 1
1
<?php
2
3
namespace WPEmerge\Templating;
4
5
/**
6
 * Include template files with php
7
 */
8
class Php implements EngineInterface {
9
	/**
10
	 * Global context
11
	 *
12
	 * @var array
13
	 */
14
	protected $global_context = [];
15
16
	/**
17
	 * Constructor
18
	 *
19
	 * @param array $global_context
20
	 */
21 1
	public function __construct( $global_context ) {
22 1
		$this->global_context = $global_context;
23 1
	}
24
25
	/**
26
	 * {@inheritDoc}
27
	 */
28 3
	public function render( $file, $context ) {
29 3
		$__template = $file;
30 3
		$__context = array_merge(
31 3
			['global' => $this->global_context],
32
			$context
33 3
		);
34 3
		$renderer = function() use ( $__template, $__context ) {
35 3
			ob_start();
36 3
			extract( $__context );
37 3
			include( $__template );
38 3
			return ob_get_clean();
39 3
		};
40 3
		return $renderer();
41
	}
42
}
43