Passed
Push — master ( c3c8e4...faa349 )
by Paul
03:28
created

BlockGenerator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 46
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A attributes() 0 3 1
A normalize() 0 12 4
A register() 0 9 2
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Blocks;
4
5
use GeminiLabs\SiteReviews\Application;
6
7
abstract class BlockGenerator
8
{
9
	/**
10
	 * @return array
11
	 */
12
	public function attributes()
13
	{
14
		return [];
15
	}
16
17
	/**
18
	 * @return array
19
	 */
20
	public function normalize( array $attributes )
21
	{
22
		if( !isset( $attributes['assigned_to'] )) {
23
			return $attributes;
24
		}
25
		if( $attributes['assigned_to'] == 'post_id' ) {
26
			$attributes['assigned_to'] = $attributes['post_id'];
27
		}
28
		else if( $attributes['assigned_to'] == 'parent_id' ) {
29
			$attributes['assigned_to'] = wp_get_post_parent_id( $attributes['post_id'] );
30
		}
31
		return $attributes;
32
	}
33
34
	/**
35
	 * @return void
36
	 */
37
	public function register( $block )
38
	{
39
		if( !function_exists( 'register_block_type' ))return;
40
		register_block_type( Application::ID.'/'.$block, [
41
			'attributes' => $this->attributes(),
42
			'editor_script' => Application::ID.'/blocks',
43
			'editor_style' => Application::ID.'/blocks',
44
			'render_callback' => [$this, 'render'],
45
			'style' => Application::ID,
46
		]);
47
	}
48
49
	/**
50
	 * @return void
51
	 */
52
	abstract public function render( array $attributes );
53
}
54