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