| Conditions | 1 |
| Paths | 1 |
| Total Lines | 100 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 | var map, heatmap; |
||
| 3 | function initMap() { |
||
| 4 | |||
| 5 | $.getJSON( "core/json/variables.json", function( jsondata ) { |
||
| 6 | |||
| 7 | var variables = jsondata; |
||
| 8 | |||
| 9 | var lattitude = Number(variables['system']['map_center_lat']); |
||
| 10 | var longitude = Number(variables['system']['map_center_long']); |
||
| 11 | var zoom_level = Number(variables['system']['zoom_level']); |
||
| 12 | |||
| 13 | |||
| 14 | map = new google.maps.Map(document.getElementById('map'), { |
||
|
|
|||
| 15 | center: {lat: lattitude, lng: longitude}, |
||
| 16 | zoom: zoom_level, |
||
| 17 | zoomControl: true, |
||
| 18 | scaleControl: false, |
||
| 19 | scrollwheel: true, |
||
| 20 | disableDoubleClickZoom: false, |
||
| 21 | }); |
||
| 22 | |||
| 23 | map.set('styles',[ |
||
| 24 | { |
||
| 25 | "featureType":"all", |
||
| 26 | "elementType":"labels.text.fill", |
||
| 27 | "stylers":[{"saturation":36},{"color":"#333333"},{"lightness":40}] |
||
| 28 | }, |
||
| 29 | { |
||
| 30 | "featureType":"all", |
||
| 31 | "elementType":"labels.text.stroke", |
||
| 32 | "stylers":[{"visibility":"on"},{"color":"#ffffff"},{"lightness":16}] |
||
| 33 | }, |
||
| 34 | { |
||
| 35 | "featureType":"all", |
||
| 36 | "elementType":"labels.icon", |
||
| 37 | "stylers":[{"visibility":"off"}] |
||
| 38 | }, |
||
| 39 | { |
||
| 40 | "featureType":"administrative", |
||
| 41 | "elementType":"geometry.fill", |
||
| 42 | "stylers":[{"color":"#fefefe"},{"lightness":20}] |
||
| 43 | }, |
||
| 44 | { |
||
| 45 | "featureType":"administrative", |
||
| 46 | "elementType":"geometry.stroke", |
||
| 47 | "stylers":[{"color":"#fefefe"},{"lightness":17},{"weight":1.2}] |
||
| 48 | }, |
||
| 49 | { |
||
| 50 | "featureType":"landscape", |
||
| 51 | "elementType":"geometry", |
||
| 52 | "stylers":[{"color":"#f5f5f5"},{"lightness":20}] |
||
| 53 | }, |
||
| 54 | { |
||
| 55 | "featureType":"poi", |
||
| 56 | "elementType":"geometry", |
||
| 57 | "stylers":[{"color":"#f5f5f5"},{"lightness":21}] |
||
| 58 | }, |
||
| 59 | { |
||
| 60 | "featureType":"poi.park", |
||
| 61 | "elementType":"geometry", |
||
| 62 | "stylers":[{"color":"#dedede"},{"lightness":21}] |
||
| 63 | }, |
||
| 64 | { |
||
| 65 | "featureType":"poi.park", |
||
| 66 | "elementType":"geometry.fill", |
||
| 67 | "stylers":[{"color":"#c2ffd7"}] |
||
| 68 | }, |
||
| 69 | { |
||
| 70 | "featureType":"road.highway", |
||
| 71 | "elementType":"geometry.fill", |
||
| 72 | "stylers":[{"color":"#ffffff"},{"lightness":17}]}, |
||
| 73 | { |
||
| 74 | "featureType":"road.highway", |
||
| 75 | "elementType":"geometry.stroke", |
||
| 76 | "stylers":[{"color":"#ffffff"},{"lightness":29},{"weight":0.2}]}, |
||
| 77 | { |
||
| 78 | "featureType":"road.arterial", |
||
| 79 | "elementType":"geometry", |
||
| 80 | "stylers":[{"color":"#ffffff"},{"lightness":18}]}, |
||
| 81 | { |
||
| 82 | "featureType":"road.local", |
||
| 83 | "elementType":"geometry", |
||
| 84 | "stylers":[{"color":"#ffffff"},{"lightness":16}]}, |
||
| 85 | { |
||
| 86 | "featureType":"transit", |
||
| 87 | "elementType":"geometry", |
||
| 88 | "stylers":[{"color":"#f2f2f2"},{"lightness":19}]}, |
||
| 89 | { |
||
| 90 | "featureType":"water", |
||
| 91 | "elementType":"geometry", |
||
| 92 | "stylers":[{"color":"#e9e9e9"},{"lightness":17}]}, |
||
| 93 | { |
||
| 94 | "featureType":"water", |
||
| 95 | "elementType":"geometry.fill", |
||
| 96 | "stylers":[{"color":"#b3d8f9"}] |
||
| 97 | } |
||
| 98 | ]); |
||
| 99 | initSlider(); |
||
| 100 | }); |
||
| 101 | |||
| 102 | } |
||
| 103 | function initSlider(){ |
||
| 193 | } |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.