| Conditions | 31 |
| Paths | 816 |
| Total Lines | 95 |
| Code Lines | 61 |
| Lines | 8 |
| Ratio | 8.42 % |
| 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 |
||
| 16 | function action_editer_site_dist($arg=null) { |
||
| 17 | |||
| 18 | if (is_null($arg)){ |
||
| 19 | $securiser_action = charger_fonction('securiser_action', 'inc'); |
||
| 20 | $arg = $securiser_action(); |
||
| 21 | } |
||
| 22 | $resyndiquer = false; |
||
| 23 | |||
| 24 | include_spip('inc/filtres'); // pour vider_url() |
||
| 25 | |||
| 26 | if (preg_match(',options/(\d+),',$arg, $r)) { |
||
| 27 | $id_syndic = $r[1]; |
||
| 28 | $resyndiquer = editer_site_options($id_syndic); |
||
| 29 | // Envoi depuis le formulaire d'edition d'un site existant |
||
| 30 | } else if ($id_syndic = intval($arg)) { |
||
| 31 | // reload si on change une des valeurs de syndication |
||
| 32 | if ( |
||
| 33 | (_request('url_syndic') OR _request('resume') OR _request('syndication')) |
||
| 34 | AND $t = sql_fetsel('url_syndic,syndication,resume', 'spip_syndic', "id_syndic=".sql_quote($id_syndic)) |
||
| 35 | AND ( |
||
| 36 | (_request('url_syndic') AND _request('url_syndic') != $t['url_syndic']) |
||
| 37 | OR |
||
| 38 | (_request('syndication') AND _request('syndication') != $t['syndication']) |
||
| 39 | OR |
||
| 40 | (_request('resume') AND _request('resume') != $t['resume']) |
||
| 41 | ) |
||
| 42 | ) |
||
| 43 | set_request('reload', 'oui'); |
||
| 44 | revisions_sites($id_syndic); |
||
| 45 | |||
| 46 | // Envoi normal depuis le formulaire de creation d'un site |
||
| 47 | } |
||
| 48 | elseif (strlen(vider_url(_request('url_site'))) |
||
| 49 | AND strlen(_request('nom_site'))) { |
||
| 50 | set_request('reload', 'oui'); |
||
| 51 | $id_syndic = insert_syndic(_request('id_parent')); |
||
| 52 | revisions_sites($id_syndic); |
||
| 53 | if ($logo = _request('logo') |
||
| 54 | AND $format_logo = _request('format_logo')){ |
||
| 55 | include_spip('inc/distant'); |
||
| 56 | @rename(copie_locale($logo), |
||
|
|
|||
| 57 | _DIR_IMG . 'siteon'.$id_syndic.'.'.$format_logo); |
||
| 58 | } |
||
| 59 | } |
||
| 60 | // Erreur |
||
| 61 | else { |
||
| 62 | include_spip('inc/headers'); |
||
| 63 | redirige_url_ecrire(); |
||
| 64 | } |
||
| 65 | |||
| 66 | // Re-syndiquer le site |
||
| 67 | if (_request('reload') == 'oui') { |
||
| 68 | // Effacer les messages si on supprime la syndication |
||
| 69 | if (_request('syndication') == 'non') |
||
| 70 | sql_delete("spip_syndic_articles", "id_syndic=".sql_quote($id_syndic)); |
||
| 71 | |||
| 72 | $t = sql_getfetsel('descriptif', 'spip_syndic', "id_syndic=$id_syndic AND syndication IN ('oui', 'sus', 'off')", '','', 1); |
||
| 73 | if ($t !== NULL) { |
||
| 74 | |||
| 75 | // Si descriptif vide, chercher le logo si pas deja la |
||
| 76 | $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
||
| 77 | if (!$logo = $chercher_logo($id_syndic, 'id_syndic', 'on') |
||
| 78 | OR !$t) { |
||
| 79 | if ($auto = vider_url(_request('url_auto'))) { |
||
| 80 | $auto = analyser_site($auto); |
||
| 81 | if (!strlen($t) AND strlen($auto['descriptif'])) |
||
| 82 | revisions_sites($id_syndic, array('descriptif' => $auto['descriptif'])); |
||
| 83 | } |
||
| 84 | if (!$logo |
||
| 85 | AND $auto['logo'] AND $auto['format_logo']) |
||
| 86 | @rename($auto['logo'], |
||
| 87 | _DIR_IMG . 'siteon'.$id_syndic.'.'.$auto['format_logo']); |
||
| 88 | } |
||
| 89 | $resyndiquer = true; |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 93 | if ($resyndiquer) { |
||
| 94 | // ah si PHP connaisait les fermetures... |
||
| 95 | // A la place, une constante utilisee exclusivement |
||
| 96 | // dans la fct suivante. |
||
| 97 | define('_GENIE_SYNDIC_NOW', $id_syndic); |
||
| 98 | // forcer l'execution immediate de cette tache |
||
| 99 | // (i.e. appeler la fct suivante avec gestion du verrou) |
||
| 100 | cron(0, array('syndic' => -91)); |
||
| 101 | } |
||
| 102 | View Code Duplication | if (_request('redirect')) { |
|
| 103 | $redirect = parametre_url(urldecode(_request('redirect')), |
||
| 104 | 'id_syndic', $id_syndic, '&'); |
||
| 105 | include_spip('inc/headers'); |
||
| 106 | redirige_par_entete($redirect); |
||
| 107 | } |
||
| 108 | else |
||
| 109 | return array($id_syndic,''); |
||
| 110 | } |
||
| 111 | |||
| 291 |
If you suppress an error, we recommend checking for the error condition explicitly: