| Conditions | 8 |
| Paths | 9 |
| Total Lines | 64 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 34 | private function migrateMailConf(string $oldMailConfPath): array |
||
| 35 | { |
||
| 36 | if (!file_exists($oldMailConfPath)) { |
||
| 37 | return []; |
||
| 38 | } |
||
| 39 | |||
| 40 | include $oldMailConfPath; |
||
| 41 | |||
| 42 | global $platform_email; |
||
| 43 | |||
| 44 | $mailerScheme = 'null'; |
||
| 45 | $query = ''; |
||
| 46 | |||
| 47 | if (!empty($smtpSecure)) { |
||
|
|
|||
| 48 | $mailerScheme = 'smtp'; |
||
| 49 | |||
| 50 | if ($smtpSecure === 'ssl') { |
||
| 51 | $mailerScheme = 'smtps'; |
||
| 52 | } elseif ($smtpSecure === 'tls') { |
||
| 53 | $query = '?encryption=tls'; |
||
| 54 | } |
||
| 55 | } |
||
| 56 | |||
| 57 | $dsn = sprintf( |
||
| 58 | '%s://%s%s@%s:%s%s', |
||
| 59 | $mailerScheme, |
||
| 60 | !empty($platform_email['SMTP_AUTH']) ? ($platform_email['SMTP_USER'] ?? '') : '', |
||
| 61 | !empty($platform_email['SMTP_AUTH']) ? ':'.($platform_email['SMTP_PASS'] ?? '') : '', |
||
| 62 | $platform_email['SMTP_HOST'] ?? '', |
||
| 63 | $platform_email['SMTP_PORT'] ?? '', |
||
| 64 | $query |
||
| 65 | ); |
||
| 66 | |||
| 67 | $dkim = [ |
||
| 68 | 'enable' => $platform_email['DKIM'] ?? false, |
||
| 69 | 'selector' => $platform_email['DKIM_SELECTOR'] ?? '', |
||
| 70 | 'domain' => $platform_email['DKIM_DOMAIN'] ?? '', |
||
| 71 | 'private_key_string' => $platform_email['DKIM_PRIVATE_KEY_STRING'] ?? '', |
||
| 72 | 'private_key' => $platform_email['DKIM_PRIVATE_KEY'] ?? '', |
||
| 73 | 'passphrase' => $platform_email['DKIM_PASSPHRASE'] ?? '', |
||
| 74 | ]; |
||
| 75 | |||
| 76 | $xoauth2 = [ |
||
| 77 | 'method' => $platform_email['XOAUTH2_METHOD'] ?? false, |
||
| 78 | 'url_authorize' => $platform_email['XOAUTH2_URL_AUTHORIZE'] ?? '', |
||
| 79 | 'url_access_token' => $platform_email['XOAUTH2_URL_ACCES_TOKEN'] ?? '', |
||
| 80 | 'url_resource_owner_details' => $platform_email['XOAUTH2_URL_RESOURCE_OWNER_DETAILS'] ?? '', |
||
| 81 | 'scopes' => $platform_email['XOAUTH2_SCOPES'] ?? '', |
||
| 82 | 'client_id' => $platform_email['XOAUTH2_CLIENT_ID'] ?? '', |
||
| 83 | 'client_secret' => $platform_email['XOAUTH2_CLIENT_SECRET'] ?? '', |
||
| 84 | 'refresh_token' => $platform_email['XOAUTH2_REFRESH_TOKEN'] ?? '', |
||
| 85 | ]; |
||
| 86 | |||
| 87 | // SMTP_UNIQUE_SENDER intentionally ignored as requested. |
||
| 88 | |||
| 89 | return [ |
||
| 90 | 'mailer_from_email' => $platform_email['SMTP_FROM_EMAIL'] ?? '', |
||
| 91 | 'mailer_from_name' => $platform_email['SMTP_FROM_NAME'] ?? '', |
||
| 92 | 'mailer_dsn' => $dsn, |
||
| 93 | 'mailer_mails_charset' => $platform_email['SMTP_CHARSET'] ?? 'UTF-8', |
||
| 94 | 'mailer_debug_enable' => !empty($platform_email['SMTP_DEBUG']) ? 'true' : 'false', |
||
| 95 | 'mailer_exclude_json' => $platform_email['EXCLUDE_JSON'] ?? false, |
||
| 96 | 'mailer_dkim' => json_encode($dkim), |
||
| 97 | 'mailer_xoauth2' => json_encode($xoauth2), |
||
| 98 | ]; |
||
| 114 |