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

BlockGenerator::attributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
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