| Conditions | 10 |
| Paths | 28 |
| Total Lines | 67 |
| 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 |
||
| 23 | public function loginPostLoginProvide(\RainLoop\Model\Account &$oAccount) |
||
| 24 | { |
||
| 25 | $dbservername = \trim($this->Config()->Get('plugin', 'hamilserver', '')); |
||
| 26 | $dbusername = \trim($this->Config()->Get('plugin', 'hmaildbusername', '')); |
||
| 27 | $dbpassword = \trim($this->Config()->Get('plugin', 'hmaildbpassword', '')); |
||
| 28 | $dbname = \trim($this->Config()->Get('plugin', 'hmaildbtable', '')); |
||
| 29 | $dbport = \trim($this->Config()->Get('plugin', 'hmaildbport', '')); |
||
| 30 | $datadir = \trim($this->Config()->Get('plugin', 'rainloopDatalocation', '')); |
||
| 31 | |||
| 32 | if ($datadir != ""){ |
||
| 33 | $userpath = $datadir.'data/_data_/_default_/storage/cfg/'.substr($oAccount->Email(), 0, 2).'/'.$oAccount->Email().'/identities'; |
||
| 34 | } else { |
||
| 35 | $userpath = APP_INDEX_ROOT_PATH.'_data_/_default_/storage/cfg/'.substr($oAccount->Email(), 0, 2).'/'.$oAccount->Email().'/identities'; |
||
| 36 | } |
||
| 37 | |||
| 38 | $hmailconn = mysqli_connect($dbservername, $dbusername, $dbpassword, $dbname, $dbport); |
||
| 39 | |||
| 40 | // Check connection |
||
| 41 | if (!$hmailconn) { |
||
| 42 | echo "Hmail-aliases: connection to db failed"; |
||
| 43 | return; |
||
| 44 | } |
||
| 45 | //Get aliases |
||
| 46 | $result = $hmailconn->query("SELECT * FROM " . $dbname . ".hm_aliases WHERE aliasvalue='".$oAccount->Email()."'"); |
||
| 47 | |||
| 48 | if ($result->num_rows > 0) { |
||
| 49 | $newidentitiesobj = array(); |
||
| 50 | |||
| 51 | //Get user account |
||
| 52 | $result2 = $hmailconn->query("SELECT * FROM " . $dbname . ".hm_accounts WHERE accountaddress='".$oAccount->Email()."'"); |
||
| 53 | $result2 = $result2->fetch_assoc(); |
||
| 54 | $firstname = $result2['accountpersonfirstname']; |
||
| 55 | $lastname = $result2['accountpersonlastname']; |
||
| 56 | |||
| 57 | if ($firstname == "" && $lastname == "") { |
||
| 58 | $name = ""; |
||
| 59 | } else { |
||
| 60 | $name = $firstname." ".$lastname; |
||
| 61 | } |
||
| 62 | |||
| 63 | //Get existing settings. If not a alias created by hmail. Transfer settings to the new array. |
||
| 64 | $identities = file_get_contents($userpath, true); |
||
| 65 | if ($identities != "") { |
||
| 66 | $identities = json_decode($identities, true); |
||
| 67 | error_log(print_r($identities, true)); |
||
| 68 | foreach ($identities as $row) { |
||
| 69 | if (strpos($row['Id'], 'HMAIL') === false) { |
||
| 70 | array_push($newidentitiesobj, $row); |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | // output data of each row |
||
| 76 | while ($row = $result->fetch_assoc()) { |
||
| 77 | $obj = array(); |
||
| 78 | $obj['Id'] = "HMAIL".base64_encode($row["aliasname"]); |
||
| 79 | $obj['Email'] = $row["aliasname"]; |
||
| 80 | $obj['Name'] = $name; |
||
| 81 | $obj['ReplyTo'] = ""; |
||
| 82 | $obj['Bcc'] = ""; |
||
| 83 | $obj['Signature'] = ""; |
||
| 84 | $obj['SignatureInsertBefore'] = false; |
||
| 85 | array_push($newidentitiesobj, $obj); |
||
| 86 | } |
||
| 87 | file_put_contents($userpath, json_encode($newidentitiesobj)); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 114 |