Test Failed
Push — develop ( 0ffb39...ec11cf )
by Paul
10:15
created

SiteReviewBlock::render()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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