Conditions | 9 |
Paths | 256 |
Total Lines | 80 |
Code Lines | 58 |
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 |
||
61 | public function form( $instance ) { |
||
62 | // Set default values. |
||
63 | $instance = $this->parse_args( $instance ); |
||
64 | |||
65 | // Retrieve an existing value from the database. |
||
66 | $title['val'] = ! empty( $instance['title'] ) ? $instance['title'] : ''; |
||
67 | $lat['val'] = ! empty( $instance['lat'] ) ? $instance['lat'] : ''; |
||
68 | $lng['val'] = ! empty( $instance['lng'] ) ? $instance['lng'] : ''; |
||
69 | $info['val'] = ! empty( $instance['info'] ) ? $instance['info'] : ''; |
||
70 | $width['val'] = ! empty( $instance['width'] ) ? $instance['width'] : ''; |
||
71 | $height['val'] = ! empty( $instance['height'] ) ? $instance['height'] : ''; |
||
72 | $zoom['val'] = ! empty( $instance['zoom'] ) ? $instance['zoom'] : ''; |
||
73 | $scrollwheel['val'] = ! empty( $instance['scrollwheel'] ) ? $instance['scrollwheel'] : 0; |
||
74 | |||
75 | $title['id'] = $this->get_field_id( 'title' ); |
||
76 | $lat['id'] = $this->get_field_id( 'lat' ); |
||
77 | $lng['id'] = $this->get_field_id( 'lng' ); |
||
78 | $info['id'] = $this->get_field_id( 'info' ); |
||
79 | $width['id'] = $this->get_field_id( 'width' ); |
||
80 | $height['id'] = $this->get_field_id( 'height' ); |
||
81 | $zoom['id'] = $this->get_field_id( 'zoom' ); |
||
82 | $scrollwheel['id'] = $this->get_field_id( 'scrollwheel' ); |
||
83 | |||
84 | $title['name'] = $this->get_field_name( 'title' ); |
||
85 | $lat['name'] = $this->get_field_name( 'lat' ); |
||
86 | $lng['name'] = $this->get_field_name( 'lng' ); |
||
87 | $info['name'] = $this->get_field_name( 'info' ); |
||
88 | $width['name'] = $this->get_field_name( 'width' ); |
||
89 | $height['name'] = $this->get_field_name( 'height' ); |
||
90 | $zoom['name'] = $this->get_field_name( 'zoom' ); |
||
91 | $scrollwheel['name'] = $this->get_field_name( 'scrollwheel' ); |
||
92 | |||
93 | // Widget title. |
||
94 | echo '<p>'; |
||
95 | echo ' <label for="' . esc_attr( $title['id'] ) . '" class="wp-api-maps_title_label">' . esc_attr( 'Title:' ) . '</label>'; |
||
96 | echo ' <input type="text" id="' . esc_attr( $title['id'] ) . '" name="' . esc_attr( $title['name'] ) . '" class="widefat" value="' . esc_attr( $title['val'] ) . '">'; |
||
97 | echo '</p>'; |
||
98 | |||
99 | // Widget width. |
||
100 | echo '<p>'; |
||
101 | echo ' <label for="' . esc_attr( $width['id'] ) . '" class="wp-api-maps_width_label">' . esc_attr( 'Width:' ) . '</label>'; |
||
102 | echo ' <input type="text" id="' . esc_attr( $width['id'] ) . '" name="' . esc_attr( $width['name'] ) . '" class="widefat" value="' . esc_attr( $width['val'] ) . '">'; |
||
103 | echo '</p>'; |
||
104 | |||
105 | // Widget height. |
||
106 | echo '<p>'; |
||
107 | echo ' <label for="' . esc_attr( $height['id'] ) . '" class="wp-api-maps_height_label">' . esc_attr( 'Height:' ) . '</label>'; |
||
108 | echo ' <input type="text" id="' . esc_attr( $height['id'] ) . '" name="' . esc_attr( $height['name'] ) . '" class="widefat" value="' . esc_attr( $height['val'] ) . '">'; |
||
109 | echo '</p>'; |
||
110 | |||
111 | // Latitude input. |
||
112 | echo '<p>'; |
||
113 | echo ' <label for="' . esc_attr( $lat['id'] ) . '" class="wp-api-maps_lat_label">' . esc_attr( 'Latitude:' ) . '</label>'; |
||
114 | echo ' <input type="text" id="' . esc_attr( $lat['id'] ) . '" name="' . esc_attr( $lat['name'] ) . '" class="widefat" value="' . esc_attr( $lat['val'] ) . '">'; |
||
115 | echo '</p>'; |
||
116 | |||
117 | // Longitude input. |
||
118 | echo '<p>'; |
||
119 | echo ' <label for="' . esc_attr( $lng['id'] ) . '" class="wp-api-maps_lng_label">' . esc_attr( 'Longitude:' ) . '</label>'; |
||
120 | echo ' <input type="text" id="' . esc_attr( $lng['id'] ) . '" name="' . esc_attr( $lng['name'] ) . '" class="widefat" value="' . esc_attr( $lng['val'] ) . '">'; |
||
121 | echo '</p>'; |
||
122 | |||
123 | // Info content input. |
||
124 | echo '<p>'; |
||
125 | echo ' <label for="' . esc_attr( $info['id'] ) . '" class="wp-api-maps_info_label">' . esc_attr( 'Info window content:' ) . '</label>'; |
||
126 | echo ' <input type="text" id="' . esc_attr( $info['id'] ) . '" name="' . esc_attr( $info['name'] ) . '" class="widefat" value="' . esc_attr( $info['val'] ) . '">'; |
||
127 | echo '</p>'; |
||
128 | |||
129 | // Zoom input. |
||
130 | echo '<p>'; |
||
131 | echo ' <label for="' . esc_attr( $zoom['id'] ) . '" class="wp-api-maps_zoom_label">' . esc_attr( 'Zoom:' ) . '</label>'; |
||
132 | echo ' <input type="text" id="' . esc_attr( $zoom['id'] ) . '" name="' . esc_attr( $zoom['name'] ) . '" class="widefat" value="' . esc_attr( $zoom['val'] ) . '">'; |
||
133 | echo '</p>'; |
||
134 | |||
135 | // ScrollWheel option. |
||
136 | echo '<p>'; |
||
137 | echo ' <input value="1" type="checkbox"' . checked( esc_attr( $scrollwheel['val'] ), 1, false ) . 'id="' . esc_attr( $scrollwheel['id'] ) . '" name="' . esc_attr( $scrollwheel['name'] ) . '" />'; |
||
138 | echo ' <label for="' . esc_attr( $scrollwheel['id'] ) . '">Disable Scroll Zoom</label>'; |
||
139 | echo '</p>'; |
||
140 | } |
||
141 | |||
188 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.