Completed
Push — master ( 3e9e3c...192c50 )
by Abdelrahman
06:42 queued 04:41
created

Repositories/EmailVerificationTokenRepository.php (1 issue)

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
3
/*
4
 * NOTICE OF LICENSE
5
 *
6
 * Part of the Rinvex Fort Package.
7
 *
8
 * This source file is subject to The MIT License (MIT)
9
 * that is bundled with this package in the LICENSE file.
10
 *
11
 * Package: Rinvex Fort Package
12
 * License: The MIT License (MIT)
13
 * Link:    https://rinvex.com
14
 */
15
16
namespace Rinvex\Fort\Repositories;
17
18
use Rinvex\Fort\Contracts\CanVerifyEmailContract;
19
use Rinvex\Fort\Contracts\EmailVerificationTokenRepositoryContract;
20
21
class EmailVerificationTokenRepository extends AbstractTokenRepository implements EmailVerificationTokenRepositoryContract
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function create(CanVerifyEmailContract $user)
27
    {
28
        $email = $user->getEmailForVerification();
29
        $agent = request()->server('HTTP_USER_AGENT');
30
        $ip = request()->ip();
31
32
        $this->deleteExisting($user);
33
34
        // We will create a new, random token for the user so that we can e-mail them
35
        // a safe link for verification. Then we will insert a record in database
36
        // so that we can verify the token within the actual verification.
37
        $token = $this->createNewToken();
38
39
        $this->getTable()->insert($this->getPayload($email, $token, $agent, $ip));
40
41
        return $token;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function exists(CanVerifyEmailContract $user, $token)
48
    {
49
        $email = $user->getEmailForVerification();
50
51
        $token = (array) $this->getTable()->where('email', $email)->where('token', $token)->first();
52
53
        return $token && ! $this->tokenExpired($token);
0 ignored issues
show
Bug Best Practice introduced by
The expression $token of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    protected function deleteExisting(CanVerifyEmailContract $user)
60
    {
61
        return $this->getTable()->where('email', $user->getEmailForVerification())->delete();
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function getData(CanVerifyEmailContract $user, $token)
68
    {
69
        $email = $user->getEmailForVerification();
70
71
        return (array) $this->getTable()->where('email', $email)->where('token', $token)->first();
72
    }
73
}
74