Conditions | 3 |
Paths | 2 |
Total Lines | 180 |
Code Lines | 116 |
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 |
||
99 | public function __construct($db) |
||
100 | { |
||
101 | global $langs, $conf; |
||
102 | |||
103 | $this->db = $db; |
||
104 | |||
105 | // Id for module (must be unique). |
||
106 | $this->numero = 500000; |
||
107 | // Key text used to identify module (for permissions, menus, etc...) |
||
108 | $this->rights_class = 'flightLog'; |
||
109 | |||
110 | // Family can be 'crm','financial','hr','projects','products','ecm','technic','interface','other' |
||
|
|||
111 | // It is used to group modules by family in module setup page |
||
112 | $this->family = "Belgian Balloon Club"; |
||
113 | // Module position in the family |
||
114 | $this->module_position = 500; |
||
115 | // Gives the possibility to the module, to provide his own family info and position of this family (Overwrite $this->family and $this->module_position. Avoid this) |
||
116 | //$this->familyinfo = array('myownfamily' => array('position' => '001', 'label' => $langs->trans("MyOwnFamily"))); |
||
117 | |||
118 | // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) |
||
119 | $this->name = preg_replace('/^mod/i', '', get_class($this)); |
||
120 | // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module) |
||
121 | $this->description = "Pilots flight log"; |
||
122 | $this->descriptionlong = "Manage flights and flights type for the Belgian Balloon Club"; |
||
123 | $this->editor_name = 'De Coninck Laurent'; |
||
124 | $this->editor_url = 'http://www.dolibarr.org'; |
||
125 | |||
126 | // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z' |
||
127 | $this->version = '1.0'; |
||
128 | // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase) |
||
129 | $this->const_name = 'MAIN_MODULE_' . strtoupper($this->name); |
||
130 | // Name of image file used for this module. |
||
131 | // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue' |
||
132 | // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module' |
||
133 | $this->picto = 'flight@flightLog'; |
||
134 | |||
135 | // Defined all module parts (triggers, login, substitutions, menus, css, etc...) |
||
136 | // for default path (eg: /mymodule/core/xxxxx) (0=disable, 1=enable) |
||
137 | // for specific path of parts (eg: /mymodule/core/modules/barcode) |
||
138 | // for specific css file (eg: /mymodule/css/mymodule.css.php) |
||
139 | //$this->module_parts = array( |
||
140 | // 'triggers' => 0, // Set this to 1 if module has its own trigger directory (core/triggers) |
||
141 | // 'login' => 0, // Set this to 1 if module has its own login method directory (core/login) |
||
142 | // 'substitutions' => 0, // Set this to 1 if module has its own substitution function file (core/substitutions) |
||
143 | // 'menus' => 0, // Set this to 1 if module has its own menus handler directory (core/menus) |
||
144 | // 'theme' => 0, // Set this to 1 if module has its own theme directory (theme) |
||
145 | // 'tpl' => 0, // Set this to 1 if module overwrite template dir (core/tpl) |
||
146 | // 'barcode' => 0, // Set this to 1 if module has its own barcode directory (core/modules/barcode) |
||
147 | // 'models' => 0, // Set this to 1 if module has its own models directory (core/modules/xxx) |
||
148 | // 'css' => array('/mymodule/css/mymodule.css.php'), // Set this to relative path of css file if module has its own css file |
||
149 | // 'js' => array('/mymodule/js/mymodule.js'), // Set this to relative path of js file if module must load a js on all pages |
||
150 | // 'hooks' => array('hookcontext1','hookcontext2',...) // Set here all hooks context managed by module. You can also set hook context 'all' |
||
151 | // 'dir' => array('output' => 'othermodulename'), // To force the default directories names |
||
152 | // 'workflow' => array('WORKFLOW_MODULE1_YOURACTIONTYPE_MODULE2'=>array('enabled'=>'! empty($conf->module1->enabled) && ! empty($conf->module2->enabled)', 'picto'=>'yourpicto@mymodule')) // Set here all workflow context managed by module |
||
153 | // ); |
||
154 | $this->module_parts = array(); |
||
155 | |||
156 | // Data directories to create when module is enabled. |
||
157 | $this->dirs = array(); |
||
158 | |||
159 | // Config pages. Put here list of php page, stored into mymodule/admin directory, to use to setup module. |
||
160 | $this->config_page_url = array(); |
||
161 | |||
162 | // Dependencies |
||
163 | $this->hidden = false; |
||
164 | $this->depends = array('modFlightBalloon'); |
||
165 | $this->requiredby = array(); |
||
166 | $this->conflictwith = array(); |
||
167 | $this->phpmin = array(5, 5); |
||
168 | $this->need_dolibarr_version = array(4, 0); |
||
169 | $this->langfiles = array("mymodule@flightLog"); |
||
170 | |||
171 | // Constants |
||
172 | $this->initConstants(); |
||
173 | |||
174 | // Array to add new pages in new tabs |
||
175 | $this->tabs = [ |
||
176 | 'user:+flights:Flights:mymodule@flightLog:$user->rights->flightLog->vol->access:/flightLog/list.php?search_fk_pilot=__ID__', |
||
177 | ]; |
||
178 | |||
179 | if (!isset($conf->flightLog) || !isset($conf->flightLog->enabled)) { |
||
180 | $conf->flightLog = new stdClass(); |
||
181 | $conf->flightLog->enabled = 0; |
||
182 | } |
||
183 | |||
184 | $this->boxes = []; |
||
185 | |||
186 | $this->initDictionnaries(); |
||
187 | $this->initCronJobs(); |
||
188 | $this->initMenu(); |
||
189 | $this->initPermissions(); |
||
190 | |||
191 | // Exports |
||
192 | $r = 0; |
||
193 | |||
194 | $this->export_code[$r] = $this->rights_class . '_' . $r; |
||
195 | $this->export_label[$r] = 'Flights export'; |
||
196 | $this->export_enabled[$r] = '1'; |
||
197 | $this->export_permission[$r] = array(array("flightLog", "vol", "detail")); |
||
198 | $this->export_fields_array[$r] = array( |
||
199 | "flight.idBBC_vols" => "Identifiant", |
||
200 | "flight.date" => "Date", |
||
201 | "flight.lieuD" => "Lieu décollage ", |
||
202 | "flight.lieuA" => "Lieu atterissage", |
||
203 | "flight.heureD" => "Heure décollage", |
||
204 | "flight.heureA" => "Heure atterissage", |
||
205 | "flight.BBC_ballons_idBBC_ballons" => "Identifiant ballon", |
||
206 | "flight.nbrPax" => "# pax", |
||
207 | "flight.remarque" => "Remarque", |
||
208 | "flight.incidents" => "Incidents", |
||
209 | "flight.fk_type" => "Identifiant type", |
||
210 | "flight.fk_pilot" => "Identifiant pilote", |
||
211 | "flight.fk_organisateur" => "Identifiant organisateur", |
||
212 | "flight.is_facture" => "Facture Oui/Non", |
||
213 | "flight.kilometers" => "# Km", |
||
214 | "flight.cost" => "Cout", |
||
215 | "flight.fk_receiver" => "Identifiant receveur d'argent", |
||
216 | "flight.justif_kilometers" => "Justificatif kilomètres", |
||
217 | "balloon.immat" => "Immat.", |
||
218 | "pilot.login" => "Pilote", |
||
219 | "flightType.nom" => "Type de vol", |
||
220 | "organisator.login" => "Organisateur", |
||
221 | "receiver.login" => "Percepteur", |
||
222 | ); |
||
223 | |||
224 | $this->export_TypeFields_array[$r] = [ |
||
225 | "flight.date" => "Date", |
||
226 | "flight.lieuD" => "Text", |
||
227 | "flight.lieuA" => "Text", |
||
228 | "flight.heureD" => "Text", |
||
229 | "flight.heureA" => "Text", |
||
230 | "flight.BBC_ballons_idBBC_ballons" => implode(":", ["List", "bbc_ballons", "immat", "rowid"]), |
||
231 | "flight.nbrPax" => "Numeric", |
||
232 | "flight.remarque" => "Text", |
||
233 | "flight.incidents" => "Text", |
||
234 | "flight.fk_type" => implode(":", ["List", "bbc_types", "nom", "idType"]), |
||
235 | "flight.fk_pilot" => implode(":", ["List", "user", "login", "rowid"]), |
||
236 | "flight.fk_organisateur" => implode(":", ["List", "user", "login", "rowid"]), |
||
237 | "flight.is_facture" => "Boolean", |
||
238 | "flight.kilometers" => "Numeric", |
||
239 | "flight.cost" => "Numeric", |
||
240 | "flight.fk_receiver" => implode(":", ["List", "user", "login", "rowid"]), |
||
241 | "flight.justif_kilometers" => "Text", |
||
242 | ]; |
||
243 | |||
244 | $this->export_entities_array[$r] = array( |
||
245 | "flight.idBBC_vols" => "Flight", |
||
246 | "flight.date" => "Flight", |
||
247 | "flight.lieuD" => "Flight", |
||
248 | "flight.lieuA" => "Flight", |
||
249 | "flight.heureD" => "Flight", |
||
250 | "flight.heureA" => "Flight", |
||
251 | "flight.BBC_ballons_idBBC_ballons" => "Flight", |
||
252 | "flight.nbrPax" => "Flight", |
||
253 | "flight.remarque" => "Flight", |
||
254 | "flight.incidents" => "Flight", |
||
255 | "flight.fk_type" => "Flight", |
||
256 | "flight.fk_pilot" => "Flight", |
||
257 | "flight.fk_organisateur" => "Flight", |
||
258 | "flight.is_facture" => "Flight", |
||
259 | "flight.kilometers" => "Flight", |
||
260 | "flight.cost" => "Flight", |
||
261 | "flight.fk_receiver" => "Flight", |
||
262 | "flight.justif_kilometers" => "Flight", |
||
263 | "balloon.immat" => "Balloon", |
||
264 | "pilot.login" => "Pilot", |
||
265 | "flightType.nom" => "FlightType", |
||
266 | "organisator.login" => "Organisator", |
||
267 | "receiver.login" => "Percepteur", |
||
268 | ); |
||
269 | $this->export_sql_start[$r] = 'SELECT DISTINCT '; |
||
270 | $this->export_sql_end[$r] = ' FROM ' . MAIN_DB_PREFIX . 'bbc_vols as flight'; |
||
271 | $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bbc_ballons as balloon on (flight.BBC_ballons_idBBC_ballons = balloon.rowid)'; |
||
272 | $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bbc_types as flightType on (flight.fk_type = flightType.idType)'; |
||
273 | $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'user as pilot on (flight.fk_pilot = pilot.rowid)'; |
||
274 | $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'user as organisator on (flight.fk_organisateur = organisator.rowid)'; |
||
275 | $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'user as receiver on (flight.fk_receiver = receiver.rowid)'; |
||
276 | $this->export_sql_end[$r] .= ' WHERE 1 = 1'; |
||
277 | $r++; |
||
278 | } |
||
279 | |||
541 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.