Test Failed
Push — develop ( 006c9f...4b441a )
by Paul
13:29
created

SiteReviewBlock::shortcode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Integrations\Gutenberg\Blocks;
4
5
use GeminiLabs\SiteReviews\Shortcodes\SiteReviewShortcode;
6
7
class SiteReviewBlock extends Block
8
{
9
    public function render(array $attributes): string
10
    {
11
        if ('edit' === filter_input(INPUT_GET, 'context')) {
12
            if (empty(wp_count_posts(glsr()->post_type)->publish)) {
13
                return $this->buildEmptyBlock(
14
                    _x('No reviews found.', 'admin-text', 'site-reviews')
15
                );
16
            }
17
        }
18
        return parent::render($attributes);
19
    }
20
21
    public static function shortcodeClass(): string
22
    {
23
        return SiteReviewShortcode::class;
24
    }
25
26
    protected function blockClassAttr(array $attributes): string
27
    {
28
        $attr = [];
29
        if (!empty($attributes['styleRatingColor']) || !empty($attributes['styleRatingColorCustom'])) {
30
            $attr[] = 'has-custom-color';
31
        }
32
        return implode(' ', $attr);
33
    }
34
35
    protected function blockStyleAttr(array $attributes): string
36
    {
37
        $attr = [];
38
        if (!empty($attributes['styleRatingColor'])) {
39
            $attr[] = "--glsr-review-star-bg: var(--wp--preset--color--{$attributes['styleRatingColor']});";
40
        } elseif (!empty($attributes['styleRatingColorCustom'])) {
41
            $attr[] = "--glsr-review-star-bg: {$attributes['styleRatingColorCustom']};";
42
        }
43
        if (!empty($attributes['styleStarSize'])) {
44
            $attr[] = "--glsr-review-star: {$attributes['styleStarSize']};";
45
        }
46
        return implode('', $attr);
47
    }
48
}
49