Passed
Push — develop ( 0903dd...82bd52 )
by Mathew
05:03 queued 02:07
created

GenerateInvitations   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 19
dl 0
loc 58
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace mathewparet\LaravelInvites\Commands;
4
5
use mathewparet\LaravelInvites\Facades\LaravelInvites;
6
use mathewparet\LaravelInvites\Exceptions\LaravelInvitesException;
7
8
use Illuminate\Console\Command;
9
10
class GenerateInvitations extends Command
11
{
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'invites:generate {email?} 
18
        {--a|allow=1 : Number of times the code can be used} 
19
        {--c|count=1 : The number of codes to be generated}
20
        {--d|days= : The number of days until expiry (preceeds hours option)}
21
        {--r|hours= : Number of hours until expiry}';
22
23
    /**
24
     * The console command description.
25
     *
26
     * @var string
27
     */
28
    protected $description = 'Generates invitation codes';
29
30
    /**
31
     * Create a new command instance.
32
     *
33
     * @return void
34
     */
35
    public function __construct()
36
    {
37
        parent::__construct();
38
    }
39
40
    /**
41
     * Execute the console command.
42
     *
43
     * @return mixed
44
     */
45
    public function handle()
46
    {
47
        $email = $this->argument('email') ?: null;
48
        $allow = $this->option('allow');
49
        $count = $this->option('count');
50
        $hours = (int) $this->option('hours');
51
        $days = (int) $this->option('days');
52
53
        try
54
        {
55
            $invite = LaravelInvites::for ($email) {
56
                ->allow($allow);
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_OBJECT_OPERATOR on line 56 at column 16
Loading history...
57
            }
58
59
            if ($days) {
60
                            $invite->setExpiry(now()->addDays($days));
61
            } else if ($hours) {
62
                            $invite->setExpiry(now()->addHours($hours));
63
            }
64
    
65
            $invite->generate($count);
66
    
67
            $this->info($count." invitations generated.");                
68
        } catch (\Exception $e)
69
        {
70
            $this->error($e->getMessage());
71
        }
72
    }
73
}
74