Passed
Push — master ( d98594...cee2ee )
by Paul
07:20 queued 03:47
created

SiteReviewsSummaryBlock::filterInterpolation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
ccs 0
cts 4
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\Blocks\BlockGenerator;
6
use GeminiLabs\SiteReviews\Shortcodes\SiteReviewsSummaryShortcode as Shortcode;
7
8
class SiteReviewsSummaryBlock extends BlockGenerator
9
{
10
	/**
11
	 * @return array
12
	 */
13
	public function attributes()
14
	{
15
		return [
16
			'assigned_to' => [
17
				'default' => '',
18
				'type' => 'string',
19
			],
20
			'category' => [
21
				'default' => '',
22
				'type' => 'string',
23
			],
24
			'className' => [
25
				'default' => '',
26
				'type' => 'string',
27
			],
28
			'hide' => [
29
				'default' => '',
30
				'type' => 'string',
31
			],
32
			'post_id' => [
33
				'default' => '',
34
				'type' => 'string',
35
			],
36
			'rating' => [
37
				'default' => '1',
38
				'type' => 'number',
39
			],
40
			'schema' => [
41
				'default' => false,
42
				'type' => 'boolean',
43
			],
44
			'type' => [
45
				'default' => '',
46
				'type' => 'string',
47
			],
48
		];
49
	}
50
51
	/**
52
	 * @return string
53
	 */
54
	public function render( array $attributes )
55
	{
56
		$attributes['class'] = $attributes['className'];
57
		$shortcode = glsr( Shortcode::class );
58
		if( filter_input( INPUT_GET, 'context' ) == 'edit' ) {
59
			$attributes = $this->normalize( $attributes );
60
			$this->filterShortcodeClass();
61
			if( !$this->hasVisibleFields( $shortcode, $attributes )) {
62
				$this->filterInterpolation();
63
			}
64
		}
65
		return $shortcode->buildShortcode( $attributes );
66
	}
67
68
	/**
69
	 * @return void
70
	 */
71
	protected function filterInterpolation()
72
	{
73
		add_filter( 'site-reviews/interpolate/reviews-summary', function( $context ) {
74
			$context['class'] = 'glsr-default glsr-block-disabled';
75
			$context['text'] = __( 'You have hidden all of the fields for this block.', 'site-reviews' );
76
			return $context;
77
		});
78
	}
79
80
	/**
81
	 * @return void
82
	 */
83
	protected function filterShortcodeClass()
84
	{
85
		add_filter( 'site-reviews/style', function() {
86
			return 'default';
87
		});
88
	}
89
}
90