| Conditions | 3 |
| Paths | 2 |
| Total Lines | 54 |
| Code Lines | 31 |
| 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 |
||
| 49 | public function render( $atts ) { |
||
| 50 | |||
| 51 | // Extract attributes and set default values. |
||
| 52 | $geomap_atts = shortcode_atts( array( |
||
| 53 | 'width' => '100%', |
||
| 54 | 'height' => '300px', |
||
| 55 | 'global' => false, |
||
| 56 | ), $atts ); |
||
| 57 | |||
| 58 | // Get id of the post |
||
| 59 | $post_id = get_the_ID(); |
||
| 60 | |||
| 61 | if ( $geomap_atts['global'] || is_null( $post_id ) ) { |
||
| 62 | // Global geomap |
||
| 63 | $geomap_id = 'wl_geomap_global'; |
||
| 64 | $post_id = null; |
||
| 65 | } else { |
||
| 66 | // Post-specific geomap |
||
| 67 | $geomap_id = 'wl_geomap_' . $post_id; |
||
| 68 | } |
||
| 69 | |||
| 70 | // Add leaflet css and library. |
||
| 71 | wp_enqueue_style( |
||
| 72 | 'leaflet', |
||
| 73 | dirname( plugin_dir_url( __FILE__ ) ) . '/bower_components/leaflet/dist/leaflet.css' |
||
| 74 | ); |
||
| 75 | wp_enqueue_script( |
||
| 76 | 'leaflet', |
||
| 77 | dirname( plugin_dir_url( __FILE__ ) ) . '/bower_components/leaflet/dist/leaflet.js' |
||
| 78 | ); |
||
| 79 | |||
| 80 | // Add wordlift-ui css and library. |
||
| 81 | wp_enqueue_style( 'wordlift-ui-css', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-ui.min.css' ); |
||
| 82 | |||
| 83 | $this->enqueue_scripts(); |
||
| 84 | |||
| 85 | wp_localize_script( 'wordlift-ui', 'wl_geomap_params', array( |
||
| 86 | 'ajax_url' => admin_url( 'admin-ajax.php' ), // Global param |
||
| 87 | 'action' => 'wl_geomap' // Global param |
||
| 88 | ) ); |
||
| 89 | |||
| 90 | // Escaping atts. |
||
| 91 | $esc_id = esc_attr( $geomap_id ); |
||
| 92 | $esc_width = esc_attr( $geomap_atts['width'] ); |
||
| 93 | $esc_height = esc_attr( $geomap_atts['height'] ); |
||
| 94 | $esc_post_id = esc_attr( $post_id ); |
||
| 95 | |||
| 96 | // Return HTML template. |
||
| 97 | return <<<EOF |
||
| 98 | <div class="wl-geomap" id="$esc_id" data-post-id="$esc_post_id" |
||
| 99 | style="width:$esc_width; height:$esc_height; background-color: gray;"> |
||
| 100 | </div> |
||
| 101 | EOF; |
||
| 102 | } |
||
| 103 | |||
| 122 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.