Completed
Push — master ( 0e9bc5...7ef25f )
by Ryan
15:00
created

SectionNormalizer::normalize()   C

Complexity

Conditions 7
Paths 13

Size

Total Lines 38
Code Lines 13

Duplication

Lines 5
Ratio 13.16 %

Importance

Changes 0
Metric Value
cc 7
eloc 13
nc 13
nop 1
dl 5
loc 38
rs 6.7272
c 0
b 0
f 0
1
<?php namespace Anomaly\Streams\Platform\Ui\Form\Component\Section;
2
3
use Anomaly\Streams\Platform\Ui\Form\FormBuilder;
4
5
/**
6
 * Class SectionNormalizer
7
 *
8
 * @link   http://pyrocms.com/
9
 * @author PyroCMS, Inc. <[email protected]>
10
 * @author Ryan Thompson <[email protected]>
11
 */
12
class SectionNormalizer
13
{
14
15
    /**
16
     * Normalize the sections.
17
     *
18
     * @param FormBuilder $builder
19
     */
20
    public function normalize(FormBuilder $builder)
21
    {
22
        $sections = $builder->getSections();
23
24
        foreach ($sections as $slug => &$section) {
25
26
            if (is_string($section)) {
27
                $section = [
28
                    'view' => $section,
29
                ];
30
            }
31
32
            /**
33
             * If tabs are defined but no orientation
34
             * then default to standard tabs.
35
             */
36
            if (isset($section['tabs']) && !isset($section['orientation'])) {
37
                $section['orientation'] = 'horizontal';
38
            }
39
40
            /*
41
             * Make sure some default parameters exist.
42
             */
43
            $section['attributes'] = array_get($section, 'attributes', []);
44
45
            /*
46
             * Move all data-* keys
47
             * to attributes.
48
             */
49 View Code Duplication
            foreach ($section as $attribute => $value) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
                if (str_is('data-*', $attribute)) {
51
                    array_set($section, 'attributes.' . $attribute, array_pull($section, $attribute));
52
                }
53
            }
54
        }
55
56
        $builder->setSections($sections);
57
    }
58
}
59