Passed
Push — master ( 3d135a...21669f )
by Paul
03:32 queued 59s
created

Component   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 60
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
init() 0 1 ?
register() 0 1 ?
normalize() 0 1 ?
A render() 0 12 2
A normalizeThis() 0 11 3
1
<?php
2
3
namespace GeminiLabs\Pollux;
4
5
use GeminiLabs\Pollux\Application;
6
use GeminiLabs\Pollux\Helper;
7
8
abstract class Component
9
{
10
	/**
11
	 * @var Application
12
	 */
13
	protected $app;
14
15
	public function __construct( Application $app )
16
	{
17
		$this->app = $app;
18
	}
19
20
	/**
21
	 * @return void
22
	 */
23
	abstract public function init();
24
25
	/**
26
	 * @return void|array
27
	 */
28
	abstract public function register();
29
30
	/**
31
	 * @return void
32
	 */
33
	abstract protected function normalize();
34
35
	/**
36
	 * @param string $view
37
	 * @return void
38
	 */
39
	public function render( $view, array $data = [] )
40
	{
41
		$file = apply_filters( 'pollux/views/file',
42
			$this->app->path( sprintf( 'views/%s.php', str_replace( '.php', '', $view ))),
43
			$view,
44
			$data
45
		);
46
		if( file_exists( $file )) {
47
			extract( $data );
48
			return include $file;
49
		}
50
	}
51
52
	/**
53
	 * @param string $id
54
	 * @return array
55
	 */
56
	protected function normalizeThis( array $data, array $defaults, $id )
57
	{
58
		$data = wp_parse_args( $data, $defaults );
59
		foreach( $defaults as $key => $value ) {
60
			$method = ( new Helper )->buildMethodName( $key, 'normalize' );
61
			if( method_exists( $this, $method )) {
62
				$data[$key] = $this->$method( $data[$key], $data, $id );
63
			}
64
		}
65
		return $data;
66
	}
67
}
68