@@ -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 |
@@ -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, |
@@ -474,7 +476,9 @@ discard block |
||
474 | 476 | $value = $this->str->lower($value); |
475 | 477 | } |
476 | 478 | |
477 | - if($encrypt) $key = Crypt::decrypt($key); |
|
479 | + if($encrypt) { |
|
480 | + $key = Crypt::decrypt($key); |
|
481 | + } |
|
478 | 482 | $check = $this->hasher->check($value, $key); |
479 | 483 | // if verify pass,remove session |
480 | 484 | if ($check) { |
@@ -500,8 +504,12 @@ discard block |
||
500 | 504 | |
501 | 505 | $this->configure($config); |
502 | 506 | |
503 | - if(!$this->sensitive) $value = $this->str->lower($value); |
|
504 | - if($this->encrypt) $key = Crypt::decrypt($key); |
|
507 | + if(!$this->sensitive) { |
|
508 | + $value = $this->str->lower($value); |
|
509 | + } |
|
510 | + if($this->encrypt) { |
|
511 | + $key = Crypt::decrypt($key); |
|
512 | + } |
|
505 | 513 | return $this->hasher->check($value, $key); |
506 | 514 | } |
507 | 515 |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | $this->hasher = $hasher; |
240 | 240 | $this->str = $str; |
241 | 241 | $this->characters = config('captcha.characters', ['1', '2', '3', '4', '6', '7', '8', '9']); |
242 | - $this->fontsDirectory = config('captcha.fontsDirectory', dirname(__DIR__) . '/assets/fonts'); |
|
242 | + $this->fontsDirectory = config('captcha.fontsDirectory', dirname(__DIR__).'/assets/fonts'); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
@@ -248,8 +248,8 @@ discard block |
||
248 | 248 | */ |
249 | 249 | protected function configure($config) |
250 | 250 | { |
251 | - if ($this->config->has('captcha.' . $config)) { |
|
252 | - foreach ($this->config->get('captcha.' . $config) as $key => $val) { |
|
251 | + if ($this->config->has('captcha.'.$config)) { |
|
252 | + foreach ($this->config->get('captcha.'.$config) as $key => $val) { |
|
253 | 253 | $this->{$key} = $val; |
254 | 254 | } |
255 | 255 | } |
@@ -265,11 +265,11 @@ discard block |
||
265 | 265 | */ |
266 | 266 | public function create(string $config = 'default', bool $api = false) |
267 | 267 | { |
268 | - $this->backgrounds = $this->files->files(__DIR__ . '/../assets/backgrounds'); |
|
268 | + $this->backgrounds = $this->files->files(__DIR__.'/../assets/backgrounds'); |
|
269 | 269 | $this->fonts = $this->files->files($this->fontsDirectory); |
270 | 270 | |
271 | 271 | if (version_compare(app()->version(), '5.5.0', '>=')) { |
272 | - $this->fonts = array_map(function ($file) { |
|
272 | + $this->fonts = array_map(function($file) { |
|
273 | 273 | /* @var File $file */ |
274 | 274 | return $file->getPathName(); |
275 | 275 | }, $this->fonts); |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | $generator = $this->generate(); |
283 | 283 | $this->text = $generator['value']; |
284 | 284 | |
285 | - $this->canvas = $this->imageManager->create($this->width , $this->height)->fill($this->fill); |
|
285 | + $this->canvas = $this->imageManager->create($this->width, $this->height)->fill($this->fill); |
|
286 | 286 | |
287 | 287 | |
288 | 288 | if ($this->bgImage) { |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | } |
363 | 363 | |
364 | 364 | $hash = $this->hasher->make($key); |
365 | - if($this->encrypt) $hash = Crypt::encrypt($hash); |
|
365 | + if ($this->encrypt) $hash = Crypt::encrypt($hash); |
|
366 | 366 | |
367 | 367 | $this->session->put('captcha', [ |
368 | 368 | 'sensitive' => $this->sensitive, |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | foreach ($text as $key => $char) { |
398 | 398 | $marginLeft = $this->textLeftPadding + ($key * ($this->image->width() - $this->textLeftPadding) / $this->length); |
399 | 399 | |
400 | - $this->image->text($char, $marginLeft, $marginTop, function ($font) { |
|
400 | + $this->image->text($char, $marginLeft, $marginTop, function($font) { |
|
401 | 401 | /* @var Font $font */ |
402 | 402 | $font->file($this->font()); |
403 | 403 | $font->size($this->fontSize()); |
@@ -436,10 +436,10 @@ discard block |
||
436 | 436 | */ |
437 | 437 | protected function fontColor(): string |
438 | 438 | { |
439 | - if (!empty($this->fontColors)) { |
|
439 | + if ( ! empty($this->fontColors)) { |
|
440 | 440 | $color = $this->fontColors[rand(0, count($this->fontColors) - 1)]; |
441 | 441 | } else { |
442 | - $color = '#' . str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT); |
|
442 | + $color = '#'.str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT); |
|
443 | 443 | } |
444 | 444 | |
445 | 445 | return $color; |
@@ -463,9 +463,9 @@ discard block |
||
463 | 463 | protected function lines() |
464 | 464 | { |
465 | 465 | for ($i = 0; $i <= $this->lines; $i++) { |
466 | - $this->image->drawLine(function (LineFactory $line) use ($i) { |
|
467 | - $line->from(rand(0, $this->image->width()) + $i * rand(0, $this->image->height()) , rand(0, $this->image->height())); |
|
468 | - $line->to( rand(0, $this->image->width()), rand(0, $this->image->height())); |
|
466 | + $this->image->drawLine(function(LineFactory $line) use ($i) { |
|
467 | + $line->from(rand(0, $this->image->width()) + $i * rand(0, $this->image->height()), rand(0, $this->image->height())); |
|
468 | + $line->to(rand(0, $this->image->width()), rand(0, $this->image->height())); |
|
469 | 469 | $line->color($this->lineColor); // color of line |
470 | 470 | $line->width($this->lineWidth); // line width in pixels |
471 | 471 | }); |
@@ -482,7 +482,7 @@ discard block |
||
482 | 482 | */ |
483 | 483 | public function check(string $value): bool |
484 | 484 | { |
485 | - if (!$this->session->has('captcha')) { |
|
485 | + if ( ! $this->session->has('captcha')) { |
|
486 | 486 | return false; |
487 | 487 | } |
488 | 488 | |
@@ -490,16 +490,16 @@ discard block |
||
490 | 490 | $sensitive = $this->session->get('captcha.sensitive'); |
491 | 491 | $encrypt = $this->session->get('captcha.encrypt'); |
492 | 492 | |
493 | - if (!Cache::pull($this->get_cache_key($key))) { |
|
493 | + if ( ! Cache::pull($this->get_cache_key($key))) { |
|
494 | 494 | $this->session->remove('captcha'); |
495 | 495 | return false; |
496 | 496 | } |
497 | 497 | |
498 | - if (!$sensitive) { |
|
498 | + if ( ! $sensitive) { |
|
499 | 499 | $value = $this->str->lower($value); |
500 | 500 | } |
501 | 501 | |
502 | - if($encrypt) $key = Crypt::decrypt($key); |
|
502 | + if ($encrypt) $key = Crypt::decrypt($key); |
|
503 | 503 | $check = $this->hasher->check($value, $key); |
504 | 504 | // if verify pass,remove session |
505 | 505 | if ($check) { |
@@ -516,7 +516,7 @@ discard block |
||
516 | 516 | * @return string |
517 | 517 | */ |
518 | 518 | protected function get_cache_key($key) { |
519 | - return 'captcha_' . md5($key); |
|
519 | + return 'captcha_'.md5($key); |
|
520 | 520 | } |
521 | 521 | |
522 | 522 | /** |
@@ -529,14 +529,14 @@ discard block |
||
529 | 529 | */ |
530 | 530 | public function check_api($value, $key, $config = 'default'): bool |
531 | 531 | { |
532 | - if (!Cache::pull($this->get_cache_key($key))) { |
|
532 | + if ( ! Cache::pull($this->get_cache_key($key))) { |
|
533 | 533 | return false; |
534 | 534 | } |
535 | 535 | |
536 | 536 | $this->configure($config); |
537 | 537 | |
538 | - if(!$this->sensitive) $value = $this->str->lower($value); |
|
539 | - if($this->encrypt) $key = Crypt::decrypt($key); |
|
538 | + if ( ! $this->sensitive) $value = $this->str->lower($value); |
|
539 | + if ($this->encrypt) $key = Crypt::decrypt($key); |
|
540 | 540 | return $this->hasher->check($value, $key); |
541 | 541 | } |
542 | 542 | |
@@ -548,7 +548,7 @@ discard block |
||
548 | 548 | */ |
549 | 549 | public function src(string $config = 'default'): string |
550 | 550 | { |
551 | - return url('captcha/' . $config) . '?' . $this->str->random(8); |
|
551 | + return url('captcha/'.$config).'?'.$this->str->random(8); |
|
552 | 552 | } |
553 | 553 | |
554 | 554 | /** |
@@ -568,8 +568,8 @@ discard block |
||
568 | 568 | continue; |
569 | 569 | } |
570 | 570 | |
571 | - $attrs_str .= $attr . '="' . $value . '" '; |
|
571 | + $attrs_str .= $attr.'="'.$value.'" '; |
|
572 | 572 | } |
573 | - return new HtmlString('<img src="' . $this->src($config) . '" ' . trim($attrs_str) . '>'); |
|
573 | + return new HtmlString('<img src="'.$this->src($config).'" '.trim($attrs_str).'>'); |
|
574 | 574 | } |
575 | 575 | } |
@@ -74,8 +74,8 @@ |
||
74 | 74 | 'captcha' |
75 | 75 | ); |
76 | 76 | |
77 | - // Bind the ImageManager with an explicit driver |
|
78 | - if (!$this->app->bound('Intervention\Image\ImageManager')) { |
|
77 | + // Bind the ImageManager with an explicit driver |
|
78 | + if (!$this->app->bound('Intervention\Image\ImageManager')) { |
|
79 | 79 | $this->app->singleton('Intervention\Image\ImageManager', function ($app) { |
80 | 80 | // Determine which driver to use, defaulting to 'gd' |
81 | 81 | $driver = config('captcha.driver', 'gd') === 'imagick' ? new ImagickDriver() : new GdDriver(); |
@@ -24,11 +24,11 @@ discard block |
||
24 | 24 | { |
25 | 25 | // Publish configuration files |
26 | 26 | $this->publishes([ |
27 | - __DIR__ . '/../config/captcha.php' => config_path('captcha.php') |
|
27 | + __DIR__.'/../config/captcha.php' => config_path('captcha.php') |
|
28 | 28 | ], 'config'); |
29 | 29 | |
30 | 30 | // HTTP routing |
31 | - if(!config('captcha.disable')){ |
|
31 | + if ( ! config('captcha.disable')) { |
|
32 | 32 | if (strpos($this->app->version(), 'Lumen') !== false) { |
33 | 33 | /* @var Router $router */ |
34 | 34 | $router = $this->app; |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | } else { |
38 | 38 | /* @var Router $router */ |
39 | 39 | $router = $this->app['router']; |
40 | - if ((double)$this->app->version() >= 5.2) { |
|
40 | + if ((double) $this->app->version() >= 5.2) { |
|
41 | 41 | $router->get('captcha/api/{config?}', '\Mews\Captcha\CaptchaController@getCaptchaApi')->middleware('web'); |
42 | 42 | $router->get('captcha/{config?}', '\Mews\Captcha\CaptchaController@getCaptcha')->middleware('web'); |
43 | 43 | } else { |
@@ -51,12 +51,12 @@ discard block |
||
51 | 51 | $validator = $this->app['validator']; |
52 | 52 | |
53 | 53 | // Validator extensions |
54 | - $validator->extend('captcha', function ($attribute, $value, $parameters) { |
|
54 | + $validator->extend('captcha', function($attribute, $value, $parameters) { |
|
55 | 55 | return config('captcha.disable') || ($value && captcha_check($value)); |
56 | 56 | }); |
57 | 57 | |
58 | 58 | // Validator extensions |
59 | - $validator->extend('captcha_api', function ($attribute, $value, $parameters) { |
|
59 | + $validator->extend('captcha_api', function($attribute, $value, $parameters) { |
|
60 | 60 | return config('captcha.disable') || ($value && captcha_api_check($value, $parameters[0], $parameters[1] ?? 'default')); |
61 | 61 | }); |
62 | 62 | } |
@@ -70,13 +70,13 @@ discard block |
||
70 | 70 | { |
71 | 71 | // Merge configs |
72 | 72 | $this->mergeConfigFrom( |
73 | - __DIR__ . '/../config/captcha.php', |
|
73 | + __DIR__.'/../config/captcha.php', |
|
74 | 74 | 'captcha' |
75 | 75 | ); |
76 | 76 | |
77 | 77 | // Bind the ImageManager with an explicit driver |
78 | - if (!$this->app->bound('Intervention\Image\ImageManager')) { |
|
79 | - $this->app->singleton('Intervention\Image\ImageManager', function ($app) { |
|
78 | + if ( ! $this->app->bound('Intervention\Image\ImageManager')) { |
|
79 | + $this->app->singleton('Intervention\Image\ImageManager', function($app) { |
|
80 | 80 | // Determine which driver to use, defaulting to 'gd' |
81 | 81 | $driver = config('captcha.driver', 'gd') === 'imagick' ? new ImagickDriver() : new GdDriver(); |
82 | 82 | |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | } |
86 | 86 | |
87 | 87 | // Bind captcha |
88 | - $this->app->bind('captcha', function ($app) { |
|
88 | + $this->app->bind('captcha', function($app) { |
|
89 | 89 | return new Captcha( |
90 | 90 | $app['Illuminate\Filesystem\Filesystem'], |
91 | 91 | $app['Illuminate\Contracts\Config\Repository'], |