Passed
Push — develop ( cf1c46...c8c750 )
by Mathew
06:48
created
src/LaravelInvitesServiceProvider.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@
 block discarded – undo
49 49
         $this->mergeConfigFrom(__DIR__.'/../config/laravelinvites.php', 'laravelinvites');
50 50
 
51 51
         // Register the service the package provides.
52
-        $this->app->singleton('laravelinvites', function ($app) {
52
+        $this->app->singleton('laravelinvites', function($app) {
53 53
             return new LaravelInvites;
54 54
         });
55 55
     }
Please login to merge, or discard this patch.
src/Commands/CheckInvitation.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -41,14 +41,14 @@
 block discarded – undo
41 41
      */
42 42
     public function handle()
43 43
     {
44
-        $email = $this->argument('email') ? : null;
44
+        $email = $this->argument('email') ?: null;
45 45
         $code = $this->argument('code');
46 46
 
47 47
         try {
48 48
             LaravelInvites::check($code, $email);
49 49
             $this->info('This code is valid');
50 50
         }
51
-        catch(LaravelInvitesException $e)
51
+        catch (LaravelInvitesException $e)
52 52
         {
53 53
             $this->error($e->getMessage());
54 54
         }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -47,8 +47,7 @@
 block discarded – undo
47 47
         try {
48 48
             LaravelInvites::check($code, $email);
49 49
             $this->info('This code is valid');
50
-        }
51
-        catch(LaravelInvitesException $e)
50
+        } catch(LaravelInvitesException $e)
52 51
         {
53 52
             $this->error($e->getMessage());
54 53
         }
Please login to merge, or discard this patch.
src/Mail/InvitationMail.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@
 block discarded – undo
39 39
             'code' => (string) $this->invite->code
40 40
         ];
41 41
 
42
-        if($this->invite->valid_upto)
42
+        if ($this->invite->valid_upto)
43 43
         {
44 44
             $url = URL::temporarySignedRoute('laravelinvites.routes.follow', $this->invite->valid_upto, $data);
45 45
         }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -42,8 +42,7 @@
 block discarded – undo
42 42
         if($this->invite->valid_upto)
43 43
         {
44 44
             $url = URL::temporarySignedRoute('laravelinvites.routes.follow', $this->invite->valid_upto, $data);
45
-        }
46
-        else
45
+        } else
47 46
         {
48 47
             $url = URL::signedRoute('laravelinvites.routes.follow', $data);
49 48
         }
Please login to merge, or discard this patch.
src/database/migrations/2019_01_22_052953_create_invites_table.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
      */
14 14
     public function up()
