Conditions | 6 |
Paths | 10 |
Total Lines | 51 |
Code Lines | 44 |
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 |
||
22 | public function display() |
||
23 | { |
||
24 | $input = $this->get_input(); |
||
25 | $multi = count($input->options()) > 1; |
||
|
|||
26 | $input->set_label_sizes(); |
||
27 | $label_size_class = $input->get_label_size_class(); |
||
28 | $html = ''; |
||
29 | if (! is_array($input->raw_value()) && $input->raw_value() !== null) { |
||
30 | EE_Error::doing_it_wrong( |
||
31 | 'EE_Checkbox_Display_Strategy::display()', |
||
32 | sprintf( |
||
33 | esc_html__( |
||
34 | 'Input values for checkboxes should be an array of values, but the value for input "%1$s" is "%2$s". Please verify that the input name is exactly "%3$s"', |
||
35 | 'event_espresso' |
||
36 | ), |
||
37 | $input->html_id(), |
||
38 | var_export($input->raw_value(), true), |
||
39 | $input->html_name() . '[]' |
||
40 | ), |
||
41 | '4.8.1' |
||
42 | ); |
||
43 | } |
||
44 | $input_raw_value = (array)$input->raw_value(); |
||
45 | foreach ($input->options() as $value => $display_text) { |
||
46 | $value = $input->get_normalization_strategy()->unnormalize_one($value); |
||
47 | $html_id = $this->get_sub_input_id($value); |
||
48 | $html .= EEH_HTML::nl(0, 'checkbox'); |
||
49 | $html .= '<label for="' |
||
50 | . $html_id |
||
51 | . '" id="' |
||
52 | . $html_id |
||
53 | . '-lbl" class="ee-checkbox-label-after' |
||
54 | . $label_size_class |
||
55 | . '">'; |
||
56 | $html .= EEH_HTML::nl(1, 'checkbox'); |
||
57 | $html .= '<input type="checkbox"'; |
||
58 | $html .= ' name="' . $input->html_name() . '[]"'; |
||
59 | $html .= ' id="' . $html_id . '"'; |
||
60 | $html .= ' class="' . $input->html_class() . '"'; |
||
61 | $html .= ' style="' . $input->html_style() . '"'; |
||
62 | $html .= ' value="' . esc_attr($value) . '"'; |
||
63 | $html .= ! empty($input_raw_value) && in_array($value, $input_raw_value, true) |
||
64 | ? ' checked="checked"' |
||
65 | : ''; |
||
66 | $html .= ' ' . $this->_input->other_html_attributes(); |
||
67 | $html .= '> '; |
||
68 | $html .= $display_text; |
||
69 | $html .= EEH_HTML::nl(-1, 'checkbox') . '</label>'; |
||
70 | } |
||
71 | return $html; |
||
72 | } |
||
73 | |||
77 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.