Passed
Push — master ( ce4978...7a447f )
by Paul
07:31
created

SiteReviewsShortcode::buildTemplate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Shortcodes;
4
5
use GeminiLabs\SiteReviews\Database\ReviewManager;
6
use GeminiLabs\SiteReviews\Defaults\SiteReviewsDefaults;
7
use GeminiLabs\SiteReviews\Helpers\Cast;
8
use GeminiLabs\SiteReviews\Modules\Html\ReviewsHtml;
9
use GeminiLabs\SiteReviews\Modules\Schema;
10
use GeminiLabs\SiteReviews\Reviews;
11
12
class SiteReviewsShortcode extends Shortcode
13
{
14
    /**
15
     * @var array
16
     */
17
    public $args;
18
19
    /**
20
     * @return ReviewsHtml
21
     */
22
    public function buildReviewsHtml(array $args = [])
23
    {
24
        $this->args = glsr(SiteReviewsDefaults::class)->unguardedMerge($args);
25
        $reviews = glsr(ReviewManager::class)->reviews($this->args);
26
        $this->generateSchema($reviews);
27
        return new ReviewsHtml($reviews);
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function buildTemplate(array $args = [])
34
    {
35
        return (string) $this->buildReviewsHtml($args);
36
    }
37
38
    /**
39
     * @return void
40
     */
41
    public function generateSchema(Reviews $reviews)
42
    {
43
        if (Cast::toBool($this->args['schema'])) {
44
            glsr(Schema::class)->store(
45
                glsr(Schema::class)->build($this->args, $reviews)
46
            );
47
        }
48
    }
49
50
    /**
51
     * @return array
52
     */
53 7
    protected function hideOptions()
54
    {
55
        return [
56 7
            'title' => _x('Hide the title', 'admin-text', 'site-reviews'),
57 7
            'rating' => _x('Hide the rating', 'admin-text', 'site-reviews'),
58 7
            'date' => _x('Hide the date', 'admin-text', 'site-reviews'),
59 7
            'assigned_links' => _x('Hide the assigned links (if shown)', 'admin-text', 'site-reviews'),
60 7
            'content' => _x('Hide the content', 'admin-text', 'site-reviews'),
61 7
            'avatar' => _x('Hide the avatar (if shown)', 'admin-text', 'site-reviews'),
62 7
            'author' => _x('Hide the author', 'admin-text', 'site-reviews'),
63 7
            'response' => _x('Hide the response', 'admin-text', 'site-reviews'),
64
        ];
65
    }
66
}
67