Test Failed
Push — develop ( 6c74c3...4ba53a )
by Paul
08:25
created

ControlDefaults::defaults()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Integrations\WPBakery\Defaults;
4
5
use GeminiLabs\SiteReviews\Defaults\DefaultsAbstract;
6
7
class ControlDefaults extends DefaultsAbstract
8
{
9
    /**
10
     * The values that should be constrained after sanitization is run.
11
     * This is done after $casts and $sanitize.
12
     */
13
    public array $enums = [
14
        'group' => ['advanced', 'design', 'general'],
15
    ];
16
17
    /**
18
     * The keys that should be mapped to other keys.
19
     * Keys are mapped before the values are normalized and sanitized.
20
     * Note: Mapped keys should not be included in the defaults!
21
     */
22
    public array $mapped = [
23
        'default' => 'std',
24
        'label' => 'heading',
25
        'name' => 'param_name',
26
    ];
27
28
    protected function defaults(): array
29
    {
30
        return [
31
            'group' => 'general',
32
            'heading' => '',
33
            'param_name' => '',
34
            'std' => '',
35
            'type' => 'textfield',
36
        ];
37
    }
38
39
    /**
40
     * Finalize provided values, this always runs last.
41
     */
42
    protected function finalize(array $values = []): array
43
    {
44
        $types = [
45
            'checkbox' => 'checkbox',
46
            'number' => 'glsr_type_range',
47
            'select' => 'dropdown',
48
            'text' => 'textfield',
49
        ];
50
        if (array_key_exists($values['type'], $types)) {
51
            $values['type'] = $types[$values['type']];
52
        }
53
        if ('dropdown' === $values['type']
54
            && !isset($values['options'])
55
            && !isset($values['value'])) {
56
            $values['type'] = 'autocomplete';
57
            $values['settings'] = [
58
                'multiple' => true,
59
                'sortable' => true,
60
            ];
61
        }
62
        return $values;
63
    }
64
}
65