Passed
Branch master (80e19c)
by Mathew
02:51
created

GenerateInvitations   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 16
dl 0
loc 53
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 18 4
A __construct() 0 3 1
1
<?php
2
3
namespace mathewparet\LaravelInvites\Commands;
4
5
use mathewparet\LaravelInvites\Facades\LaravelInvites;
6
7
use Illuminate\Console\Command;
8
9
class GenerateInvitations extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'invites:generate {email?} 
17
        {--a|allow=1 : Number of times the code can be used} 
18
        {--c|count=1 : The number of codes to be generated}
19
        {--d|days= : The number of days until expiry (preceeds hours option)}
20
        {--r|hours= : Number of hours until expiry}';
21
22
    /**
23
     * The console command description.
24
     *
25
     * @var string
26
     */
27
    protected $description = 'Generates invitation codes';
28
29
    /**
30
     * Create a new command instance.
31
     *
32
     * @return void
33
     */
34
    public function __construct()
35
    {
36
        parent::__construct();
37
    }
38
39
    /**
40
     * Execute the console command.
41
     *
42
     * @return mixed
43
     */
44
    public function handle()
45
    {
46
        $email = $this->argument('email') ? : null;
47
        $allow = $this->option('allow');
48
        $count = $this->option('count');
49
        $hours = $this->option('hours');
50
        $days = $this->option('days');
51
52
        $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

52
        $invite = LaravelInvites::/** @scrutinizer ignore-call */ for($email)->allow($allow);
Loading history...
53
54
        if($days)
55
            $invite->setExpiry(now()->addDays($days));
0 ignored issues
show
Bug introduced by
$days of type string is incompatible with the type integer expected by parameter $value of Carbon\Carbon::addDays(). ( Ignorable by Annotation )

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

55
            $invite->setExpiry(now()->addDays(/** @scrutinizer ignore-type */ $days));
Loading history...
56
        else if($hours)
57
            $invite->setExpiry(now()->addHours($hours));
0 ignored issues
show
Bug introduced by
$hours of type string is incompatible with the type integer expected by parameter $value of Carbon\Carbon::addHours(). ( Ignorable by Annotation )

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

57
            $invite->setExpiry(now()->addHours(/** @scrutinizer ignore-type */ $hours));
Loading history...
58
59
        $invites = $invite->generate($count);
0 ignored issues
show
Unused Code introduced by
The assignment to $invites is dead and can be removed.
Loading history...
60
61
        $this->info($count." invitations generated.");
62
    }
63
}
64