| Conditions | 10 |
| Total Lines | 39 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Complex classes like property_ads.js ➔ loadPropertyAds often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | import 'bootstrap/js/dist/tooltip'; |
||
| 22 | function loadPropertyAds() { |
||
| 23 | let xhrId = ++xhrCount; |
||
| 24 | |||
| 25 | $.ajax({ |
||
| 26 | type: 'GET', |
||
| 27 | url: Routing.generate('property_ads_list'), |
||
|
|
|||
| 28 | data: { |
||
| 29 | filters: $filterForm |
||
| 30 | .find(':input').filter(function () { |
||
| 31 | return '' !== $(this).val() |
||
| 32 | }) |
||
| 33 | .serialize(), |
||
| 34 | sort: $sortSelect.val() |
||
| 35 | }, |
||
| 36 | beforeSend: function () { |
||
| 37 | if ($body.find('.loader').length) { |
||
| 38 | return; |
||
| 39 | } |
||
| 40 | |||
| 41 | $body.append('<div class="loader"></div>'); |
||
| 42 | }, |
||
| 43 | success: function (html) { |
||
| 44 | if (xhrId !== xhrCount) { |
||
| 45 | return; |
||
| 46 | } |
||
| 47 | |||
| 48 | $container.html(html); |
||
| 49 | $('#result-count').html($container.find('> article').length); |
||
| 50 | initTooltips(); |
||
| 51 | }, |
||
| 52 | complete: function () { |
||
| 53 | if (xhrId !== xhrCount) { |
||
| 54 | return; |
||
| 55 | } |
||
| 56 | |||
| 57 | $body.find('.loader').remove(); |
||
| 58 | } |
||
| 59 | }); |
||
| 60 | } |
||
| 61 | |||
| 71 |
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.