Conditions | 7 |
Paths | 13 |
Total Lines | 38 |
Code Lines | 13 |
Lines | 5 |
Ratio | 13.16 % |
Changes | 0 |
1 | <?php namespace Anomaly\Streams\Platform\Ui\Form\Component\Section; |
||
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) { |
|
|
|||
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 |
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.