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