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

SectionDefaults::finalize()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
eloc 9
c 2
b 0
f 2
dl 0
loc 14
rs 9.9666
cc 3
nc 2
nop 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