| Conditions | 4 |
| Paths | 6 |
| Total Lines | 56 |
| 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 |
||
| 20 | function install_etape_ldap4_dist() { |
||
| 21 | $adresse_ldap = _request('adresse_ldap'); |
||
| 22 | $login_ldap = _request('login_ldap'); |
||
| 23 | $pass_ldap = _request('pass_ldap'); |
||
| 24 | $port_ldap = _request('port_ldap'); |
||
| 25 | $base_ldap = _request('base_ldap'); |
||
| 26 | $base_ldap_text = _request('base_ldap_text'); |
||
| 27 | if (!$base_ldap) { |
||
| 28 | $base_ldap = $base_ldap_text; |
||
| 29 | } |
||
| 30 | |||
| 31 | echo install_debut_html('AUTO', ' onload="document.getElementById(\'suivant\').focus();return false;"'); |
||
| 32 | |||
| 33 | $ldap_link = ldap_connect($adresse_ldap, $port_ldap); |
||
| 34 | @ldap_bind($ldap_link, $login_ldap, $pass_ldap); |
||
|
|
|||
| 35 | |||
| 36 | // Essayer de verifier le chemin fourni |
||
| 37 | $r = @ldap_compare($ldap_link, $base_ldap, 'objectClass', ''); |
||
| 38 | $fail = (ldap_errno($ldap_link) == 32); |
||
| 39 | |||
| 40 | if ($fail) { |
||
| 41 | echo info_etape(_T('info_chemin_acces_annuaire')), |
||
| 42 | info_progression_etape(3, 'etape_ldap', 'install/', true), |
||
| 43 | "<div class='error'><p><b>" . _T('avis_operation_echec') . '</b></p><p>' . _T('avis_chemin_invalide_1'), |
||
| 44 | ' (<tt>' . spip_htmlspecialchars($base_ldap) . '</tt>) ' . _T('avis_chemin_invalide_2') . '</p></div>'; |
||
| 45 | } else { |
||
| 46 | info_etape(_T('info_reglage_ldap')); |
||
| 47 | echo info_progression_etape(4, 'etape_ldap', 'install/'); |
||
| 48 | |||
| 49 | $statuts = liste_statuts_ldap(); |
||
| 50 | $statut_ldap = defined('_INSTALL_STATUT_LDAP') |
||
| 51 | ? _INSTALL_STATUT_LDAP |
||
| 52 | : $GLOBALS['liste_des_statuts']['info_redacteurs']; |
||
| 53 | |||
| 54 | |||
| 55 | $res = install_propager(array('adresse_ldap', 'port_ldap', 'login_ldap', 'pass_ldap', 'protocole_ldap', 'tls_ldap')) |
||
| 56 | . "<input type='hidden' name='etape' value='ldap5' />" |
||
| 57 | . "<input type='hidden' name='base_ldap' value='" . spip_htmlentities($base_ldap) . "' />" |
||
| 58 | . fieldset( |
||
| 59 | _T('info_statut_utilisateurs_1'), |
||
| 60 | array( |
||
| 61 | 'statut_ldap' => array( |
||
| 62 | 'label' => _T('info_statut_utilisateurs_2') . '<br />', |
||
| 63 | 'valeur' => $statut_ldap, |
||
| 64 | 'alternatives' => $statuts |
||
| 65 | ) |
||
| 66 | ) |
||
| 67 | ) |
||
| 68 | . install_ldap_correspondances() |
||
| 69 | . bouton_suivant(); |
||
| 70 | |||
| 71 | echo generer_form_ecrire('install', $res); |
||
| 72 | } |
||
| 73 | |||
| 74 | echo install_fin_html(); |
||
| 75 | } |
||
| 76 | |||
| 109 |
If you suppress an error, we recommend checking for the error condition explicitly: