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

SiteReviewsFormBlock   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 10
eloc 18
c 2
b 0
f 1
dl 0
loc 34
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A blockClassAttr() 0 7 3
A blockStyleAttr() 0 18 6
A shortcodeClass() 0 3 1
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Integrations\Gutenberg\Blocks;
4
5
use GeminiLabs\SiteReviews\Shortcodes\SiteReviewsFormShortcode;
6
7
class SiteReviewsFormBlock extends Block
8
{
9
    public static function shortcodeClass(): string
10
    {
11
        return SiteReviewsFormShortcode::class;
12
    }
13
14
    protected function blockClassAttr(array $attributes): string
15
    {
16
        $attr = [];
17
        if (!empty($attributes['styleRatingColor']) || !empty($attributes['styleRatingColorCustom'])) {
18
            $attr[] = 'has-custom-color';
19
        }
20
        return implode(' ', $attr);
21
    }
22
23
    protected function blockStyleAttr(array $attributes): string
24
    {
25
        $attr = [];
26
        if (!empty($attributes['styleRatingColor'])) {
27
            $attr[] = "--glsr-form-star-bg: var(--wp--preset--color--{$attributes['styleRatingColor']});";
28
        } elseif (!empty($attributes['styleRatingColorCustom'])) {
29
            $attr[] = "--glsr-form-star-bg: {$attributes['styleRatingColorCustom']};";
30
        }
31
        if (!empty($attributes['styleStarSize'])) {
32
            $attr[] = "--glsr-form-star: {$attributes['styleStarSize']};";
33
        }
34
        if (!empty($attributes['styleFieldSpacing']['left'])) {
35
            $attr[] = "--glsr-form-col-gap: {$attributes['styleFieldSpacing']['left']};";
36
        }
37
        if (!empty($attributes['styleFieldSpacing']['top'])) {
38
            $attr[] = "--glsr-form-row-gap: {$attributes['styleFieldSpacing']['top']};";
39
        }
40
        return implode('', $attr);
41
    }
42
}
43