VerifiesEmails   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
eloc 12
c 2
b 0
f 0
dl 0
loc 44
ccs 0
cts 20
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A verify() 0 15 4
A resend() 0 9 2
1
<?php
2
3
namespace MedianetDev\LaravelAuthApi\Http\Controllers\Traits;
4
5
use Illuminate\Auth\Events\Verified;
6
use Illuminate\Http\Request;
7
use Illuminate\Support\Facades\Auth;
8
use MedianetDev\LaravelAuthApi\Http\Helpers\ApiResponse;
9
10
trait VerifiesEmails
11
{
12
    /**
13
     * Mark the authenticated user's email address as verified.
14
     *
15
     * @param \Illuminate\Http\Request $request
16
     *
17
     * @return \Illuminate\Http\Response
18
     *
19
     * @throws \Illuminate\Auth\Access\AuthorizationException
20
     */
21
    public function verify(Request $request)
22
    {
23
        if (! hash_equals((string) $request->route('code'), (string) hexdec(substr(sha1($request->user()->getKey().$request->user()->getEmailForVerification()), 0, 3)))) {
24
            return ApiResponse::send(['error' => 'Bad codes.'], 0, 403, 'Bad codes.');
25
        }
26
27
        if ($request->user()->hasVerifiedEmail()) {
28
            return ApiResponse::send(['success' => 'email already verified.....'], 1, 200, 'email already verified.....');
29
        }
30
31
        if ($request->user()->markEmailAsVerified()) {
32
            event(new Verified($request->user()));
33
        }
34
35
        return ApiResponse::send(['success' => 'email verified successfully'], 1, 200, 'email verified successfully');
36
    }
37
38
    /**
39
     * Resend the email verification notification.
40
     *
41
     * @param \Illuminate\Http\Request $request
42
     *
43
     * @return \Illuminate\Http\Response
44
     */
45
    public function resend(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

45
    public function resend(/** @scrutinizer ignore-unused */ Request $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
46
    {
47
        if (Auth::guard('apiauth')->user()->hasVerifiedEmail()) {
48
            return ApiResponse::send(['success' => 'email already verified'], 1, 200, 'email already verified');
49
        }
50
51
        Auth::guard('apiauth')->user()->sendEmailVerificationNotification();
52
53
        return ApiResponse::send(['success' => 'email resended successfully'], 1, 200, 'email resended successfully');
54
    }
55
}
56