Passed
Push — develop ( 7fa65f...4875bb )
by Paul
13:31
created

SiteReviewBlock   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 10 3
A shortcodeClass() 0 3 1
A blockClasses() 0 7 2
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 blockClasses(array $attributes): array
27
    {
28
        $classes = [];
29
        if (!empty($attributes['styleAlign'])) {
30
            $classes[] = "items-justified-{$attributes['styleAlign']}";
31
        }
32
        return $classes;
33
    }
34
}
35