MailController::getMail()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Mail as MailModel;
6
use Illuminate\Support\Facades\Config;
7
use Illuminate\Support\Facades\Mail;
8
use Laravel\Lumen\Routing\Controller as BaseController;
9
10
/**
11
 * Class MailController.
12
 */
13
class MailController extends BaseController
14
{
15
    /**
16
     * Send an Email.
17
     *
18
     * @param array  $configuration
19
     * @param string $view
20
     */
21 View Code Duplication
    public function send(array $configuration, string $view = 'habbo-web-mail.confirm-mail')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
22
    {
23
        if (!Config::get('mail.enable')) {
24
            return;
25
        }
26
27
        Mail::send($view, $configuration, function ($message) use ($configuration) {
28
            $message->from(Config::get('mail.from.address'), Config::get('mail.from.name'));
29
            $message->to($configuration['email'])->subject($configuration['subject']);
30
        });
31
    }
32
33
    /**
34
     * Prepare the E-Mail.
35
     *
36
     * @param string $email
37
     * @param string $url
38
     *
39
     * @return string
40
     */
41
    public function prepare(string $email, string $url): string
42
    {
43
        (new MailModel())->store($token = uniqid('HabboMail', true), $url, $email)->save();
44
45
        return $token;
46
    }
47
48
    /**
49
     * Get E-Mail by Controller.
50
     *
51
     * @param string $token
52
     *
53
     * @return object
54
     */
55
    public function getMail(string $token)
56
    {
57
        $mailRequest = MailModel::where('token', $token)->where('used', '0')->first();
58
59
        if ($mailRequest !== null) {
60
            $mailRequest->update(['used' => '1']);
61
        }
62
63
        return $mailRequest;
64
    }
65
}
66