Completed
Push — development ( b579bd...8aa65f )
by Claudio
01:58
created

MailController::prepare()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
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
 * @package App\Http\Controllers
13
 */
14
class MailController extends BaseController
15
{
16
    /**
17
     * Send an Email
18
     *
19
     * @param array $configuration
20
     * @param string $view
21
     */
22 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...
23
    {
24
        if (!Config::get('mail.enable'))
25
            return;
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
     * @return string
39
     */
40
    public function prepare(string $email, string $url): string
41
    {
42
        (new MailModel)->store($token = uniqid('HabboMail', true), $url, $email)->save();
43
44
        return $token;
45
    }
46
47
    /**
48
     * Get E-Mail by Controller
49
     *
50
     * @param string $token
51
     * @return object
52
     */
53
    public function getMail(string $token)
54
    {
55
        $mailRequest = MailModel::where('token', $token)->where('used', '0')->first();
56
57
        if ($mailRequest !== null)
58
            $mailRequest->update(['used' => '1']);
59
60
        return $mailRequest;
61
    }
62
}
63