Passed
Push — develop ( 839f1b...6e51fd )
by Paul
15:21
created

ControlDefaults   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 18
c 1
b 0
f 0
dl 0
loc 44
ccs 0
cts 15
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A defaults() 0 6 1
A finalize() 0 10 1
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Integrations\FusionBuilder\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' => [
15
            'design', 'general',
16
        ],
17
    ];
18
19
    /**
20
     * The keys that should be mapped to other keys.
21
     * Keys are mapped before the values are normalized and sanitized.
22
     * Note: Mapped keys should not be included in the defaults!
23
     */
24
    public array $mapped = [
25
        'label' => 'heading',
26
        'name' => 'param_name',
27
    ];
28
29
    protected function defaults(): array
30
    {
31
        return [
32
            'group' => 'general',
33
            'label' => '',
34
            'type' => 'textfield',
35
        ];
36
    }
37
38
    /**
39
     * Finalize provided values, this always runs last.
40
     */
41
    protected function finalize(array $values = []): array
42
    {
43
        $groups = [
44
            'advanced' => esc_html_x('Advanced', 'admin-text', 'site-reviews'),
45
            'design' => esc_html_x('Design', 'admin-text', 'site-reviews'),
46
            'general' => esc_html_x('General', 'admin-text', 'site-reviews'),
47
        ];
48
        $group = $groups[$values['group']] ?? ucfirst($values['group']);
49
        $values['group'] = $group;
50
        return $values;
51
    }
52
}
53