Conditions | 10 |
Paths | 32 |
Total Lines | 32 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
39 | protected function finalize(array $values = []): array |
||
40 | { |
||
41 | $types = [ |
||
42 | 'checkbox' => Controls_Manager::SWITCHER, |
||
43 | 'number' => Controls_Manager::NUMBER, |
||
44 | 'radio' => Controls_Manager::CHOOSE, |
||
45 | 'select' => Controls_Manager::SELECT2, |
||
46 | 'text' => Controls_Manager::TEXT, |
||
47 | 'textarea' => Controls_Manager::TEXTAREA, |
||
48 | ]; |
||
49 | if (array_key_exists($values['type'], $types)) { |
||
50 | $values['type'] = $types[$values['type']]; |
||
51 | } |
||
52 | if (Controls_Manager::SWITCHER === $values['type'] && !empty($values['options'])) { |
||
53 | $values['type'] = 'multi_switcher'; |
||
54 | } |
||
55 | if (!in_array($values['type'], [ |
||
56 | Controls_Manager::CHOOSE, |
||
57 | Controls_Manager::COLOR, |
||
58 | Controls_Manager::NUMBER, |
||
59 | Controls_Manager::SWITCHER, |
||
60 | ]) && !isset($values['label_block'])) { |
||
61 | $values['label_block'] = true; |
||
62 | } |
||
63 | if (Controls_Manager::SELECT2 === $values['type'] && !empty($values['placeholder'])) { |
||
64 | $values['select2options'] ??= []; |
||
65 | $values['select2options']['placeholder'] = $values['placeholder']; |
||
66 | } |
||
67 | if (Controls_Manager::SELECT2 === $values['type'] && !isset($values['options'])) { |
||
68 | $values['type'] = 'select2_ajax'; |
||
69 | } |
||
70 | return $values; |
||
71 | } |
||
73 |