GenerateInvitations::handle()   A
last analyzed

Complexity

Conditions 5
Paths 12

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 24
rs 9.4555
c 0
b 0
f 0
cc 5
nc 12
nop 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)->allow($allow);
0 ignored issues
show
Bug introduced by
The method for() does not exist on mathewparet\LaravelInvites\Facades\LaravelInvites. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

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

55
            $invite = LaravelInvites::/** @scrutinizer ignore-call */ for($email)->allow($allow);
Loading history...
56
57
            if ($days) {
58
                            $invite->setExpiry(now()->addDays($days));
59
            } else if ($hours) {
60
                            $invite->setExpiry(now()->addHours($hours));
61
            }
62
    
63
            $invite->generate($count);
64
    
65
            $this->info($count." invitations generated.");                
66
        } catch (\Exception $e)
67
        {
68
            $this->error($e->getMessage());
69
        }
70
    }
71
}
72