| Conditions | 6 |
| Paths | 24 |
| Total Lines | 76 |
| 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 |
||
| 73 | function render_field( $field ) { |
||
| 74 | |||
| 75 | // validate value |
||
| 76 | if( empty($field['value']) ) { |
||
| 77 | |||
| 78 | $field['value'] = array(); |
||
| 79 | |||
| 80 | } |
||
| 81 | |||
| 82 | |||
| 83 | // value |
||
| 84 | $field['value'] = acf_parse_args($field['value'], array( |
||
| 85 | 'address' => '', |
||
| 86 | 'lat' => '', |
||
| 87 | 'lng' => '' |
||
| 88 | )); |
||
| 89 | |||
| 90 | |||
| 91 | // default options |
||
| 92 | foreach( $this->default_values as $k => $v ) { |
||
| 93 | |||
| 94 | if( empty($field[ $k ]) ) { |
||
| 95 | |||
| 96 | $field[ $k ] = $v; |
||
| 97 | |||
| 98 | } |
||
| 99 | |||
| 100 | } |
||
| 101 | |||
| 102 | |||
| 103 | // vars |
||
| 104 | $atts = array( |
||
| 105 | 'id' => $field['id'], |
||
| 106 | 'class' => "acf-google-map {$field['class']}", |
||
| 107 | 'data-id' => $field['id'] . '-' . uniqid(), |
||
| 108 | 'data-lat' => $field['center_lat'], |
||
| 109 | 'data-lng' => $field['center_lng'], |
||
| 110 | 'data-zoom' => $field['zoom'], |
||
| 111 | ); |
||
| 112 | |||
| 113 | |||
| 114 | // has value |
||
| 115 | if( $field['value']['address'] ) { |
||
| 116 | |||
| 117 | $atts['class'] .= ' -value'; |
||
| 118 | |||
| 119 | } |
||
| 120 | |||
| 121 | ?> |
||
| 122 | <div <?php acf_esc_attr_e($atts); ?>> |
||
| 123 | |||
| 124 | <div class="acf-hidden"> |
||
| 125 | <?php foreach( $field['value'] as $k => $v ): ?> |
||
| 126 | <input type="hidden" class="input-<?php echo $k; ?>" name="<?php echo esc_attr($field['name']); ?>[<?php echo $k; ?>]" value="<?php echo esc_attr( $v ); ?>" /> |
||
| 127 | <?php endforeach; ?> |
||
| 128 | </div> |
||
| 129 | |||
| 130 | <div class="title acf-soh"> |
||
| 131 | |||
| 132 | <div class="actions acf-soh-target"> |
||
| 133 | <a href="#" data-name="search" class="acf-icon -search grey" title="<?php _e("Search", 'acf'); ?>"></a> |
||
| 134 | <a href="#" data-name="clear" class="acf-icon -cancel grey" title="<?php _e("Clear location", 'acf'); ?>"></a> |
||
| 135 | <a href="#" data-name="locate" class="acf-icon -location grey" title="<?php _e("Find current location", 'acf'); ?>"></a> |
||
| 136 | </div> |
||
| 137 | |||
| 138 | <input class="search" type="text" placeholder="<?php _e("Search for address...",'acf'); ?>" value="<?php echo $field['value']['address']; ?>" /> |
||
| 139 | <i class="acf-loading"></i> |
||
| 140 | |||
| 141 | </div> |
||
| 142 | |||
| 143 | <div class="canvas" style="height: <?php echo $field['height']; ?>px"></div> |
||
| 144 | |||
| 145 | </div> |
||
| 146 | <?php |
||
| 147 | |||
| 148 | } |
||
| 149 | |||
| 285 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.