| Conditions | 28 |
| Paths | 7201 |
| Total Lines | 111 |
| Code Lines | 70 |
| Lines | 7 |
| Ratio | 6.31 % |
| 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 |
||
| 226 | function auteur_instituer($id_auteur, $c, $force_webmestre = false) { |
||
| 227 | if (!$id_auteur=intval($id_auteur)) |
||
| 228 | return false; |
||
| 229 | $erreurs = array(); // contiendra les differentes erreurs a traduire par _T() |
||
| 230 | $champs = array(); |
||
| 231 | |||
| 232 | // les memoriser pour les faire passer dans le pipeline pre_edition |
||
| 233 | View Code Duplication | if (isset($c['login']) AND strlen($c['login'])) |
|
| 234 | $champs['login'] = $c['login']; |
||
| 235 | View Code Duplication | if (isset($c['pass']) AND strlen($c['pass'])) |
|
| 236 | $champs['pass'] = $c['pass']; |
||
| 237 | |||
| 238 | $statut = $statut_ancien = sql_getfetsel('statut','spip_auteurs','id_auteur='.intval($id_auteur)); |
||
| 239 | |||
| 240 | if (isset($c['statut']) |
||
| 241 | AND (autoriser('modifier', 'auteur', $id_auteur,null, array('statut' => $c['statut'])))) |
||
| 242 | $statut = $champs['statut'] = $c['statut']; |
||
| 243 | |||
| 244 | // Restreindre avant de declarer l'auteur |
||
| 245 | // (section critique sur les droits) |
||
| 246 | if ($c['id_parent']) { |
||
| 247 | if (is_array($c['restreintes'])) |
||
| 248 | $c['restreintes'][] = $c['id_parent']; |
||
| 249 | else |
||
| 250 | $c['restreintes'] = array($c['id_parent']); |
||
| 251 | } |
||
| 252 | |||
| 253 | if (isset($c['webmestre']) |
||
| 254 | AND ($force_webmestre OR autoriser('modifier', 'auteur', $id_auteur,null, array('webmestre' => '?')))) |
||
| 255 | $champs['webmestre'] = $c['webmestre']=='oui'?'oui':'non'; |
||
| 256 | |||
| 257 | // Envoyer aux plugins |
||
| 258 | $champs = pipeline('pre_edition', |
||
| 259 | array( |
||
| 260 | 'args' => array( |
||
| 261 | 'table' => 'spip_auteurs', |
||
| 262 | 'id_objet' => $id_auteur, |
||
| 263 | 'action' => 'instituer', |
||
| 264 | 'statut_ancien' => $statut_ancien, |
||
| 265 | ), |
||
| 266 | 'data' => $champs |
||
| 267 | ) |
||
| 268 | ); |
||
| 269 | |||
| 270 | if (is_array($c['restreintes']) |
||
| 271 | AND autoriser('modifier', 'auteur', $id_auteur, NULL, array('restreint'=>$c['restreintes']))) { |
||
| 272 | $rubriques = array_map('intval',$c['restreintes']); |
||
| 273 | $rubriques = array_unique($rubriques); |
||
| 274 | $rubriques = array_diff($rubriques,array(0)); |
||
| 275 | auteur_dissocier($id_auteur, array('rubrique'=>'*')); |
||
| 276 | auteur_associer($id_auteur,array('rubrique'=>$rubriques)); |
||
| 277 | } |
||
| 278 | |||
| 279 | $flag_ecrire_acces = false; |
||
| 280 | // commencer par traiter les cas particuliers des logins et pass |
||
| 281 | // avant les autres ecritures en base |
||
| 282 | if (isset($champs['login']) OR isset($champs['pass'])){ |
||
| 283 | $auth_methode = sql_getfetsel('source','spip_auteurs','id_auteur='.intval($id_auteur)); |
||
| 284 | include_spip('inc/auth'); |
||
| 285 | View Code Duplication | if (isset($champs['login']) AND strlen($champs['login'])) |
|
| 286 | if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) |
||
| 287 | $erreurs[] = 'ecrire:impossible_modifier_login_auteur'; |
||
| 288 | if (isset($champs['pass']) AND strlen($champs['pass'])){ |
||
| 289 | $champs['login'] = sql_getfetsel('login','spip_auteurs','id_auteur='.intval($id_auteur)); |
||
| 290 | if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) |
||
| 291 | $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
||
| 292 | } |
||
| 293 | unset($champs['login']); |
||
| 294 | unset($champs['pass']); |
||
| 295 | $flag_ecrire_acces = true; |
||
| 296 | } |
||
| 297 | |||
| 298 | if (!count($champs)) return implode(' ', array_map('_T', $erreurs)); |
||
| 299 | sql_updateq('spip_auteurs', $champs , 'id_auteur='.$id_auteur); |
||
| 300 | |||
| 301 | // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin |
||
| 302 | if ($flag_ecrire_acces |
||
| 303 | OR isset($champs['statut']) |
||
| 304 | ) { |
||
| 305 | include_spip('inc/acces'); |
||
| 306 | ecrire_acces(); |
||
| 307 | } |
||
| 308 | |||
| 309 | // Invalider les caches |
||
| 310 | include_spip('inc/invalideur'); |
||
| 311 | suivre_invalideur("id='auteur/$id_auteur'"); |
||
| 312 | |||
| 313 | // Pipeline |
||
| 314 | pipeline('post_edition', |
||
| 315 | array( |
||
| 316 | 'args' => array( |
||
| 317 | 'table' => 'spip_auteurs', |
||
| 318 | 'id_objet' => $id_auteur, |
||
| 319 | 'action' => 'instituer', |
||
| 320 | 'statut_ancien' => $statut_ancien, |
||
| 321 | ), |
||
| 322 | 'data' => $champs |
||
| 323 | ) |
||
| 324 | ); |
||
| 325 | |||
| 326 | |||
| 327 | // Notifications |
||
| 328 | if ($notifications = charger_fonction('notifications', 'inc')) { |
||
| 329 | $notifications('instituerauteur', $id_auteur, |
||
| 330 | array('statut' => $statut, 'statut_ancien' => $statut_ancien) |
||
| 331 | ); |
||
| 332 | } |
||
| 333 | |||
| 334 | return implode(' ', array_map('_T', $erreurs)); |
||
| 335 | |||
| 336 | } |
||
| 337 | |||
| 356 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.