| Conditions | 1 |
| Paths | 1 |
| Total Lines | 100 |
| Code Lines | 63 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 install_form () { |
||
| 14 | $timezones = get_timezones_list(); |
||
| 15 | return h::{'form[method=post]'}( |
||
| 16 | h::nav( |
||
| 17 | h::{'radio[name=mode]'}( |
||
| 18 | [ |
||
| 19 | 'value' => ['1', '0'], |
||
| 20 | 'in' => [h::span('Regular user'), h::span('Expert')], |
||
| 21 | 'onclick' => |
||
| 22 | "var items = document.getElementsByClassName('expert');" |
||
| 23 | ."for (var i = 0; i < items.length; i++) {" |
||
| 24 | ."items.item(i).style.display = this.value == '0' ? 'table-row' : '';" |
||
| 25 | ."}" |
||
| 26 | ] |
||
| 27 | ) |
||
| 28 | ). |
||
| 29 | h::table( |
||
| 30 | h::{'tr td'}( |
||
| 31 | 'Site name:', |
||
| 32 | h::{'input[name=site_name]'}() |
||
| 33 | ). |
||
| 34 | h::{'tr.expert td'}( |
||
| 35 | 'Database engine:', |
||
| 36 | h::{'select[name=db_engine][size=3][selected=MySQLi]'}( |
||
| 37 | file_get_json(__DIR__.'/../db_engines.json') |
||
| 38 | ) |
||
| 39 | ). |
||
| 40 | h::{'tr.expert td'}( |
||
| 41 | 'Database host:', |
||
| 42 | h::{'input[name=db_host][value=localhost]'}( |
||
| 43 | [ |
||
| 44 | 'placeholder' => 'Relative or absolute path to DB for SQLite' |
||
| 45 | ] |
||
| 46 | ) |
||
| 47 | ). |
||
| 48 | h::{'tr td'}( |
||
| 49 | 'Database name:', |
||
| 50 | h::{'input[name=db_name]'}() |
||
| 51 | ). |
||
| 52 | h::{'tr td'}( |
||
| 53 | 'Database user:', |
||
| 54 | h::{'input[name=db_user]'}() |
||
| 55 | ). |
||
| 56 | h::{'tr td'}( |
||
| 57 | 'Database user password:', |
||
| 58 | h::{'input[type=password][name=db_password]'}() |
||
| 59 | ). |
||
| 60 | h::{'tr.expert td'}( |
||
| 61 | 'Database tables prefix:', |
||
| 62 | h::{'input[name=db_prefix]'}( |
||
| 63 | [ |
||
| 64 | 'value' => substr(md5(random_bytes(1000)), 0, 5).'_' |
||
| 65 | ] |
||
| 66 | ) |
||
| 67 | ). |
||
| 68 | h::{'tr.expert td'}( |
||
| 69 | 'Database charset:', |
||
| 70 | h::{'input[name=db_charset][value=utf8mb4]'}() |
||
| 71 | ). |
||
| 72 | h::{'tr td'}( |
||
| 73 | 'Timezone:', |
||
| 74 | h::{'select[name=timezone][size=7][selected=UTC]'}( |
||
| 75 | [ |
||
| 76 | 'in' => array_keys($timezones), |
||
| 77 | 'value' => array_values($timezones) |
||
| 78 | ] |
||
| 79 | ) |
||
| 80 | ). |
||
| 81 | h::{'tr td'}( |
||
| 82 | 'Language:', |
||
| 83 | h::{'select[name=language][size=3][selected=English]'}( |
||
| 84 | file_get_json(__DIR__.'/../languages.json') |
||
| 85 | ) |
||
| 86 | ). |
||
| 87 | h::{'tr td'}( |
||
| 88 | 'Email of administrator:', |
||
| 89 | h::{'input[type=email][name=admin_email]'}() |
||
| 90 | ). |
||
| 91 | h::{'tr td'}( |
||
| 92 | 'Administrator password:', |
||
| 93 | h::{'input[type=password][name=admin_password]'}() |
||
| 94 | ) |
||
| 95 | ). |
||
| 96 | h::{'button.readme'}( |
||
| 97 | 'Readme', |
||
| 98 | [ |
||
| 99 | 'onclick' => "window.open('readme.html', 'readme', 'location=no')" |
||
| 100 | ] |
||
| 101 | ). |
||
| 102 | h::{'button.license'}( |
||
| 103 | 'License', |
||
| 104 | [ |
||
| 105 | 'onclick' => "window.open('license.txt', 'license', 'location=no')" |
||
| 106 | ] |
||
| 107 | ). |
||
| 108 | h::{'button[type=submit]'}( |
||
| 109 | 'Install' |
||
| 110 | ) |
||
| 111 | ); |
||
| 112 | } |
||
| 113 | |||
| 225 |