Conditions | 12 |
Paths | 32 |
Total Lines | 31 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
81 | protected static function vcTransformControl(string $name, array $args): array |
||
82 | { |
||
83 | $control = glsr(ControlDefaults::class)->merge( |
||
84 | wp_parse_args(compact('name'), $args) |
||
85 | ); |
||
86 | if ('hide' === $name) { |
||
87 | $control['heading'] = _x('Hide', 'admin-text', 'site-reviews'); |
||
88 | } |
||
89 | // Handle dropdown type: add placeholder as first option if present |
||
90 | if ('dropdown' === $control['type'] |
||
91 | && !empty($control['options']) |
||
92 | && !isset($control['options']['']) |
||
93 | && !empty($control['placeholder'])) { |
||
94 | $control['options'] = ['' => $control['placeholder']] + $control['options']; |
||
95 | } |
||
96 | // Set value to options for dropdown/checkbox if value is not set |
||
97 | if (isset($control['options']) && !isset($control['value'])) { |
||
98 | $control['value'] = $control['options']; |
||
99 | } |
||
100 | // Flip value array for dropdown/checkbox if options exist |
||
101 | if (in_array($control['type'], ['checkbox', 'dropdown']) && !empty($control['options'])) { |
||
102 | $control['value'] = array_flip($control['value']); |
||
103 | } |
||
104 | // Set default value for checkbox if not set |
||
105 | if ('checkbox' === $control['type'] && !isset($control['value'])) { |
||
106 | $control['value'] = [ |
||
107 | esc_html_x('Yes', 'admin-text', 'site-reviews') => 'true', |
||
108 | ]; |
||
109 | } |
||
110 | unset($control['options']); |
||
111 | return $control; |
||
112 | } |
||
114 |