SendMobileVerificationNotification::handle()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 3
nc 2
nop 1
1
<?php
2
3
namespace Fouladgar\MobileVerification\Listeners;
4
5
use Exception;
6
use Fouladgar\MobileVerification\Contracts\MustVerifyMobile;
7
use Fouladgar\MobileVerification\Tokens\TokenBrokerInterface;
8
use Illuminate\Auth\Events\Registered;
9
10
class SendMobileVerificationNotification
11
{
12
    /**
13
     * @var TokenBrokerInterface
14
     */
15
    protected $tokenBroker;
16
17
    /**
18
     * SendMobileVerificationNotification constructor.
19
     *
20
     * @param TokenBrokerInterface $tokenBroker
21
     */
22
    public function __construct(TokenBrokerInterface $tokenBroker)
23
    {
24
        $this->tokenBroker = $tokenBroker;
25
    }
26
27
    /**
28
     * Handle the event.
29
     *
30
     * @param Registered $event
31
     *
32
     * @throws Exception
33
     *
34
     * @return void
35
     */
36
    public function handle(Registered $event): void
37
    {
38
        $user = $event->user;
39
40
        if ($user instanceof MustVerifyMobile && ! $user->hasVerifiedMobile()) {
41
            $this->tokenBroker->sendToken($user);
42
        }
43
    }
44
}
45