Test Failed
Push — develop ( 4ba53a...c20cce )
by Paul
10:12
created

ControlDefaults   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 18
c 1
b 0
f 0
dl 0
loc 51
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A defaults() 0 6 1
A finalize() 0 9 2
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
            'advanced', '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
    /**
30
     * The values that should be sanitized.
31
     * This is done after $casts and before $enums.
32
     */
33
    public array $sanitize = [
34
        'description' => 'text', // Flatsome does not support HTML in descriptions
35
    ];
36
37
    protected function defaults(): array
38
    {
39
        return [
40
            'group' => 'general',
41
            'label' => '',
42
            'type' => 'textfield',
43
        ];
44
    }
45
46
    /**
47
     * Finalize provided values, this always runs last.
48
     */
49
    protected function finalize(array $values = []): array
50
    {
51
        $types = [
52
            'text' => 'textfield',
53
        ];
54
        if (array_key_exists($values['type'], $types)) {
55
            $values['type'] = $types[$values['type']];
56
        }
57
        return $values;
58
    }
59
}
60