Test Failed
Push — develop ( 8a2d95...1ddb5f )
by Paul
11:12
created

SiteReviewsSummaryBlock   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 12
eloc 26
c 1
b 0
f 1
dl 0
loc 44
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A shortcode() 0 3 1
A blockClassAttr() 0 10 4
B blockStyleAttr() 0 25 7
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Integrations\Gutenberg\Blocks;
4
5
use GeminiLabs\SiteReviews\Contracts\ShortcodeContract;
6
use GeminiLabs\SiteReviews\Shortcodes\SiteReviewsSummaryShortcode;
7
8
class SiteReviewsSummaryBlock extends Block
9
{
10
    public function shortcode(): ShortcodeContract
11
    {
12
        return glsr(SiteReviewsSummaryShortcode::class);
13
    }
14
15
    protected function blockClassAttr(array $attributes): string
16
    {
17
        $attr = [];
18
        if (!empty($attributes['styleAlign'])) {
19
            $attr[] = "items-justified-{$attributes['styleAlign']}";
20
        }
21
        if (!empty($attributes['styleRatingColor']) || !empty($attributes['styleRatingColorCustom'])) {
22
            $attr[] = 'has-custom-rating-color';
23
        }
24
        return implode(' ', $attr);
25
    }
26
27
    protected function blockStyleAttr(array $attributes): string
28
    {
29
        $attr = [];
30
        if (!empty($attributes['styleRatingColor'])) {
31
            $attr[] = "--glsr-bar-bg: var(--wp--preset--color--{$attributes['styleRatingColor']});";
32
            $attr[] = '--glsr-summary-star-bg: var(--glsr-bar-bg);';
33
        } elseif (!empty($attributes['styleRatingColorCustom'])) {
34
            $attr[] = "--glsr-bar-bg: {$attributes['styleRatingColorCustom']};";
35
            $attr[] = '--glsr-summary-star-bg: var(--glsr-bar-bg);';
36
        }
37
        if (!empty($attributes['styleBarSize'])) {
38
            $attr[] = "--glsr-bar-size: {$attributes['styleBarSize']};";
39
        }
40
        if (!empty($attributes['styleBarSpacing'])) {
41
            $attr[] = "--glsr-bar-spacing: {$attributes['styleBarSpacing']};";
42
        }
43
        if (!empty($attributes['styleStarSize'])) {
44
            $attr[] = "--glsr-summary-star: {$attributes['styleStarSize']};";
45
        }
46
        if (!empty($attributes['styleMaxWidth'])) {
47
            $attr[] = "--glsr-max-w: {$attributes['styleMaxWidth']};";
48
        } else {
49
            $attr[] = "--glsr-max-w: none";
50
        }
51
        return implode('', $attr);
52
    }
53
}
54