Test Failed
Push — develop ( c74868...df43c9 )
by Paul
09:13
created

SectionDefaults   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 4
eloc 20
c 2
b 0
f 2
dl 0
loc 40
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A finalize() 0 14 3
A defaults() 0 7 1
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Integrations\Breakdance\Defaults;
4
5
use GeminiLabs\SiteReviews\Defaults\DefaultsAbstract;
6
7
class SectionDefaults extends DefaultsAbstract
8
{
9
    /**
10
     * The values that should be sanitized.
11
     * This is done after $casts and before $enums.
12
     */
13
    public array $sanitize = [
14
        'children' => 'array-consolidate',
15
        'fields' => 'array-string',
16
        'label' => 'text',
17
        'options' => 'array-consolidate',
18
    ];
19
20
    protected function defaults(): array
21
    {
22
        return [
23
            'children' => [],
24
            'fields' => [],
25
            'label' => '',
26
            'options' => [],
27
        ];
28
    }
29
30
    /**
31
     * Finalize provided values, this always runs last.
32
     */
33
    protected function finalize(array $values = []): array
34
    {
35
        if (empty($values['children'])) {
36
            return $values;
37
        }
38
        $children = array_filter($values['children'], function ($child) {
39
            $type = $child['options']['type'] ?? 'alert_box';
40
            if ('alert_box' !== $type) {
41
                return true;
42
            }
43
            return !empty($child['options']['alertBoxOptions']['content']);
44
        });
45
        $values['children'] = array_values($children);
46
        return $values;
47
    }
48
}
49