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 |
||
64 | function changeDB() |
||
65 | { |
||
66 | global $spanish_vals, $french_vals, $english_vals, $dbTmp; |
||
67 | $res = mysqli_query($dbTmp, "SELECT * FROM ".$pre."log_items") or die(mysqli_error($dbTmp)); |
||
|
|||
68 | while ($data = mysqli_fetch_array($res)) { |
||
69 | $action = ""; |
||
70 | //ENGLISH |
||
71 | View Code Duplication | foreach ($english_vals as $lang) { |
|
72 | if ($lang[1] == $data['action']) { |
||
73 | mysqli_query($dbTmp, "UPDATE ".$pre."log_items SET action = '".$lang[0]."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']); |
||
74 | $found = true; |
||
75 | $action = $lang[0]; |
||
76 | } |
||
77 | if ($lang[1] == $data['raison'] && !empty($data['raison'])) { |
||
78 | mysqli_query($dbTmp, "UPDATE ".$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']."'"); |
||
79 | $found = true; |
||
80 | } elseif ($lang[1] == trim(substr($data['raison'], 0, strpos($data['raison'], ":"))) && !empty($data['raison'])) { |
||
81 | $data1 = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT action FROM ".$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."'")); |
||
82 | mysqli_query($dbTmp, "UPDATE ".$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]."'"); |
||
83 | $found = true; |
||
84 | } |
||
85 | } |
||
86 | |||
87 | //FRENCH |
||
88 | $action = ""; |
||
89 | View Code Duplication | foreach ($french_vals as $lang) { |
|
90 | if ($lang[1] == $data['action']) { |
||
91 | mysqli_query($dbTmp, "UPDATE ".$pre."log_items SET action = '".$lang[0]."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']); |
||
92 | $found = true; |
||
93 | $action = $lang[0]; |
||
94 | } |
||
95 | if ($lang[1] == $data['raison'] && !empty($data['raison'])) { |
||
96 | mysqli_query($dbTmp, "UPDATE ".$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']."'"); |
||
97 | $found = true; |
||
98 | } elseif ($lang[1] == trim(substr($data['raison'], 0, strpos($data['raison'], ":"))) && !empty($data['raison'])) { |
||
99 | $data1 = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT action FROM ".$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."'")); |
||
100 | mysqli_query($dbTmp, "UPDATE ".$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]."'"); |
||
101 | $found = true; |
||
102 | } |
||
103 | } |
||
104 | |||
105 | //SPANISH |
||
106 | $action = ""; |
||
107 | View Code Duplication | foreach ($spanish_vals as $lang) { |
|
108 | if ($lang[1] == $data['action']) { |
||
109 | mysqli_query($dbTmp, "UPDATE ".$pre."log_items SET action = '".$lang[0]."' WHERE id_item=".$data['id_item']." AND date =".$data['date']." AND id_user =".$data['id_user']); |
||
110 | $found = true; |
||
111 | $action = $lang[0]; |
||
112 | } |
||
113 | if ($lang[1] == $data['raison'] && !empty($data['raison'])) { |
||
114 | mysqli_query($dbTmp, "UPDATE ".$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']."'"); |
||
115 | $found = true; |
||
116 | } elseif ($lang[1] == trim(substr($data['raison'], 0, strpos($data['raison'], ":"))) && !empty($data['raison'])) { |
||
117 | $data1 = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT action FROM ".$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."'")); |
||
118 | mysqli_query($dbTmp, "UPDATE ".$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]."'"); |
||
119 | $found = true; |
||
120 | } |
||
121 | } |
||
122 | } |
||
123 | } |
||
124 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.