Passed
Push — dev6 ( 5ebf7f...1a3248 )
by Ron
16:55
created

SetEmailSettingsController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 15
c 1
b 0
f 0
dl 0
loc 31
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 24 3
1
<?php
2
3
namespace App\Http\Controllers\Admin\Email;
4
5
use App\Events\Admin\EmailSettingsUpdatedEvent;
6
use App\Http\Controllers\Controller;
7
use App\Http\Requests\Admin\EmailSettingsRequest;
8
use App\Traits\AppSettingsTrait;
9
use Illuminate\Http\Request;
10
11
class SetEmailSettingsController extends Controller
12
{
13
    use AppSettingsTrait;
14
15
    /**
16
     * Save the new email settings
17
     */
18
    public function __invoke(EmailSettingsRequest $request)
19
    {
20
        //  Modify the settings so that they are entered into the database properly
21
        $mailSettings = [
22
            'mail.from.address'              => $request->from_address,
23
            'mail.mailers.smtp.username'     => $request->authentication ? $request->username : null,
24
            'mail.mailers.smtp.host'         => $request->host,
25
            'mail.mailers.smtp.port'         => $request->port,
26
            'mail.mailers.smtp.encryption'   => $request->encryption
27
        ];
28
29
        //  Only update the password if it has been modified
30
        if($request->password !== 'RandomString')
31
        {
32
            $mailSettings['mail.mailers.smtp.password'] = $request->password;
33
        }
34
35
        //  Submit the settings
36
        $this->saveArray($mailSettings);
37
38
        event(new EmailSettingsUpdatedEvent($request));
39
        return back()->with([
40
            'message' => 'Email Settings Updated',
41
            'type'    => 'success',
42
        ]);
43
    }
44
}
45