Passed
Branch master (80e19c)
by Mathew
02:51
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 1 patch
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.
src/Commands/GenerateInvitations.php 1 patch
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 = $this->option('hours');
50 50
         $days = $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
         $invites = $invite->generate($count);
Please login to merge, or discard this patch.
src/Mail/InvitationMail.php 1 patch
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.
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 1 patch
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.
src/Exceptions/InvitationNotValidWithEmailException.php 1 patch
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.
src/LaravelInvites.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -44,8 +44,8 @@  discard block
 block discarded – undo
44 44
 
45 45
     public function get()
46 46
     {
47
-        if(!blank(optional($this->data)['email']))
48
-            $result =  Invite::valid()->whereEmail($this->data['email'])->first();
47
+        if (!blank(optional($this->data)['email']))
48
+            $result = Invite::valid()->whereEmail($this->data['email'])->first();
49 49
         else
50 50
             $result = Invite::valid()->get();
51 51
 
@@ -54,18 +54,18 @@  discard block
 block discarded – undo
54 54
         return $result;
55 55
     }
56 56
 
57
-    public function for($email=null)
57
+    public function for ($email = null)
58 58
     {
59
-        if(!$email)
59
+        if (!$email)
60 60
         {
61 61
             unset($this->data['email']);
62 62
             return $this;
63 63
         }
64 64
 
65
-        $validator = Validator::make(compact('email'),[
65
+        $validator = Validator::make(compact('email'), [
66 66
             'email'=>'required|email'
67 67
         ]);
68
-        if($validator->fails())
68
+        if ($validator->fails())
69 69
             throw new InvalidEmailIdException;
70 70
 
71 71
         $this->data['email'] = $email;
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
     {
78 78
         $invite = Invite::create($this->data);
79 79
 
80
-        if($invite->email && config('laravelinvites.mail.enabled', true))
80
+        if ($invite->email && config('laravelinvites.mail.enabled', true))
81 81
             Mail::to($invite->email)->send(new InvitationMail($invite));
82 82
 
83 83
         return $invite;
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 
86 86
     public function validFrom($date = null)
87 87
     {
88
-        $this->data['valid_from'] = $date ? : now();
88
+        $this->data['valid_from'] = $date ?: now();
89 89
 
90 90
         return $this;
91 91
     }
@@ -97,12 +97,12 @@  discard block
 block discarded – undo
97 97
      */
98 98
     private function prepare()
99 99
     {
100
-        if($this->number_of_invites == 1)
100
+        if ($this->number_of_invites == 1)
101 101
             return $this->prepareSingle();
102 102
 
103 103
         $invites = [];
104 104
 
105
-        for($i = 0; $i < $this->number_of_invites; $i++)
105
+        for ($i = 0; $i < $this->number_of_invites; $i++)
106 106
         {
107 107
             $invites[] = $this->prepareSingle();
108 108
         }
@@ -119,22 +119,22 @@  discard block
 block discarded – undo
119 119
      */
120 120
     public function generate($number_of_invites = 1)
121 121
     {
122
-        if(optional($this->data)['email'] && !blank($this->data['email']))
122
+        if (optional($this->data)['email'] && !blank($this->data['email']))
123 123
         {
124
-            if($number_of_invites > 1)
124
+            if ($number_of_invites > 1)
125 125
                 throw new AnEmailCanHaveOnlyOneInvitation;
126 126
 
127
-            $validator = Validator::make($this->data,[
127
+            $validator = Validator::make($this->data, [
128 128
                 'email'=>'unique:'.config('laravelinvites.table').',email'
129 129
             ]);
130 130
 
131
-            if($validator->fails())
131
+            if ($validator->fails())
132 132
                 throw new AnEmailCanHaveOnlyOneInvitation;
133 133
         }
134 134
 
135 135
         $this->number_of_invites = $number_of_invites;
136 136
 
137
-        $invitations =  $this->prepare();
137
+        $invitations = $this->prepare();
138 138
         
139 139
         $this->initializeData();
140 140
 
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 
208 208
     private function getEmailParameter($parameters)
209 209
     {
210
-        return $parameters[0] ? : 'email' ;
210
+        return $parameters[0] ?: 'email';
211 211
     }
212 212
     
213 213
     public function validate($attribute, $value, $parameters, $validator)
@@ -220,27 +220,27 @@  discard block
 block discarded – undo
220 220
             $this->check($code, $email);
221 221
             return true;
222 222
         }
223
-        catch(InvalidInvitationCodeException $e)
223
+        catch (InvalidInvitationCodeException $e)
224 224
         {
225 225
             $validator->errors()->add($emailFieldName, ':attribute is invalid');
226 226
             return false;
227 227
         }
228
-        catch(InvitationNotYetActiveException $e)
228
+        catch (InvitationNotYetActiveException $e)
229 229
         {
230 230
             $validator->errors()->add($emailFieldName, ':attribute is not valid yet');
231 231
             return false;
232 232
         }
233
-        catch(InvitationExpiredException $e)
233
+        catch (InvitationExpiredException $e)
234 234
         {
235 235
             $validator->errors()->add($emailFieldName, ':attribute expired');
236 236
             return false;
237 237
         }
238
-        catch(InvitationNotValidWithEmailException $e)
238
+        catch (InvitationNotValidWithEmailException $e)
239 239
         {
240 240
             $validator->errors()->add($emailFieldName, ':attribute is not valid with the provided '.$emailFieldName);
241 241
             return false;
242 242
         }
243
-        catch(MaximumUseOfCodeException $e)
243
+        catch (MaximumUseOfCodeException $e)
244 244
         {
245 245
             $validator->errors()->add($emailFieldName, ':attribute has been used for the maximum possible times');
246 246
             return false;
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 
263 263
             return true;
264 264
         }
265
-        catch(LaravelInvitesException $e)
265
+        catch (LaravelInvitesException $e)
266 266
         {
267 267
             return false;
268 268
         }
@@ -274,23 +274,23 @@  discard block
 block discarded – undo
274 274
      * @param string $code
275 275
      * @param string $email
276 276
      */
277
-    public function check($code, $email=null)
277
+    public function check($code, $email = null)
278 278
     {
279 279
         $invite = Invite::whereCode($code)->first();
280 280
 
281
-        if(!$invite)
281
+        if (!$invite)
282 282
             throw new InvalidInvitationCodeException;
283 283
         
284
-        if($invite->valid_from > now())
284
+        if ($invite->valid_from > now())
285 285
             throw new InvitationNotYetActiveException($invite->valid_from);
286 286
 
287
-        if($invite->valid_upto && $invite->valid_upto <= now())
287
+        if ($invite->valid_upto && $invite->valid_upto <= now())
288 288
             throw new InvitationExpiredException($invite->valid_upto);
289 289
 
290
-        if($invite->used_count > ($invite->allowed_count-1))
290
+        if ($invite->used_count > ($invite->allowed_count - 1))
291 291
             throw new MaximumUseOfCodeException($invite->allowed_count);
292 292
 
293
-        if($invite->email !== $email && !blank($invite->email))
293
+        if ($invite->email !== $email && !blank($invite->email))
294 294
             throw new InvitationNotValidWithEmailException($email, $invite->email);
295 295
 
296 296
         return true;
Please login to merge, or discard this patch.