| Conditions | 21 |
| Paths | 688 |
| Total Lines | 60 |
| Code Lines | 43 |
| Lines | 45 |
| Ratio | 75 % |
| 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 |
||
| 65 | function changeDB() |
||
| 66 | { |
||
| 67 | global $k, $spanish_vals, $french_vals, $english_vals, $dbTmp; |
||
| 68 | $res = mysqli_query($dbTmp, "SELECT * FROM ".$_SESSION['pre']."log_items") or die(mysqli_error($dbTmp)); |
||
| 69 | while ($data = mysqli_fetch_array($res)) { |
||
| 70 | $action = ""; |
||
| 71 | //ENGLISH |
||
| 72 | View Code Duplication | foreach ($english_vals as $lang) { |
|
| 73 | if ($lang[1] == $data['action']) { |
||
| 74 | mysqli_query($dbTmp, "UPDATE ".$_SESSION['pre']."log_items SET action = '".$lang[0]."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']); |
||
| 75 | $found = true; |
||
|
|
|||
| 76 | $action = $lang[0]; |
||
| 77 | } |
||
| 78 | if ($lang[1] == $data['raison'] && !empty($data['raison'])) { |
||
| 79 | mysqli_query($dbTmp, "UPDATE ".$_SESSION['pre']."log_items SET raison = '".$lang[0]."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$data['action']."'"); |
||
| 80 | $found = true; |
||
| 81 | } elseif ($lang[1] == trim(substr($data['raison'], 0, strpos($data['raison'], ":"))) && !empty($data['raison'])) { |
||
| 82 | $data1 = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT action FROM ".$_SESSION['pre']."log_items WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$action."'")); |
||
| 83 | mysqli_query($dbTmp, "UPDATE ".$_SESSION['pre']."log_items SET raison = '".$lang[0]." ".substr($data['raison'], strpos($data['raison'], ":"))."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$data1[0]."'"); |
||
| 84 | $found = true; |
||
| 85 | } |
||
| 86 | } |
||
| 87 | |||
| 88 | //FRENCH |
||
| 89 | $action = ""; |
||
| 90 | View Code Duplication | foreach ($french_vals as $lang) { |
|
| 91 | if ($lang[1] == $data['action']) { |
||
| 92 | mysqli_query($dbTmp, "UPDATE ".$_SESSION['pre']."log_items SET action = '".$lang[0]."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']); |
||
| 93 | $found = true; |
||
| 94 | $action = $lang[0]; |
||
| 95 | } |
||
| 96 | if ($lang[1] == $data['raison'] && !empty($data['raison'])) { |
||
| 97 | mysqli_query($dbTmp, "UPDATE ".$_SESSION['pre']."log_items SET raison = '".$lang[0]."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$data['action']."'"); |
||
| 98 | $found = true; |
||
| 99 | } elseif ($lang[1] == trim(substr($data['raison'], 0, strpos($data['raison'], ":"))) && !empty($data['raison'])) { |
||
| 100 | $data1 = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT action FROM ".$_SESSION['pre']."log_items WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$action."'")); |
||
| 101 | mysqli_query($dbTmp, "UPDATE ".$_SESSION['pre']."log_items SET raison = '".$lang[0]." ".substr($data['raison'], strpos($data['raison'], ":"))."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$data1[0]."'"); |
||
| 102 | $found = true; |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 106 | //SPANISH |
||
| 107 | $action = ""; |
||
| 108 | View Code Duplication | foreach ($spanish_vals as $lang) { |
|
| 109 | if ($lang[1] == $data['action']) { |
||
| 110 | mysqli_query($dbTmp, "UPDATE ".$_SESSION['pre']."log_items SET action = '".$lang[0]."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']); |
||
| 111 | $found = true; |
||
| 112 | $action = $lang[0]; |
||
| 113 | } |
||
| 114 | if ($lang[1] == $data['raison'] && !empty($data['raison'])) { |
||
| 115 | mysqli_query($dbTmp, "UPDATE ".$_SESSION['pre']."log_items SET raison = '".$lang[0]."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$data['action']."'"); |
||
| 116 | $found = true; |
||
| 117 | } elseif ($lang[1] == trim(substr($data['raison'], 0, strpos($data['raison'], ":"))) && !empty($data['raison'])) { |
||
| 118 | $data1 = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT action FROM ".$_SESSION['pre']."log_items WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$action."'")); |
||
| 119 | mysqli_query($dbTmp, "UPDATE ".$_SESSION['pre']."log_items SET raison = '".$lang[0]." ".substr($data['raison'], strpos($data['raison'], ":"))."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']." AND raison ='".$data['raison']."' AND action ='".$data1[0]."'"); |
||
| 120 | $found = true; |
||
| 121 | } |
||
| 122 | } |
||
| 123 | } |
||
| 124 | } |
||
| 125 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.