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

SectionNormalizer   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 10.64 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 5
loc 47
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
C normalize() 5 38 7

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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