@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | use Intervention\Image\ImageManager; |
4 | 4 | |
5 | -if (!function_exists('captcha')) { |
|
5 | +if ( ! function_exists('captcha')) { |
|
6 | 6 | /** |
7 | 7 | * @param string $config |
8 | 8 | * @return array|ImageManager|mixed |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | } |
15 | 15 | } |
16 | 16 | |
17 | -if (!function_exists('captcha_src')) { |
|
17 | +if ( ! function_exists('captcha_src')) { |
|
18 | 18 | /** |
19 | 19 | * @param string $config |
20 | 20 | * @return string |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | } |
26 | 26 | } |
27 | 27 | |
28 | -if (!function_exists('captcha_img')) { |
|
28 | +if ( ! function_exists('captcha_img')) { |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * @param string $config |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | } |
38 | 38 | } |
39 | 39 | |
40 | -if (!function_exists('captcha_check')) { |
|
40 | +if ( ! function_exists('captcha_check')) { |
|
41 | 41 | /** |
42 | 42 | * @param string $value |
43 | 43 | * @return bool |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
51 | -if (!function_exists('captcha_api_check')) { |
|
51 | +if ( ! function_exists('captcha_api_check')) { |
|
52 | 52 | /** |
53 | 53 | * @param string $value |
54 | 54 | * @param string $key |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | { |
22 | 22 | // Publish configuration files |
23 | 23 | $this->publishes([ |
24 | - __DIR__ . '/../config/captcha.php' => config_path('captcha.php') |
|
24 | + __DIR__.'/../config/captcha.php' => config_path('captcha.php') |
|
25 | 25 | ], 'config'); |
26 | 26 | |
27 | 27 | // HTTP routing |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | } else { |
34 | 34 | /* @var Router $router */ |
35 | 35 | $router = $this->app['router']; |
36 | - if ((double)$this->app->version() >= 5.2) { |
|
36 | + if ((double) $this->app->version() >= 5.2) { |
|
37 | 37 | $router->get('captcha/api/{config?}', '\Mews\Captcha\CaptchaController@getCaptchaApi')->middleware('web'); |
38 | 38 | $router->get('captcha/{config?}', '\Mews\Captcha\CaptchaController@getCaptcha')->middleware('web'); |
39 | 39 | } else { |
@@ -46,12 +46,12 @@ discard block |
||
46 | 46 | $validator = $this->app['validator']; |
47 | 47 | |
48 | 48 | // Validator extensions |
49 | - $validator->extend('captcha', function ($attribute, $value, $parameters) { |
|
49 | + $validator->extend('captcha', function($attribute, $value, $parameters) { |
|
50 | 50 | return captcha_check($value); |
51 | 51 | }); |
52 | 52 | |
53 | 53 | // Validator extensions |
54 | - $validator->extend('captcha_api', function ($attribute, $value, $parameters) { |
|
54 | + $validator->extend('captcha_api', function($attribute, $value, $parameters) { |
|
55 | 55 | return captcha_api_check($value, $parameters[0]); |
56 | 56 | }); |
57 | 57 | } |
@@ -65,12 +65,12 @@ discard block |
||
65 | 65 | { |
66 | 66 | // Merge configs |
67 | 67 | $this->mergeConfigFrom( |
68 | - __DIR__ . '/../config/captcha.php', |
|
68 | + __DIR__.'/../config/captcha.php', |
|
69 | 69 | 'captcha' |
70 | 70 | ); |
71 | 71 | |
72 | 72 | // Bind captcha |
73 | - $this->app->bind('captcha', function ($app) { |
|
73 | + $this->app->bind('captcha', function($app) { |
|
74 | 74 | return new Captcha( |
75 | 75 | $app['Illuminate\Filesystem\Filesystem'], |
76 | 76 | $app['Illuminate\Contracts\Config\Repository'], |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | $this->hasher = $hasher; |
217 | 217 | $this->str = $str; |
218 | 218 | $this->characters = config('captcha.characters', ['1', '2', '3', '4', '6', '7', '8', '9']); |
219 | - $this->fontsDirectory = config('captcha.fontsDirectory', __DIR__ . '/../assets/fonts'); |
|
219 | + $this->fontsDirectory = config('captcha.fontsDirectory', __DIR__.'/../assets/fonts'); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -225,8 +225,8 @@ discard block |
||
225 | 225 | */ |
226 | 226 | protected function configure($config) |
227 | 227 | { |
228 | - if ($this->config->has('captcha.' . $config)) { |
|
229 | - foreach ($this->config->get('captcha.' . $config) as $key => $val) { |
|
228 | + if ($this->config->has('captcha.'.$config)) { |
|
229 | + foreach ($this->config->get('captcha.'.$config) as $key => $val) { |
|
230 | 230 | $this->{$key} = $val; |
231 | 231 | } |
232 | 232 | } |
@@ -242,11 +242,11 @@ discard block |
||
242 | 242 | */ |
243 | 243 | public function create(string $config = 'default', bool $api = false) |
244 | 244 | { |
245 | - $this->backgrounds = $this->files->files(__DIR__ . '/../assets/backgrounds'); |
|
245 | + $this->backgrounds = $this->files->files(__DIR__.'/../assets/backgrounds'); |
|
246 | 246 | $this->fonts = $this->files->files($this->fontsDirectory); |
247 | 247 | |
248 | 248 | if (version_compare(app()->version(), '5.5.0', '>=')) { |
249 | - $this->fonts = array_map(function ($file) { |
|
249 | + $this->fonts = array_map(function($file) { |
|
250 | 250 | /* @var File $file */ |
251 | 251 | return $file->getPathName(); |
252 | 252 | }, $this->fonts); |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | } |
295 | 295 | |
296 | 296 | if ($api) { |
297 | - Cache::put('captcha_record_' . $generator['key'], $generator['value'], $this->expire); |
|
297 | + Cache::put('captcha_record_'.$generator['key'], $generator['value'], $this->expire); |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | return $api ? [ |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | } |
342 | 342 | |
343 | 343 | $hash = $this->hasher->make($key); |
344 | - if($this->encrypt) $hash = Crypt::encrypt($hash); |
|
344 | + if ($this->encrypt) $hash = Crypt::encrypt($hash); |
|
345 | 345 | |
346 | 346 | $this->session->put('captcha', [ |
347 | 347 | 'sensitive' => $this->sensitive, |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | foreach ($text as $key => $char) { |
373 | 373 | $marginLeft = $this->textLeftPadding + ($key * ($this->image->width() - $this->textLeftPadding) / $this->length); |
374 | 374 | |
375 | - $this->image->text($char, $marginLeft, $marginTop, function ($font) { |
|
375 | + $this->image->text($char, $marginLeft, $marginTop, function($font) { |
|
376 | 376 | /* @var Font $font */ |
377 | 377 | $font->file($this->font()); |
378 | 378 | $font->size($this->fontSize()); |
@@ -411,10 +411,10 @@ discard block |
||
411 | 411 | */ |
412 | 412 | protected function fontColor(): string |
413 | 413 | { |
414 | - if (!empty($this->fontColors)) { |
|
414 | + if ( ! empty($this->fontColors)) { |
|
415 | 415 | $color = $this->fontColors[rand(0, count($this->fontColors) - 1)]; |
416 | 416 | } else { |
417 | - $color = '#' . str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT); |
|
417 | + $color = '#'.str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT); |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | return $color; |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | rand(0, $this->image->height()), |
444 | 444 | rand(0, $this->image->width()), |
445 | 445 | rand(0, $this->image->height()), |
446 | - function ($draw) { |
|
446 | + function($draw) { |
|
447 | 447 | /* @var Font $draw */ |
448 | 448 | $draw->color($this->fontColor()); |
449 | 449 | } |
@@ -461,18 +461,18 @@ discard block |
||
461 | 461 | */ |
462 | 462 | public function check(string $value): bool |
463 | 463 | { |
464 | - if (!$this->session->has('captcha')) { |
|
464 | + if ( ! $this->session->has('captcha')) { |
|
465 | 465 | return false; |
466 | 466 | } |
467 | 467 | |
468 | 468 | $key = $this->session->get('captcha.key'); |
469 | 469 | $sensitive = $this->session->get('captcha.sensitive'); |
470 | 470 | |
471 | - if (!$sensitive) { |
|
471 | + if ( ! $sensitive) { |
|
472 | 472 | $value = $this->str->lower($value); |
473 | 473 | } |
474 | 474 | |
475 | - if($this->encrypt) $key = Crypt::decrypt($key); |
|
475 | + if ($this->encrypt) $key = Crypt::decrypt($key); |
|
476 | 476 | $check = $this->hasher->check($value, $key); |
477 | 477 | // if verify pass,remove session |
478 | 478 | if ($check) { |
@@ -491,11 +491,11 @@ discard block |
||
491 | 491 | */ |
492 | 492 | public function check_api($value, $key): bool |
493 | 493 | { |
494 | - if (!Cache::pull('captcha_record_' . $key)) { |
|
494 | + if ( ! Cache::pull('captcha_record_'.$key)) { |
|
495 | 495 | return false; |
496 | 496 | } |
497 | 497 | |
498 | - if($this->encrypt) $key = Crypt::decrypt($key); |
|
498 | + if ($this->encrypt) $key = Crypt::decrypt($key); |
|
499 | 499 | return $this->hasher->check($value, $key); |
500 | 500 | } |
501 | 501 | |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | */ |
508 | 508 | public function src(string $config = 'default'): string |
509 | 509 | { |
510 | - return url('captcha/' . $config) . '?' . $this->str->random(8); |
|
510 | + return url('captcha/'.$config).'?'.$this->str->random(8); |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | /** |
@@ -527,8 +527,8 @@ discard block |
||
527 | 527 | continue; |
528 | 528 | } |
529 | 529 | |
530 | - $attrs_str .= $attr . '="' . $value . '" '; |
|
530 | + $attrs_str .= $attr.'="'.$value.'" '; |
|
531 | 531 | } |
532 | - return new HtmlString('<img src="' . $this->src($config) . '" ' . trim($attrs_str) . '>'); |
|
532 | + return new HtmlString('<img src="'.$this->src($config).'" '.trim($attrs_str).'>'); |
|
533 | 533 | } |
534 | 534 | } |
@@ -341,7 +341,9 @@ discard block |
||
341 | 341 | } |
342 | 342 | |
343 | 343 | $hash = $this->hasher->make($key); |
344 | - if($this->encrypt) $hash = Crypt::encrypt($hash); |
|
344 | + if($this->encrypt) { |
|
345 | + $hash = Crypt::encrypt($hash); |
|
346 | + } |
|
345 | 347 | |
346 | 348 | $this->session->put('captcha', [ |
347 | 349 | 'sensitive' => $this->sensitive, |
@@ -472,7 +474,9 @@ discard block |
||
472 | 474 | $value = $this->str->lower($value); |
473 | 475 | } |
474 | 476 | |
475 | - if($this->encrypt) $key = Crypt::decrypt($key); |
|
477 | + if($this->encrypt) { |
|
478 | + $key = Crypt::decrypt($key); |
|
479 | + } |
|
476 | 480 | $check = $this->hasher->check($value, $key); |
477 | 481 | // if verify pass,remove session |
478 | 482 | if ($check) { |
@@ -495,7 +499,9 @@ discard block |
||
495 | 499 | return false; |
496 | 500 | } |
497 | 501 | |
498 | - if($this->encrypt) $key = Crypt::decrypt($key); |
|
502 | + if($this->encrypt) { |
|
503 | + $key = Crypt::decrypt($key); |
|
504 | + } |
|
499 | 505 | return $this->hasher->check($value, $key); |
500 | 506 | } |
501 | 507 |