Test Failed
Push — develop ( c6b569...7a7654 )
by Paul
09:40
created

SiteReviewBlock   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
eloc 12
dl 0
loc 24
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 17 5
A shortcode() 0 3 1
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Blocks;
4
5
use GeminiLabs\SiteReviews\Contracts\ShortcodeContract;
6
use GeminiLabs\SiteReviews\Helpers\Cast;
7
use GeminiLabs\SiteReviews\Review;
8
use GeminiLabs\SiteReviews\Shortcodes\SiteReviewShortcode;
9
10
class SiteReviewBlock extends SiteReviewsBlock
11
{
12
    public function render(array $attributes): string
13
    {
14
        $attributes['class'] = $attributes['className'];
15
        if ('edit' === filter_input(INPUT_GET, 'context')) {
16
            $attributes = $this->normalize($attributes);
17
            if (0 !== Cast::toInt($attributes['post_id']) && !Review::isReview($attributes['post_id'])) {
18
                return $this->buildEmptyBlock(
19
                    _x('Enter a valid Review Post ID to display a review.', 'admin-text', 'site-reviews')
20
                );
21
            }
22
            if (!$this->hasVisibleFields($attributes)) {
23
                return $this->buildEmptyBlock(
24
                    _x('You have hidden all of the fields for this block.', 'admin-text', 'site-reviews')
25
                );
26
            }
27
        }
28
        return $this->shortcode()->buildBlock($attributes);
29
    }
30
31
    public function shortcode(): ShortcodeContract
32
    {
33
        return glsr(SiteReviewShortcode::class);
34
    }
35
}
36