@@ -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 |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | $this->hasher = $hasher; |
231 | 231 | $this->str = $str; |
232 | 232 | $this->characters = config('captcha.characters', ['1', '2', '3', '4', '6', '7', '8', '9']); |
233 | - $this->fontsDirectory = config('captcha.fontsDirectory', dirname(__DIR__) . '/assets/fonts'); |
|
233 | + $this->fontsDirectory = config('captcha.fontsDirectory', dirname(__DIR__).'/assets/fonts'); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
@@ -239,8 +239,8 @@ discard block |
||
239 | 239 | */ |
240 | 240 | protected function configure($config) |
241 | 241 | { |
242 | - if ($this->config->has('captcha.' . $config)) { |
|
243 | - foreach ($this->config->get('captcha.' . $config) as $key => $val) { |
|
242 | + if ($this->config->has('captcha.'.$config)) { |
|
243 | + foreach ($this->config->get('captcha.'.$config) as $key => $val) { |
|
244 | 244 | $this->{$key} = $val; |
245 | 245 | } |
246 | 246 | } |
@@ -256,11 +256,11 @@ discard block |
||
256 | 256 | */ |
257 | 257 | public function create(string $config = 'default', bool $api = false) |
258 | 258 | { |
259 | - $this->backgrounds = $this->files->files(__DIR__ . '/../assets/backgrounds'); |
|
259 | + $this->backgrounds = $this->files->files(__DIR__.'/../assets/backgrounds'); |
|
260 | 260 | $this->fonts = $this->files->files($this->fontsDirectory); |
261 | 261 | |
262 | 262 | if (version_compare(app()->version(), '5.5.0', '>=')) { |
263 | - $this->fonts = array_map(function ($file) { |
|
263 | + $this->fonts = array_map(function($file) { |
|
264 | 264 | /* @var File $file */ |
265 | 265 | return $file->getPathName(); |
266 | 266 | }, $this->fonts); |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | $generator = $this->generate(); |
274 | 274 | $this->text = $generator['value']; |
275 | 275 | |
276 | - $this->canvas = $this->imageManager->create($this->width , $this->height)->fill($this->fill); |
|
276 | + $this->canvas = $this->imageManager->create($this->width, $this->height)->fill($this->fill); |
|
277 | 277 | |
278 | 278 | |
279 | 279 | if ($this->bgImage) { |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | } |
354 | 354 | |
355 | 355 | $hash = $this->hasher->make($key); |
356 | - if($this->encrypt) $hash = Crypt::encrypt($hash); |
|
356 | + if ($this->encrypt) $hash = Crypt::encrypt($hash); |
|
357 | 357 | |
358 | 358 | $this->session->put('captcha', [ |
359 | 359 | 'sensitive' => $this->sensitive, |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | foreach ($text as $key => $char) { |
389 | 389 | $marginLeft = $this->textLeftPadding + ($key * ($this->image->width() - $this->textLeftPadding) / $this->length); |
390 | 390 | |
391 | - $this->image->text($char, $marginLeft, $marginTop, function ($font) { |
|
391 | + $this->image->text($char, $marginLeft, $marginTop, function($font) { |
|
392 | 392 | /* @var Font $font */ |
393 | 393 | $font->file($this->font()); |
394 | 394 | $font->size($this->fontSize()); |
@@ -427,10 +427,10 @@ discard block |
||
427 | 427 | */ |
428 | 428 | protected function fontColor(): string |
429 | 429 | { |
430 | - if (!empty($this->fontColors)) { |
|
430 | + if ( ! empty($this->fontColors)) { |
|
431 | 431 | $color = $this->fontColors[rand(0, count($this->fontColors) - 1)]; |
432 | 432 | } else { |
433 | - $color = '#' . str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT); |
|
433 | + $color = '#'.str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | return $color; |
@@ -454,9 +454,9 @@ discard block |
||
454 | 454 | protected function lines() |
455 | 455 | { |
456 | 456 | for ($i = 0; $i <= $this->lines; $i++) { |
457 | - $this->image->drawLine(function (LineFactory $line) use ($i) { |
|
458 | - $line->from(rand(0, $this->image->width()) + $i * rand(0, $this->image->height()) , rand(0, $this->image->height())); |
|
459 | - $line->to( rand(0, $this->image->width()), rand(0, $this->image->height())); |
|
457 | + $this->image->drawLine(function(LineFactory $line) use ($i) { |
|
458 | + $line->from(rand(0, $this->image->width()) + $i * rand(0, $this->image->height()), rand(0, $this->image->height())); |
|
459 | + $line->to(rand(0, $this->image->width()), rand(0, $this->image->height())); |
|
460 | 460 | $line->color('ff00ff'); // color of line |
461 | 461 | $line->width(5); // line width in pixels |
462 | 462 | }); |
@@ -473,7 +473,7 @@ discard block |
||
473 | 473 | */ |
474 | 474 | public function check(string $value): bool |
475 | 475 | { |
476 | - if (!$this->session->has('captcha')) { |
|
476 | + if ( ! $this->session->has('captcha')) { |
|
477 | 477 | return false; |
478 | 478 | } |
479 | 479 | |
@@ -481,16 +481,16 @@ discard block |
||
481 | 481 | $sensitive = $this->session->get('captcha.sensitive'); |
482 | 482 | $encrypt = $this->session->get('captcha.encrypt'); |
483 | 483 | |
484 | - if (!Cache::pull($this->get_cache_key($key))) { |
|
484 | + if ( ! Cache::pull($this->get_cache_key($key))) { |
|
485 | 485 | $this->session->remove('captcha'); |
486 | 486 | return false; |
487 | 487 | } |
488 | 488 | |
489 | - if (!$sensitive) { |
|
489 | + if ( ! $sensitive) { |
|
490 | 490 | $value = $this->str->lower($value); |
491 | 491 | } |
492 | 492 | |
493 | - if($encrypt) $key = Crypt::decrypt($key); |
|
493 | + if ($encrypt) $key = Crypt::decrypt($key); |
|
494 | 494 | $check = $this->hasher->check($value, $key); |
495 | 495 | // if verify pass,remove session |
496 | 496 | if ($check) { |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | * @return string |
508 | 508 | */ |
509 | 509 | protected function get_cache_key($key) { |
510 | - return 'captcha_' . md5($key); |
|
510 | + return 'captcha_'.md5($key); |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | /** |
@@ -520,14 +520,14 @@ discard block |
||
520 | 520 | */ |
521 | 521 | public function check_api($value, $key, $config = 'default'): bool |
522 | 522 | { |
523 | - if (!Cache::pull($this->get_cache_key($key))) { |
|
523 | + if ( ! Cache::pull($this->get_cache_key($key))) { |
|
524 | 524 | return false; |
525 | 525 | } |
526 | 526 | |
527 | 527 | $this->configure($config); |
528 | 528 | |
529 | - if(!$this->sensitive) $value = $this->str->lower($value); |
|
530 | - if($this->encrypt) $key = Crypt::decrypt($key); |
|
529 | + if ( ! $this->sensitive) $value = $this->str->lower($value); |
|
530 | + if ($this->encrypt) $key = Crypt::decrypt($key); |
|
531 | 531 | return $this->hasher->check($value, $key); |
532 | 532 | } |
533 | 533 | |
@@ -539,7 +539,7 @@ discard block |
||
539 | 539 | */ |
540 | 540 | public function src(string $config = 'default'): string |
541 | 541 | { |
542 | - return url('captcha/' . $config) . '?' . $this->str->random(8); |
|
542 | + return url('captcha/'.$config).'?'.$this->str->random(8); |
|
543 | 543 | } |
544 | 544 | |
545 | 545 | /** |
@@ -559,8 +559,8 @@ discard block |
||
559 | 559 | continue; |
560 | 560 | } |
561 | 561 | |
562 | - $attrs_str .= $attr . '="' . $value . '" '; |
|
562 | + $attrs_str .= $attr.'="'.$value.'" '; |
|
563 | 563 | } |
564 | - return new HtmlString('<img src="' . $this->src($config) . '" ' . trim($attrs_str) . '>'); |
|
564 | + return new HtmlString('<img src="'.$this->src($config).'" '.trim($attrs_str).'>'); |
|
565 | 565 | } |
566 | 566 | } |
@@ -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'], |