| Conditions | 10 |
| Paths | 18 |
| Total Lines | 69 |
| 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 |
||
| 76 | function logo_modifier($objet, $id_objet, $etat, $source) { |
||
| 77 | $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
||
| 78 | $objet = objet_type($objet); |
||
| 79 | $primary = id_table_objet($objet); |
||
| 80 | include_spip('inc/chercher_logo'); |
||
| 81 | |||
| 82 | $mode = preg_replace(",\W,", '', $etat); |
||
| 83 | if (!$mode){ |
||
| 84 | spip_log("logo_modifier : etat $etat invalide", 'logo'); |
||
| 85 | $erreur = 'etat invalide'; |
||
| 86 | |||
| 87 | return $erreur; |
||
| 88 | } |
||
| 89 | // chercher dans la base |
||
| 90 | $mode_document = 'logo' . $mode; |
||
| 91 | |||
| 92 | // supprimer le logo eventueel existant |
||
| 93 | // TODO : si un logo existe, le modifier plutot que supprimer + reinserer (mais il faut gerer le cas ou il est utilise par plusieurs objets, donc pas si simple) |
||
| 94 | // mais de toute facon l'interface actuelle oblige a supprimer + reinserer |
||
| 95 | logo_supprimer($objet, $id_objet, $etat); |
||
| 96 | |||
| 97 | |||
| 98 | include_spip('inc/documents'); |
||
| 99 | $erreur = ''; |
||
| 100 | |||
| 101 | if (!$source) { |
||
| 102 | spip_log('spip_image_ajouter : source inconnue', 'logo'); |
||
| 103 | $erreur = 'source inconnue'; |
||
| 104 | |||
| 105 | return $erreur; |
||
| 106 | } |
||
| 107 | |||
| 108 | // fichier dans upload/ |
||
| 109 | if (is_string($source)) { |
||
| 110 | $tmp_name = false; |
||
| 111 | if (file_exists($source)) { |
||
| 112 | $tmp_name = $source; |
||
| 113 | } elseif (file_exists($f = determine_upload() . $source)) { |
||
| 114 | $tmp_name = $f; |
||
| 115 | } |
||
| 116 | if (!$tmp_name) { |
||
| 117 | spip_log('spip_image_ajouter : source inconnue', 'logo'); |
||
| 118 | $erreur = 'source inconnue'; |
||
| 119 | |||
| 120 | return $erreur; |
||
| 121 | } |
||
| 122 | $source = array( |
||
| 123 | 'tmp_name' => $tmp_name, |
||
| 124 | 'name' => basename($tmp_name), |
||
| 125 | ); |
||
| 126 | } elseif ($erreur = check_upload_error($source['error'], '', true)) { |
||
| 127 | return $erreur; |
||
| 128 | } |
||
| 129 | |||
| 130 | $source['mode'] = $mode_document; |
||
| 131 | $ajouter_documents = charger_fonction('ajouter_documents', 'action'); |
||
| 132 | $ajoutes = $ajouter_documents('new', [$source], $objet, $id_objet, $mode_document); |
||
| 133 | |||
| 134 | $id_document = reset($ajoutes); |
||
| 135 | |||
| 136 | if (!is_numeric($id_document)) { |
||
| 137 | $erreur = ($id_document ? $id_document : 'Erreur inconnue'); |
||
| 138 | spip_log("Erreur ajout logo : $erreur pour source=".json_encode($source), 'logo'); |
||
| 139 | return $erreur; |
||
| 140 | } |
||
| 141 | |||
| 142 | return ''; // tout est bon, pas d'erreur |
||
| 143 | |||
| 144 | } |
||
| 145 | |||
| 182 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.If the return type contains the type array, this check recommends the use of a more specific type like
String[]orarray<String>.