| Conditions | 2 |
| Paths | 2 |
| Total Lines | 73 |
| Code Lines | 6 |
| 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 | <?php |
||
| 13 | function tablesPrint($tables) { ?> |
||
|
|
|||
| 14 | |||
| 15 | <p class="jsonly"><input id="filter-field"> |
||
| 16 | <style> |
||
| 17 | .select-text { |
||
| 18 | margin-right: 5px; |
||
| 19 | } |
||
| 20 | </style> |
||
| 21 | <p id='tables'></p> |
||
| 22 | <script type="text/javascript"> |
||
| 23 | var filterf = function () { |
||
| 24 | var spanProto = document.createElement('span'); |
||
| 25 | var aProto = document.createElement('a'); |
||
| 26 | var brProto = document.createElement('br'); |
||
| 27 | |||
| 28 | function appendTables() { |
||
| 29 | var fragment = document.createDocumentFragment(); |
||
| 30 | var item; |
||
| 31 | for (var i = 0, len = tempTables.length; i < len; i++) { |
||
| 32 | item = tempTables[i]; |
||
| 33 | var span = spanProto.cloneNode(); |
||
| 34 | |||
| 35 | var aSelect = aProto.cloneNode(); |
||
| 36 | aSelect.href = hMe+"select="+item; |
||
| 37 | aSelect.text = langSelect; |
||
| 38 | aSelect.className = "select-text"; |
||
| 39 | |||
| 40 | var aName = aProto.cloneNode(); |
||
| 41 | aName.href = hMe+"table="+item; |
||
| 42 | aName.text = item; |
||
| 43 | span.appendChild(aSelect); |
||
| 44 | |||
| 45 | |||
| 46 | span.appendChild(aName); |
||
| 47 | var br = brProto.cloneNode(); |
||
| 48 | span.appendChild(br); |
||
| 49 | fragment.appendChild(span); |
||
| 50 | } |
||
| 51 | tableDiv.appendChild(fragment); |
||
| 52 | } |
||
| 53 | |||
| 54 | var tables = [<?php foreach($tables as $table => $type) { echo "'".urlencode($table) ."'" . ',';}?>]; |
||
| 55 | var tempTables = tables; |
||
| 56 | var hMe = "<?php echo h(ME) ?>"; |
||
| 57 | hMe = hMe.replace(/&/g, '&'); |
||
| 58 | var langSelect = "<?php echo lang('select');?>"; |
||
| 59 | |||
| 60 | |||
| 61 | var filter = document.getElementById("filter-field"); |
||
| 62 | var tableDiv = document.getElementById("tables"); |
||
| 63 | filter.onkeyup = function(event) { |
||
| 64 | |||
| 65 | while(tableDiv.firstChild) { |
||
| 66 | tableDiv.removeChild(tableDiv.firstChild); |
||
| 67 | } |
||
| 68 | |||
| 69 | tempTables = []; |
||
| 70 | var value = this.value.toLowerCase(); |
||
| 71 | var item; |
||
| 72 | for (var i = 0, len = tables.length; i < len; i++) { |
||
| 73 | item = tables[i]; |
||
| 74 | if(item.toLowerCase().indexOf(value) > -1) { |
||
| 75 | tempTables.push(item); |
||
| 76 | } |
||
| 77 | } |
||
| 78 | appendTables(); |
||
| 79 | }; |
||
| 80 | |||
| 81 | appendTables(); |
||
| 82 | } |
||
| 83 | filterf(); |
||
| 84 | </script> |
||
| 85 | <?php return true;}} ?> |
||
| 86 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.