| Conditions | 11 |
| Paths | 25 |
| Total Lines | 46 |
| Lines | 10 |
| Ratio | 21.74 % |
| 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 |
||
| 36 | function maj_timestamp_mysql($tables = null) { |
||
| 37 | |||
| 38 | include_spip('base/dump'); |
||
| 39 | if (is_null($tables)) { |
||
| 40 | $tables = base_lister_toutes_tables(); |
||
| 41 | } elseif (is_string($tables)) { |
||
| 42 | $tables = [$tables]; |
||
| 43 | } elseif (!is_array($tables)) { |
||
| 44 | return; |
||
| 45 | } |
||
| 46 | |||
| 47 | // rien a faire si base non mysql |
||
| 48 | if (strncmp($GLOBALS['connexions'][0]['type'], 'mysql', 5) !== 0) { |
||
| 49 | return; |
||
| 50 | } |
||
| 51 | |||
| 52 | $trouver_table = charger_fonction('trouver_table', 'base'); |
||
| 53 | // forcer le vidage de cache |
||
| 54 | $trouver_table(''); |
||
| 55 | |||
| 56 | foreach ($tables as $table) { |
||
| 57 | if (time() >= _TIME_OUT) { |
||
| 58 | return; |
||
| 59 | } |
||
| 60 | if ($desc = $trouver_table($table)) { |
||
| 61 | $fields_corrected = _mysql_remplacements_definitions_table($desc['field']); |
||
| 62 | $d = array_diff($desc['field'], $fields_corrected); |
||
| 63 | if ($d) { |
||
|
|
|||
| 64 | spip_log("Table $table TIMESTAMP incorrect", "maj"); |
||
| 65 | View Code Duplication | foreach ($desc['field'] as $field => $type) { |
|
| 66 | if ($desc['field'][$field] !== $fields_corrected[$field]) { |
||
| 67 | spip_log("Adaptation TIMESTAMP table $table", "maj." . _LOG_INFO_IMPORTANTE); |
||
| 68 | sql_alter("table $table change $field $field " . $fields_corrected[$field]); |
||
| 69 | $trouver_table(''); |
||
| 70 | $new_desc = $trouver_table($table); |
||
| 71 | spip_log("Apres conversion $table : " . var_export($new_desc['field'], true), |
||
| 72 | "maj." . _LOG_INFO_IMPORTANTE); |
||
| 73 | } |
||
| 74 | } |
||
| 75 | } |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 79 | // forcer le vidage de cache |
||
| 80 | $trouver_table(''); |
||
| 81 | } |
||
| 82 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.