@@ -47,8 +47,8 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 106 | 106 | */ |
| 107 | 107 | public function validFrom(Carbon $date) |
| 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 |
||
| 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 | } |
@@ -140,16 +140,16 @@ discard block |
||
| 140 | 140 | */ |
| 141 | 141 | private function validateEmailBeforeGeneration($number_of_invites = 1) |
| 142 | 142 | { |
| 143 | - if(optional($this->data)['email'] && !blank($this->data['email'])) |
|
| 143 | + if (optional($this->data)['email'] && !blank($this->data['email'])) |
|
| 144 | 144 | { |
| 145 | - if($number_of_invites > 1) |
|
| 145 | + if ($number_of_invites > 1) |
|
| 146 | 146 | throw new AnEmailCanHaveOnlyOneInvitation; |
| 147 | 147 | |
| 148 | - $validator = Validator::make($this->data,[ |
|
| 148 | + $validator = Validator::make($this->data, [ |
|
| 149 | 149 | 'email'=>'unique:'.config('laravelinvites.table').',email' |
| 150 | 150 | ]); |
| 151 | 151 | |
| 152 | - if($validator->fails()) |
|
| 152 | + if ($validator->fails()) |
|
| 153 | 153 | throw new AnEmailCanHaveOnlyOneInvitation; |
| 154 | 154 | } |
| 155 | 155 | } |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | |
| 168 | 168 | $this->number_of_invites = $number_of_invites; |
| 169 | 169 | |
| 170 | - $invitations = $this->prepare(); |
|
| 170 | + $invitations = $this->prepare(); |
|
| 171 | 171 | |
| 172 | 172 | $this->initializeData(); |
| 173 | 173 | |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | */ |
| 248 | 248 | private function getEmailParameter($parameters) |
| 249 | 249 | { |
| 250 | - return $parameters[0] ? : 'email' ; |
|
| 250 | + return $parameters[0] ?: 'email'; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -273,27 +273,27 @@ discard block |
||
| 273 | 273 | $this->check($value, $email); |
| 274 | 274 | return true; |
| 275 | 275 | } |
| 276 | - catch(InvalidInvitationCodeException $e) |
|
| 276 | + catch (InvalidInvitationCodeException $e) |
|
| 277 | 277 | { |
| 278 | 278 | $validator->errors()->add($emailFieldName, ':attribute is invalid'); |
| 279 | 279 | return false; |
| 280 | 280 | } |
| 281 | - catch(InvitationNotYetActiveException $e) |
|
| 281 | + catch (InvitationNotYetActiveException $e) |
|
| 282 | 282 | { |
| 283 | 283 | $validator->errors()->add($emailFieldName, ':attribute is not valid yet'); |
| 284 | 284 | return false; |
| 285 | 285 | } |
| 286 | - catch(InvitationExpiredException $e) |
|
| 286 | + catch (InvitationExpiredException $e) |
|
| 287 | 287 | { |
| 288 | 288 | $validator->errors()->add($emailFieldName, ':attribute expired'); |
| 289 | 289 | return false; |
| 290 | 290 | } |
| 291 | - catch(InvitationNotValidWithEmailException $e) |
|
| 291 | + catch (InvitationNotValidWithEmailException $e) |
|
| 292 | 292 | { |
| 293 | 293 | $validator->errors()->add($emailFieldName, ':attribute is not valid with the provided '.$emailFieldName); |
| 294 | 294 | return false; |
| 295 | 295 | } |
| 296 | - catch(MaximumUseOfCodeException $e) |
|
| 296 | + catch (MaximumUseOfCodeException $e) |
|
| 297 | 297 | { |
| 298 | 298 | $validator->errors()->add($emailFieldName, ':attribute has been used for the maximum possible times'); |
| 299 | 299 | return false; |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | |
| 318 | 318 | return true; |
| 319 | 319 | } |
| 320 | - catch(LaravelInvitesException $e) |
|
| 320 | + catch (LaravelInvitesException $e) |
|
| 321 | 321 | { |
| 322 | 322 | return false; |
| 323 | 323 | } |
@@ -331,23 +331,23 @@ discard block |
||
| 331 | 331 | * |
| 332 | 332 | * @return boolean |
| 333 | 333 | */ |
| 334 | - public function check($code, $email=null) |
|
| 334 | + public function check($code, $email = null) |
|
| 335 | 335 | { |
| 336 | 336 | $invite = Invite::whereCode($code)->first(); |
| 337 | 337 | |
| 338 | - if(!$invite) |
|
| 338 | + if (!$invite) |
|
| 339 | 339 | throw new InvalidInvitationCodeException; |
| 340 | 340 | |
| 341 | - if($invite->valid_from > now()) |
|
| 341 | + if ($invite->valid_from > now()) |
|
| 342 | 342 | throw new InvitationNotYetActiveException($invite->valid_from); |
| 343 | 343 | |
| 344 | - if($invite->valid_upto && $invite->valid_upto <= now()) |
|
| 344 | + if ($invite->valid_upto && $invite->valid_upto <= now()) |
|
| 345 | 345 | throw new InvitationExpiredException($invite->valid_upto); |
| 346 | 346 | |
| 347 | - if($invite->used_count > ($invite->allowed_count-1)) |
|
| 347 | + if ($invite->used_count > ($invite->allowed_count - 1)) |
|
| 348 | 348 | throw new MaximumUseOfCodeException($invite->allowed_count); |
| 349 | 349 | |
| 350 | - if($invite->email !== $email && !blank($invite->email)) |
|
| 350 | + if ($invite->email !== $email && !blank($invite->email)) |
|
| 351 | 351 | throw new InvitationNotValidWithEmailException($email, $invite->email); |
| 352 | 352 | |
| 353 | 353 | return true; |
@@ -47,10 +47,11 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | |
@@ -142,15 +146,17 @@ discard block |
||
| 142 | 146 | { |
| 143 | 147 | if(optional($this->data)['email'] && !blank($this->data['email'])) |
| 144 | 148 | { |
| 145 | - if($number_of_invites > 1) |
|
| 146 | - throw new AnEmailCanHaveOnlyOneInvitation; |
|
| 149 | + if($number_of_invites > 1) { |
|
| 150 | + throw new AnEmailCanHaveOnlyOneInvitation; |
|
| 151 | + } |
|
| 147 | 152 | |
| 148 | 153 | $validator = Validator::make($this->data,[ |
| 149 | 154 | 'email'=>'unique:'.config('laravelinvites.table').',email' |
| 150 | 155 | ]); |
| 151 | 156 | |
| 152 | - if($validator->fails()) |
|
| 153 | - throw new AnEmailCanHaveOnlyOneInvitation; |
|
| 157 | + if($validator->fails()) { |
|
| 158 | + throw new AnEmailCanHaveOnlyOneInvitation; |
|
| 159 | + } |
|
| 154 | 160 | } |
| 155 | 161 | } |
| 156 | 162 | |
@@ -272,28 +278,23 @@ discard block |
||
| 272 | 278 | |
| 273 | 279 | $this->check($value, $email); |
| 274 | 280 | return true; |
| 275 | - } |
|
| 276 | - catch(InvalidInvitationCodeException $e) |
|
| 281 | + } catch(InvalidInvitationCodeException $e) |
|
| 277 | 282 | { |
| 278 | 283 | $validator->errors()->add($emailFieldName, ':attribute is invalid'); |
| 279 | 284 | return false; |
| 280 | - } |
|
| 281 | - catch(InvitationNotYetActiveException $e) |
|
| 285 | + } catch(InvitationNotYetActiveException $e) |
|
| 282 | 286 | { |
| 283 | 287 | $validator->errors()->add($emailFieldName, ':attribute is not valid yet'); |
| 284 | 288 | return false; |
| 285 | - } |
|
| 286 | - catch(InvitationExpiredException $e) |
|
| 289 | + } catch(InvitationExpiredException $e) |
|
| 287 | 290 | { |
| 288 | 291 | $validator->errors()->add($emailFieldName, ':attribute expired'); |
| 289 | 292 | return false; |
| 290 | - } |
|
| 291 | - catch(InvitationNotValidWithEmailException $e) |
|
| 293 | + } catch(InvitationNotValidWithEmailException $e) |
|
| 292 | 294 | { |
| 293 | 295 | $validator->errors()->add($emailFieldName, ':attribute is not valid with the provided '.$emailFieldName); |
| 294 | 296 | return false; |
| 295 | - } |
|
| 296 | - catch(MaximumUseOfCodeException $e) |
|
| 297 | + } catch(MaximumUseOfCodeException $e) |
|
| 297 | 298 | { |
| 298 | 299 | $validator->errors()->add($emailFieldName, ':attribute has been used for the maximum possible times'); |
| 299 | 300 | return false; |
@@ -316,8 +317,7 @@ discard block |
||
| 316 | 317 | $this->check($code, $email); |
| 317 | 318 | |
| 318 | 319 | return true; |
| 319 | - } |
|
| 320 | - catch(LaravelInvitesException $e) |
|
| 320 | + } catch(LaravelInvitesException $e) |
|
| 321 | 321 | { |
| 322 | 322 | return false; |
| 323 | 323 | } |
@@ -335,20 +335,25 @@ discard block |
||
| 335 | 335 | { |
| 336 | 336 | $invite = Invite::whereCode($code)->first(); |
| 337 | 337 | |
| 338 | - if(!$invite) |
|
| 339 | - throw new InvalidInvitationCodeException; |
|
| 338 | + if(!$invite) { |
|
| 339 | + throw new InvalidInvitationCodeException; |
|
| 340 | + } |
|
| 340 | 341 | |
| 341 | - if($invite->valid_from > now()) |
|
| 342 | - throw new InvitationNotYetActiveException($invite->valid_from); |
|
| 342 | + if($invite->valid_from > now()) { |
|
| 343 | + throw new InvitationNotYetActiveException($invite->valid_from); |
|
| 344 | + } |
|
| 343 | 345 | |
| 344 | - if($invite->valid_upto && $invite->valid_upto <= now()) |
|
| 345 | - throw new InvitationExpiredException($invite->valid_upto); |
|
| 346 | + if($invite->valid_upto && $invite->valid_upto <= now()) { |
|
| 347 | + throw new InvitationExpiredException($invite->valid_upto); |
|
| 348 | + } |
|
| 346 | 349 | |
| 347 | - if($invite->used_count > ($invite->allowed_count-1)) |
|
| 348 | - throw new MaximumUseOfCodeException($invite->allowed_count); |
|
| 350 | + if($invite->used_count > ($invite->allowed_count-1)) { |
|
| 351 | + throw new MaximumUseOfCodeException($invite->allowed_count); |
|
| 352 | + } |
|
| 349 | 353 | |
| 350 | - if($invite->email !== $email && !blank($invite->email)) |
|
| 351 | - throw new InvitationNotValidWithEmailException($email, $invite->email); |
|
| 354 | + if($invite->email !== $email && !blank($invite->email)) { |
|
| 355 | + throw new InvitationNotValidWithEmailException($email, $invite->email); |
|
| 356 | + } |
|
| 352 | 357 | |
| 353 | 358 | return true; |
| 354 | 359 | } |
@@ -49,7 +49,7 @@ |
||
| 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 (/** @scrutinizer ignore-unused */ $app) { |
|
| 52 | + $this->app->singleton('laravelinvites', function(/** @scrutinizer ignore-unused */ $app) { |
|
| 53 | 53 | return new LaravelInvites; |
| 54 | 54 | }); |
| 55 | 55 | } |