15 15
     {
16
-        Schema::create(config('laravelinvites.table'), function (Blueprint $table) {
16
+        Schema::create(config('laravelinvites.table'), function(Blueprint $table) {
17 17
             $table->increments('id');
18 18
             $table->string('email')->nullable()->unique();
19 19
             $table->string('code')->unique();
Please login to merge, or discard this patch.
src/Models/Invite.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -37,13 +37,13 @@  discard block
 block discarded – undo
37 37
     {
38 38
         $this->increment('used_count');
39 39
 
40
-        if($this->used_count >= $this->allowed_count && config('laravelinvites.delete_on_full', true))
40
+        if ($this->used_count >= $this->allowed_count && config('laravelinvites.delete_on_full', true))
41 41
             $this->delete();
42 42
     }
43 43
 
44 44
     public function scopeValid($query)
45 45
     {
46
-        return $query->where('valid_from','<=', now())
46
+        return $query->where('valid_from', '<=', now())
47 47
             ->where('valid_upto', '>=', now())
48 48
             ->whereRaw('allowed_count > used_count');
49 49
     }
@@ -59,13 +59,13 @@  discard block
 block discarded – undo
59 59
      */
60 60
     private function setDefaultExpiry()
61 61
     {
62
-        if(config('laravelinvites.expiry.type')==='none')
62
+        if (config('laravelinvites.expiry.type') === 'none')
63 63
             return null;
64 64
         
65
-        if(config('laravelinvites.expiry.type') === 'hours')
65
+        if (config('laravelinvites.expiry.type') === 'hours')
66 66
             return now()->addHours(config('laravelinvites.expiry.value'));
67 67
             
68
-        elseif(config('laravelinvites.expiry.type') === "days")
68
+        elseif (config('laravelinvites.expiry.type') === "days")
69 69
             return now()->addDays(config('laravelinvites.expiry.days'));
70 70
     }
71 71
 }
72 72
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +11 added lines, -9 removed lines patch added patch discarded remove patch
@@ -37,8 +37,9 @@  discard block
 block discarded – undo
37 37
     {
38 38
         $this->increment('used_count');
39 39
 
40
-        if($this->used_count >= $this->allowed_count && config('laravelinvites.delete_on_full', true))
41
-            $this->delete();
40
+        if($this->used_count >= $this->allowed_count && config('laravelinvites.delete_on_full', true)) {
41
+                    $this->delete();
42
+        }
42 43
     }
43 44
 
44 45
     public function scopeValid($query)
@@ -59,13 +60,14 @@  discard block
 block discarded – undo
59 60
      */
60 61
     private function setDefaultExpiry()
61 62
     {
62
-        if(config('laravelinvites.expiry.type')==='none')
63
-            return null;
63
+        if(config('laravelinvites.expiry.type')==='none') {
64
+                    return null;
65
+        }
64 66
         
65
-        if(config('laravelinvites.expiry.type') === 'hours')
66
-            return now()->addHours(config('laravelinvites.expiry.value'));
67
-            
68
-        elseif(config('laravelinvites.expiry.type') === "days")
69
-            return now()->addDays(config('laravelinvites.expiry.days'));
67
+        if(config('laravelinvites.expiry.type') === 'hours') {
68
+                    return now()->addHours(config('laravelinvites.expiry.value'));
69
+        } elseif(config('laravelinvites.expiry.type') === "days") {
70
+                    return now()->addDays(config('laravelinvites.expiry.days'));
71
+        }
70 72
     }
71 73
 }
72 74
\ No newline at end of file
Please login to merge, or discard this patch.
src/Exceptions/InvitationNotValidWithEmailException.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@
 block discarded – undo
8 8
 {
9 9
     public function __construct($email, $valid_email)
10 10
     {
11
-        if($email)
11
+        if ($email)
12 12
             parent::__construct("This invitation code is not valid with this $email");
13 13
         else
14 14
             parent::__construct("This invitation code is valid only for $valid_email");
Please login to merge, or discard this patch.
Braces   +5 added lines, -4 removed lines patch added patch discarded remove patch
@@ -8,9 +8,10 @@
 block discarded – undo
8 8
 {
9 9
     public function __construct($email, $valid_email)
10 10
     {
11
-        if($email)
12
-            parent::__construct("This invitation code is not valid with this $email");
13
-        else
14
-            parent::__construct("This invitation code is valid only for $valid_email");
11
+        if($email) {
12
+                    parent::__construct("This invitation code is not valid with this $email");
13
+        } else {
14
+                    parent::__construct("This invitation code is valid only for $valid_email");
15
+        }
15 16
     }
16 17
 }
Please login to merge, or discard this patch.
src/Commands/GenerateInvitations.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -43,17 +43,17 @@
 block discarded – undo
43 43
      */
44 44
     public function handle()
45 45
     {
46
-        $email = $this->argument('email') ? : null;
46
+        $email = $this->argument('email') ?: null;
47 47
         $allow = $this->option('allow');
48 48
         $count = $this->option('count');
49 49
         $hours = (int) $this->option('hours');
50 50
         $days = (int) $this->option('days');
51 51
 
52
-        $invite = LaravelInvites::for($email)->allow($allow);
52
+        $invite = LaravelInvites::for ($email)->allow($allow);
53 53
 
54
-        if($days)
54
+        if ($days)
55 55
             $invite->setExpiry(now()->addDays($days));
56
-        else if($hours)
56
+        else if ($hours)
57 57
             $invite->setExpiry(now()->addHours($hours));
58 58
 
59 59
         $invite->generate($count);
Please login to merge, or discard this patch.
Braces   +8 added lines, -5 removed lines patch added patch discarded remove patch
@@ -49,12 +49,15 @@
 block discarded – undo
49 49
         $hours = (int) $this->option('hours');
50 50
         $days = (int) $this->option('days');
51 51
 
52
-        $invite = LaravelInvites::for($email)->allow($allow);
52
+        $invite = LaravelInvites::for($email) {
53
+            ->allow($allow);
54
+        }
53 55
 
54
-        if($days)
55
-            $invite->setExpiry(now()->addDays($days));
56
-        else if($hours)
57
-            $invite->setExpiry(now()->addHours($hours));
56
+        if($days) {
57
+                    $invite->setExpiry(now()->addDays($days));
58
+        } else if($hours) {
59
+                    $invite->setExpiry(now()->addHours($hours));
60
+        }
58 61
 
59 62
         $invite->generate($count);
60 63
 
Please login to merge, or discard this patch.
src/LaravelInvites.php 2 patches
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -47,8 +47,8 @@  discard block
 block discarded – undo
47 47
      */
48 48
     public function get()
49 49
     {
50
-        if(!blank(optional($this->data)['email']))
51
-            $result =  Invite::valid()->whereEmail($this->data['email'])->first();
50
+        if (!blank(optional($this->data)['email']))
51
+            $result = Invite::valid()->whereEmail($this->data['email'])->first();
52 52
         else
53 53
             $result = Invite::valid()->get();
54 54
 
@@ -64,18 +64,18 @@  discard block
 block discarded – undo
64 64
      * 
65 65
      * @return \mathewparet\LaravelInvites\Facades\LaravelInvites
66 66
      */
67
-    public function for($email=null)
67
+    public function for ($email = null)
68 68
     {
69
-        if(!$email)
69
+        if (!$email)
70 70
         {
71 71
             unset($this->data['email']);
72 72
             return $this;
73 73
         }
74 74
 
75
-        $validator = Validator::make(compact('email'),[
75
+        $validator = Validator::make(compact('email'), [
76 76
             'email'=>'required|email'
77 77
         ]);
78
-        if($validator->fails())
78
+        if ($validator->fails())
79 79
             throw new InvalidEmailIdException;
80 80
 
81 81
         $this->data['email'] = $email;
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
     {
93 93
         $invite = Invite::create($this->data);
94 94
 
95
-        if($invite->email && config('laravelinvites.mail.enabled', true))
95
+        if ($invite->email && config('laravelinvites.mail.enabled', true))
96 96
             Mail::to($invite->email)->send(new InvitationMail($invite));
97 97
 
98 98
         return $invite;
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
      */
107 107
     public function validFrom(Carbon $data)
108 108
     {
109
-        $this->data['valid_from'] = $date ? : now();
109
+        $this->data['valid_from'] = $date ?: now();
110 110
 
111 111
         return $this;
112 112
     }
@@ -118,12 +118,12 @@  discard block
 block discarded – undo
118 118
      */
119 119
     private function prepare()
120 120
     {
121
-        if($this->number_of_invites == 1)
121
+        if ($this->number_of_invites == 1)
122 122
             return $this->prepareSingle();
123 123
 
124 124
         $invites = [];
125 125
 
126
-        for($i = 0; $i < $this->number_of_invites; $i++)
126
+        for ($i = 0; $i < $this->number_of_invites; $i++)
127 127
         {
128 128
             $invites[] = $this->prepareSingle();
129 129
         }
@@ -138,16 +138,16 @@  discard block
 block discarded – undo
138 138
      */
139 139
     private function validateEmailBeforeGeneration()
140 140
     {
141
-        if(optional($this->data)['email'] && !blank($this->data['email']))
141
+        if (optional($this->data)['email'] && !blank($this->data['email']))
142 142
         {
143
-            if($number_of_invites > 1)
143
+            if ($number_of_invites > 1)
144 144
                 throw new AnEmailCanHaveOnlyOneInvitation;
145 145
 
146
-            $validator = Validator::make($this->data,[
146
+            $validator = Validator::make($this->data, [
147 147
                 'email'=>'unique:'.config('laravelinvites.table').',email'
148 148
             ]);
149 149
 
150
-            if($validator->fails())
150
+            if ($validator->fails())
151 151
                 throw new AnEmailCanHaveOnlyOneInvitation;
152 152
         }
153 153
     }
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 
166 166
         $this->number_of_invites = $number_of_invites;
167 167
 
168
-        $invitations =  $this->prepare();
168
+        $invitations = $this->prepare();
169 169
         
170 170
         $this->initializeData();
171 171
 
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
      */
246 246
     private function getEmailParameter($parameters)
247 247
     {
248
-        return $parameters[0] ? : 'email' ;
248
+        return $parameters[0] ?: 'email';
249 249
     }
250 250
     
251 251
     /**
@@ -271,27 +271,27 @@  discard block
 block discarded – undo
271 271
             $this->check($code, $email);
272 272
             return true;
273 273
         }
274
-        catch(InvalidInvitationCodeException $e)
274
+        catch (InvalidInvitationCodeException $e)
275 275
         {
276 276
             $validator->errors()->add($emailFieldName, ':attribute is invalid');
277 277
             return false;
278 278
         }
279
-        catch(InvitationNotYetActiveException $e)
279
+        catch (InvitationNotYetActiveException $e)
280 280
         {
281 281
             $validator->errors()->add($emailFieldName, ':attribute is not valid yet');
282 282
             return false;
283 283
         }
284
-        catch(InvitationExpiredException $e)
284
+        catch (InvitationExpiredException $e)
285 285
         {
286 286
             $validator->errors()->add($emailFieldName, ':attribute expired');
287 287
             return false;
288 288
         }
289
-        catch(InvitationNotValidWithEmailException $e)
289
+        catch (InvitationNotValidWithEmailException $e)
290 290
         {
291 291
             $validator->errors()->add($emailFieldName, ':attribute is not valid with the provided '.$emailFieldName);
292 292
             return false;
293 293
         }
294
-        catch(MaximumUseOfCodeException $e)
294
+        catch (MaximumUseOfCodeException $e)
295 295
         {
296 296
             $validator->errors()->add($emailFieldName, ':attribute has been used for the maximum possible times');
297 297
             return false;
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 
316 316
             return true;
317 317
         }
318
-        catch(LaravelInvitesException $e)
318
+        catch (LaravelInvitesException $e)
319 319
         {
320 320
             return false;
321 321
         }
@@ -329,23 +329,23 @@  discard block
 block discarded – undo
329 329
      * 
330 330
      * @return boolean
331 331
      */
332
-    public function check($code, $email=null)
332
+    public function check($code, $email = null)
333 333
     {
334 334
         $invite = Invite::whereCode($code)->first();
335 335
 
336
-        if(!$invite)
336
+        if (!$invite)
337 337
             throw new InvalidInvitationCodeException;
338 338
         
339
-        if($invite->valid_from > now())
339
+        if ($invite->valid_from > now())
340 340
             throw new InvitationNotYetActiveException($invite->valid_from);
341 341
 
342
-        if($invite->valid_upto && $invite->valid_upto <= now())
342
+        if ($invite->valid_upto && $invite->valid_upto <= now())
343 343
             throw new InvitationExpiredException($invite->valid_upto);
344 344
 
345
-        if($invite->used_count > ($invite->allowed_count-1))
345
+        if ($invite->used_count > ($invite->allowed_count - 1))
346 346
             throw new MaximumUseOfCodeException($invite->allowed_count);
347 347
 
348
-        if($invite->email !== $email && !blank($invite->email))
348
+        if ($invite->email !== $email && !blank($invite->email))
349 349
             throw new InvitationNotValidWithEmailException($email, $invite->email);
350 350
 
351 351
         return true;
Please login to merge, or discard this patch.
Braces   +41 added lines, -36 removed lines patch added patch discarded remove patch
@@ -47,10 +47,11 @@  discard block
 block discarded – undo
47 47
      */
48 48
     public function get()
49 49
     {
50
-        if(!blank(optional($this->data)['email']))
51
-            $result =  Invite::valid()->whereEmail($this->data['email'])->first();
52
-        else
53
-            $result = Invite::valid()->get();
50
+        if(!blank(optional($this->data)['email'])) {
51
+                    $result =  Invite::valid()->whereEmail($this->data['email'])->first();
52
+        } else {
53
+                    $result = Invite::valid()->get();
54
+        }
54 55
 
55 56
         $this->initializeData();
56 57
 
@@ -75,8 +76,9 @@  discard block
 block discarded – undo
75 76
         $validator = Validator::make(compact('email'),[
76 77
             'email'=>'required|email'
77 78
         ]);
78
-        if($validator->fails())
79
-            throw new InvalidEmailIdException;
79
+        if($validator->fails()) {
80
+                    throw new InvalidEmailIdException;
81
+        }
80 82
 
81 83
         $this->data['email'] = $email;
82 84
 
@@ -92,8 +94,9 @@  discard block
 block discarded – undo
92 94
     {
93 95
         $invite = Invite::create($this->data);
94 96
 
95
-        if($invite->email && config('laravelinvites.mail.enabled', true))
96
-            Mail::to($invite->email)->send(new InvitationMail($invite));
97
+        if($invite->email && config('laravelinvites.mail.enabled', true)) {
98
+                    Mail::to($invite->email)->send(new InvitationMail($invite));
99
+        }
97 100
 
98 101
         return $invite;
99 102
     }
@@ -118,8 +121,9 @@  discard block
 block discarded – undo
118 121
      */
119 122
     private function prepare()
120 123
     {
121
-        if($this->number_of_invites == 1)
122
-            return $this->prepareSingle();
124
+        if($this->number_of_invites == 1) {
125
+                    return $this->prepareSingle();
126
+        }
123 127
 
124 128
         $invites = [];
125 129
 
@@ -140,15 +144,17 @@  discard block
 block discarded – undo
140 144
     {
141 145
         if(optional($this->data)['email'] && !blank($this->data['email']))
142 146
         {
143
-            if($number_of_invites > 1)
144
-                throw new AnEmailCanHaveOnlyOneInvitation;
147
+            if($number_of_invites > 1) {
148
+                            throw new AnEmailCanHaveOnlyOneInvitation;
149
+            }
145 150
 
146 151
             $validator = Validator::make($this->data,[
147 152
                 'email'=>'unique:'.config('laravelinvites.table').',email'
148 153
             ]);
149 154
 
150
-            if($validator->fails())
151
-                throw new AnEmailCanHaveOnlyOneInvitation;
155
+            if($validator->fails()) {
156
+                            throw new AnEmailCanHaveOnlyOneInvitation;
157
+            }
152 158
         }
153 159
     }
154 160
 
@@ -270,28 +276,23 @@  discard block
 block discarded – undo
270 276
 
271 277
             $this->check($code, $email);
272 278
             return true;
273
-        }
274
-        catch(InvalidInvitationCodeException $e)
279
+        } catch(InvalidInvitationCodeException $e)
275 280
         {
276 281
             $validator->errors()->add($emailFieldName, ':attribute is invalid');
277 282
             return false;
278
-        }
279
-        catch(InvitationNotYetActiveException $e)
283
+        } catch(InvitationNotYetActiveException $e)
280 284
         {
281 285
             $validator->errors()->add($emailFieldName, ':attribute is not valid yet');
282 286
             return false;
283
-        }
284
-        catch(InvitationExpiredException $e)
287
+        } catch(InvitationExpiredException $e)
285 288
         {
286 289
             $validator->errors()->add($emailFieldName, ':attribute expired');
287 290
             return false;
288
-        }
289
-        catch(InvitationNotValidWithEmailException $e)
291
+        } catch(InvitationNotValidWithEmailException $e)
290 292
         {
291 293
             $validator->errors()->add($emailFieldName, ':attribute is not valid with the provided '.$emailFieldName);
292 294
             return false;
293
-        }
294
-        catch(MaximumUseOfCodeException $e)
295
+        } catch(MaximumUseOfCodeException $e)
295 296
         {
296 297
             $validator->errors()->add($emailFieldName, ':attribute has been used for the maximum possible times');
297 298
             return false;
@@ -314,8 +315,7 @@  discard block
 block discarded – undo
314 315
             $this->check($code, $email);
315 316
 
316 317
             return true;
317
-        }
318
-        catch(LaravelInvitesException $e)
318
+        } catch(LaravelInvitesException $e)
319 319
         {
320 320
             return false;
321 321
         }
@@ -333,20 +333,25 @@  discard block
 block discarded – undo
333 333
     {
334 334
         $invite = Invite::whereCode($code)->first();
335 335
 
336
-        if(!$invite)
337
-            throw new InvalidInvitationCodeException;
336
+        if(!$invite) {
337
+                    throw new InvalidInvitationCodeException;
338
+        }
338 339
         
339
-        if($invite->valid_from > now())
340
-            throw new InvitationNotYetActiveException($invite->valid_from);
340
+        if($invite->valid_from > now()) {
341
+                    throw new InvitationNotYetActiveException($invite->valid_from);
342
+        }
341 343
 
342
-        if($invite->valid_upto && $invite->valid_upto <= now())
343
-            throw new InvitationExpiredException($invite->valid_upto);
344
+        if($invite->valid_upto && $invite->valid_upto <= now()) {
345
+                    throw new InvitationExpiredException($invite->valid_upto);
346
+        }
344 347
 
345
-        if($invite->used_count > ($invite->allowed_count-1))
346
-            throw new MaximumUseOfCodeException($invite->allowed_count);
348
+        if($invite->used_count > ($invite->allowed_count-1)) {
349
+                    throw new MaximumUseOfCodeException($invite->allowed_count);
350
+        }
347 351
 
348
-        if($invite->email !== $email && !blank($invite->email))
349
-            throw new InvitationNotValidWithEmailException($email, $invite->email);
352
+        if($invite->email !== $email && !blank($invite->email)) {
353
+                    throw new InvitationNotValidWithEmailException($email, $invite->email);
354
+        }
350 355
 
351 356
         return true;
352 357
     }
Please login to merge, or discard this patch.