Passed
Push — master ( c6a124...535cb5 )
by Paul
09:05 queued 01:21
created

SettingBuilder::buildAfter()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Modules\Html;
4
5
use GeminiLabs\SiteReviews\Helper;
6
use GeminiLabs\SiteReviews\Helpers\Cast;
7
8
class SettingBuilder extends Builder
9
{
10
    /**
11
     * @return void|string
12
     */
13
    public function buildFormElement()
14
    {
15
        $method = Helper::buildMethodName($this->tag, 'buildForm');
16
        return $this->$method().$this->buildAfter().$this->buildFieldDescription();
17
    }
18
19
    /**
20
     * @return string|void
21
     */
22
    protected function buildAfter()
23
    {
24
        if (!empty($this->args->after)) {
25
            return '&nbsp;'.$this->args->after;
26
        }
27
    }
28
29
    /**
30
     * @return string|void
31
     */
32
    protected function buildFieldDescription()
33
    {
34
        if (!empty($this->args->description)) {
35
            return $this->p([
36
                'class' => 'description',
37
                'text' => $this->args->description,
38
            ]);
39
        }
40
    }
41
42
    /**
43
     * @return string|void
44
     */
45
    protected function buildFormInputChoices()
46
    {
47
        $fields = [];
48
        $index = 0;
49
        foreach ($this->args->options as $value => $label) {
50
            $fields[] = $this->input([
51
                'checked' => in_array($value, $this->args->cast('value', 'array')),
52
                'id' => Helper::ifTrue(!empty($this->args->id), $this->args->id.'-'.++$index),
53
                'label' => $label,
54
                'name' => $this->args->name,
55
                'type' => $this->args->type,
56
                'value' => $value,
57
            ]);
58
        }
59
        return $this->div([
60
            'class' => $this->args->class,
61
            'text' => implode('<br>', $fields),
62
        ]);
63
    }
64
65
    /**
66
     * @return array
67
     */
68
    protected function normalize(array $args, $type)
69
    {
70
        if (class_exists($className = $this->getFieldClassName($type))) {
71
            $args = $className::merge($args, 'setting');
72
        }
73
        return $args;
74
    }
75
}
76