SubscribeSubscriberCommandHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5
Metric Value
wmc 2
lcom 0
cbo 5
dl 0
loc 24
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 12 2
1
<?php
2
3
/*
4
 * This file is part of Gitamin.
5
 *
6
 * Copyright (C) 2015-2016 The Gitamin Team
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Gitamin\Handlers\Commands\Subscriber;
13
14
use Gitamin\Commands\Subscriber\SubscribeSubscriberCommand;
15
use Gitamin\Commands\Subscriber\VerifySubscriberCommand;
16
use Gitamin\Events\Subscriber\SubscriberHasSubscribedEvent;
17
use Gitamin\Models\Subscriber;
18
use Illuminate\Foundation\Bus\DispatchesJobs;
19
20
class SubscribeSubscriberCommandHandler
21
{
22
    use DispatchesJobs;
23
24
    /**
25
     * Handle the subscribe subscriber command.
26
     *
27
     * @param \Gitamin\Commands\Subscriber\SubscribeSubscriberCommand $command
28
     *
29
     * @return \Gitamin\Models\Subscriber
30
     */
31
    public function handle(SubscribeSubscriberCommand $command)
32
    {
33
        $subscriber = Subscriber::create(['email' => $command->email]);
34
35
        if ($command->verified) {
36
            $this->dispatch(new VerifySubscriberCommand($subscriber));
37
        } else {
38
            event(new SubscriberHasSubscribedEvent($subscriber));
39
        }
40
41
        return $subscriber;
42
    }
43
}
44