Completed
Push — master ( eeedf4...3b415d )
by Alejandro
02:34
created

src/Service/ConfigMigrationService.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace AcMailer\Service;
3
4
5
/**
6
 * Class ConfigMigrationService
7
 * @author Alejandro Celaya Alastrué
8
 * @link http://www.alejandrocelaya.com
9
 */
10
class ConfigMigrationService implements ConfigMigrationServiceInterface
11
{
12
    /**
13
     * Reads a configuration array with the structure used in version 4.5 and earlier and parses it to the new one
14
     *
15
     * @param array $oldConfig
16
     * @return array
17
     */
18 5
    public function parseConfig(array $oldConfig)
19
    {
20
        $newConfig = [
21 5
            'message_options' => [],
22
            'smtp_options' => [],
23
            'file_options' => []
24
        ];
25
26
        // Mail acapter
27 5
        if (isset($oldConfig['mail_adapter_service'])) {
28 1
            $newConfig['mail_adapter'] = $oldConfig['mail_adapter_service'];
29 4
        } elseif (isset($oldConfig['mail_adapter'])) {
30 1
            $newConfig['mail_adapter'] = $oldConfig['mail_adapter'];
31
        }
32
33
        // Common message options
34 5
        if (isset($oldConfig['from'])) {
35 1
            $newConfig['message_options']['from'] = $oldConfig['from'];
36
        }
37 5
        if (isset($oldConfig['from_name'])) {
38 1
            $newConfig['message_options']['from_name'] = $oldConfig['from_name'];
39
        }
40 5
        if (isset($oldConfig['to'])) {
41 1
            $newConfig['message_options']['to'] = $oldConfig['to'];
42
        }
43 5
        if (isset($oldConfig['cc'])) {
44 1
            $newConfig['message_options']['cc'] = $oldConfig['cc'];
45
        }
46 5
        if (isset($oldConfig['bcc'])) {
47 1
            $newConfig['message_options']['bcc'] = $oldConfig['bcc'];
48
        }
49 5
        if (isset($oldConfig['subject'])) {
50 1
            $newConfig['message_options']['subject'] = $oldConfig['subject'];
51
        }
52
53
        // Body
54 5
        $newConfig['message_options']['body'] = [];
55 5
        if (isset($oldConfig['body'])) {
56 1
            $newConfig['message_options']['body']['content'] = $oldConfig['body'];
57
        }
58 5
        if (isset($oldConfig['body_charset'])) {
59 1
            $newConfig['message_options']['body']['charset'] = $oldConfig['body_charset'];
60
        }
61 5
        if (isset($oldConfig['template'])) {
62 1
            $newConfig['message_options']['body']['template'] = $oldConfig['template'];
63 1
            $newConfig['message_options']['body']['use_template'] = $oldConfig['template']['use_template'];
64 1
            unset($newConfig['message_options']['body']['template']['use_template']);
65 1
            $newConfig['message_options']['body']['template']['default_layout'] = [];
66
        }
67
68
        // Attachments
69 5
        if (isset($oldConfig['attachments'])) {
70 1
            $newConfig['message_options']['attachments'] = $oldConfig['attachments'];
71
        }
72
73
        // SMTP
74 5
        if (isset($oldConfig['server'])) {
75 1
            $newConfig['smtp_options']['host'] = $oldConfig['server'];
76
        }
77 5
        if (isset($oldConfig['port'])) {
78 1
            $newConfig['smtp_options']['port'] = $oldConfig['port'];
79
        }
80 5
        if (isset($oldConfig['connection_class'])) {
81 1
            $newConfig['smtp_options']['connection_class'] = $oldConfig['connection_class'];
82
        }
83 5
        $newConfig['smtp_options']['connection_config'] = [];
84 5 View Code Duplication
        if (isset($oldConfig['smtp_user'])) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
85 1
            $newConfig['smtp_options']['connection_config']['username'] = $oldConfig['smtp_user'];
86
        }
87 5 View Code Duplication
        if (isset($oldConfig['smtp_user'])) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
88 1
            $newConfig['smtp_options']['connection_config']['username'] = $oldConfig['smtp_user'];
89
        }
90 5
        if (isset($oldConfig['smtp_password'])) {
91 1
            $newConfig['smtp_options']['connection_config']['password'] = $oldConfig['smtp_password'];
92
        }
93 5
        if (isset($oldConfig['ssl'])) {
94 1
            $newConfig['smtp_options']['connection_config']['ssl'] = $oldConfig['ssl'];
95
        }
96
97
        // File
98 5
        if (isset($oldConfig['file_path'])) {
99 1
            $newConfig['file_options']['path'] = $oldConfig['file_path'];
100
        }
101 5
        if (isset($oldConfig['file_callback'])) {
102 1
            $newConfig['file_options']['callback'] = $oldConfig['file_callback'];
103
        }
104
105
        return [
106
            'acmailer_options' => [
107 5
                'default' => $newConfig
108
            ]
109
        ];
110
    }
111
}
112