| Conditions | 3 |
| Paths | 4 |
| Total Lines | 115 |
| Code Lines | 37 |
| 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 |
||
| 61 | public function index() { |
||
| 62 | |||
| 63 | $tree = Globals::getTree(); |
||
| 64 | Theme::theme(new AdministrationTheme)->init($tree); |
||
| 65 | $controller = new PageController(); |
||
| 66 | $controller |
||
| 67 | ->restrictAccess(Auth::isAdmin()) |
||
| 68 | ->setPageTitle($this->module->getTitle()); |
||
| 69 | |||
| 70 | $token = $this->module->getSetting('MAJ_AT_FORCE_EXEC_TOKEN'); |
||
| 71 | if(is_null($token)) { |
||
| 72 | $token = Functions::generateRandomToken(); |
||
| 73 | $this->module->setSetting('PAT_FORCE_EXEC_TOKEN', $token); |
||
| 74 | } |
||
| 75 | |||
| 76 | $data = new ViewBag(); |
||
| 77 | $data->set('title', $controller->getPageTitle()); |
||
| 78 | |||
| 79 | $table_id = 'table-admintasks-' . Uuid::uuid4(); |
||
| 80 | $data->set('table_id', $table_id); |
||
| 81 | |||
| 82 | $data->set('trigger_url_root', WT_BASE_URL.'module.php?mod='.$this->module->getName().'&mod_action=Task@trigger'); |
||
| 83 | $token = $this->module->getSetting('MAJ_AT_FORCE_EXEC_TOKEN'); |
||
| 84 | if(is_null($token)) { |
||
| 85 | $token = Functions::generateRandomToken(); |
||
| 86 | $this->module->setSetting('MAJ_AT_FORCE_EXEC_TOKEN', $token); |
||
| 87 | } |
||
| 88 | $data->set('trigger_token', $token); |
||
| 89 | |||
| 90 | $this->provider->getInstalledTasks(); |
||
| 91 | |||
| 92 | $controller |
||
| 93 | ->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL) |
||
| 94 | ->addExternalJavascript(WT_DATATABLES_BOOTSTRAP_JS_URL) |
||
| 95 | ->addInlineJavascript(' |
||
| 96 | //Datatable initialisation |
||
| 97 | jQuery.fn.dataTableExt.oSort["unicode-asc" ]=function(a,b) {return a.replace(/<[^<]*>/, "").localeCompare(b.replace(/<[^<]*>/, ""))}; |
||
| 98 | jQuery.fn.dataTableExt.oSort["unicode-desc" ]=function(a,b) {return b.replace(/<[^<]*>/, "").localeCompare(a.replace(/<[^<]*>/, ""))}; |
||
| 99 | jQuery.fn.dataTableExt.oSort["num-html-asc" ]=function(a,b) {a=parseFloat(a.replace(/<[^<]*>/, "")); b=parseFloat(b.replace(/<[^<]*>/, "")); return (a<b) ? -1 : (a>b ? 1 : 0);}; |
||
| 100 | jQuery.fn.dataTableExt.oSort["num-html-desc"]=function(a,b) {a=parseFloat(a.replace(/<[^<]*>/, "")); b=parseFloat(b.replace(/<[^<]*>/, "")); return (a>b) ? -1 : (a<b ? 1 : 0);}; |
||
| 101 | |||
| 102 | var adminTasksTable = jQuery("#'.$table_id.'").DataTable({ |
||
| 103 | '.I18N::datatablesI18N().', |
||
| 104 | sorting: [[3, "asc"]], |
||
| 105 | pageLength: 10, |
||
| 106 | processing: true, |
||
| 107 | serverSide : true, |
||
| 108 | ajax : { |
||
| 109 | url : "module.php?mod='.$this->module->getName().'&mod_action=AdminConfig@jsonTasksList&ged='. $tree->getNameUrl().'", |
||
| 110 | type : "POST" |
||
| 111 | }, |
||
| 112 | columns: [ |
||
| 113 | /* 0 Edit */ { sortable: false, className: "text-center"}, |
||
| 114 | /* 1 task_name */ { visible: false }, |
||
| 115 | /* 2 Enabled */ { sortable: false, className: "text-center" }, |
||
| 116 | /* 3 Task Title */ null, |
||
| 117 | /* 4 Last Run */ null, |
||
| 118 | /* 5 Last status */ { className: "text-center" }, |
||
| 119 | /* 6 Frequency */ { sortable: false, className: "text-center" }, |
||
| 120 | /* 7 Nb Occcurrences*/ { sortable: false, className: "text-center" }, |
||
| 121 | /* 8 Is Running */ { sortable: false, className: "text-center" }, |
||
| 122 | /* 9 Run task */ { sortable: false, className: "text-center" } |
||
| 123 | ], |
||
| 124 | }); |
||
| 125 | |||
| 126 | ') |
||
| 127 | ->addInlineJavascript(' |
||
| 128 | function generate_force_token() { |
||
| 129 | jQuery("#bt_genforcetoken").attr("disabled", "disabled"); |
||
| 130 | jQuery("#bt_tokentext").empty().html("<i class=\"fa fa-spinner fa-pulse fa-fw\"></i>"); |
||
| 131 | jQuery("#token_url").load( |
||
| 132 | "module.php?mod='.$this->module->getName().'&mod_action=AdminConfig@generateToken", |
||
| 133 | function() { |
||
| 134 | jQuery("#bt_genforcetoken").removeAttr("disabled"); |
||
| 135 | jQuery("#bt_tokentext").empty().html("'.I18N::translate('Regenerate token').'"); |
||
| 136 | adminTasksTable.ajax.reload(); |
||
| 137 | } |
||
| 138 | ); |
||
| 139 | } |
||
| 140 | |||
| 141 | function set_admintask_status(task, status) { |
||
| 142 | jQuery.ajax({ |
||
| 143 | url: "module.php", |
||
| 144 | type: "GET", |
||
| 145 | data: { |
||
| 146 | mod: "' . $this->module->getName() .'", |
||
| 147 | mod_action: "Task@setStatus", |
||
| 148 | task: task, |
||
| 149 | status: status |
||
| 150 | }, |
||
| 151 | error: function(result, stat, error) { |
||
| 152 | var err = typeof result.responseJSON === "undefined" ? error : result.responseJSON.error; |
||
| 153 | alert("' . I18N::translate('An error occured while editing this task:') . '" + err); |
||
| 154 | }, |
||
| 155 | complete: function(result, stat) { |
||
| 156 | adminTasksTable.ajax.reload(null, false); |
||
| 157 | } |
||
| 158 | }); |
||
| 159 | } |
||
| 160 | |||
| 161 | function run_admintask(taskname) { |
||
| 162 | jQuery("#bt_runtask_" + taskname).attr("disabled", "disabled"); |
||
| 163 | jQuery("#bt_runtasktext_" + taskname).empty().html("<i class=\"fa fa-cog fa-spin fa-fw\"></i><span class=\"sr-only\">'.I18N::translate('Running').'</span>"); |
||
| 164 | jQuery("#bt_runtasktext_" + taskname).load( |
||
| 165 | "module.php?mod='.$this->module->getName().'&mod_action=Task@trigger&force='.$token.'&task=" + taskname, |
||
| 166 | function() { |
||
| 167 | jQuery("#bt_runtasktext_" + taskname).empty().html("<i class=\"fa fa-check\"></i>'.I18N::translate('Done').'"); |
||
| 168 | adminTasksTable.ajax.reload(); |
||
| 169 | } |
||
| 170 | ); |
||
| 171 | |||
| 172 | } |
||
| 173 | '); |
||
| 174 | |||
| 175 | ViewFactory::make('AdminConfig', $this, $controller, $data)->render(); |
||
| 176 | } |
||
| 304 | } |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.