Test Failed
Push — develop ( 93bfc8...438c44 )
by Paul
08:04
created

MetaboxField::buildFieldElement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Modules\Html;
4
5
use GeminiLabs\SiteReviews\Contracts\BuilderContract;
6
use GeminiLabs\SiteReviews\Modules\Sanitizer;
7
use GeminiLabs\SiteReviews\Review;
8
9
class MetaboxField extends Field
10
{
11
    public Review $review;
12
13
    public function __construct(array $args = [])
14
    {
15
        $this->review = glsr_get_review(get_the_ID()); // review is cached
16
        parent::__construct($args);
17
    }
18
19
    public function builder(): BuilderContract
20
    {
21
        return glsr(MetaboxBuilder::class);
22
    }
23
24
    public function buildField(): string
25
    {
26
        return glsr(Template::class)->build('partials/editor/metabox-field', [
27
            'context' => [
28
                'class' => $this->classAttrField(),
29
                'field' => $this->buildFieldElement(),
30
                'label' => $this->buildFieldLabel(),
31
            ],
32
            'field' => $this,
33
            'review' => $this->review,
34
        ]);
35
    }
36
37
    public function buildFieldElement(): string
38
    {
39
        return $this->fieldElement()->build([
40
            'class' => 'glsr-input-value',
41
            'label' => '', // prevent the field label from being built
42
        ]);
43
    }
44
45
    public function location(): string
46
    {
47
        return 'metabox';
48
    }
49
50
    protected function classAttrField(): string
51
    {
52
        $type = $this->isChoiceField() ? 'choice' : $this->original_type;
53
        return glsr(Sanitizer::class)->sanitizeAttrClass(
54
            "glsr-metabox-field glsr-field-{$type}"
55
        );
56
    }
57
}
58