@@ -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 | |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | $this->hasher = $hasher; |
| 234 | 234 | $this->str = $str; |
| 235 | 235 | $this->characters = config('captcha.characters', ['1', '2', '3', '4', '6', '7', '8', '9']); |
| 236 | - $this->fontsDirectory = config('captcha.fontsDirectory', dirname(__DIR__) . '/assets/fonts'); |
|
| 236 | + $this->fontsDirectory = config('captcha.fontsDirectory', dirname(__DIR__).'/assets/fonts'); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -242,8 +242,8 @@ discard block |
||
| 242 | 242 | */ |
| 243 | 243 | protected function configure($config) |
| 244 | 244 | { |
| 245 | - if ($this->config->has('captcha.' . $config)) { |
|
| 246 | - foreach ($this->config->get('captcha.' . $config) as $key => $val) { |
|
| 245 | + if ($this->config->has('captcha.'.$config)) { |
|
| 246 | + foreach ($this->config->get('captcha.'.$config) as $key => $val) { |
|
| 247 | 247 | $this->{$key} = $val; |
| 248 | 248 | } |
| 249 | 249 | } |
@@ -259,11 +259,11 @@ discard block |
||
| 259 | 259 | */ |
| 260 | 260 | public function create(string $config = 'default', bool $api = false) |
| 261 | 261 | { |
| 262 | - $this->backgrounds = $this->files->files(__DIR__ . '/../assets/backgrounds'); |
|
| 262 | + $this->backgrounds = $this->files->files(__DIR__.'/../assets/backgrounds'); |
|
| 263 | 263 | $this->fonts = $this->files->files($this->fontsDirectory); |
| 264 | 264 | |
| 265 | 265 | if (version_compare(app()->version(), '5.5.0', '>=')) { |
| 266 | - $this->fonts = array_map(function ($file) { |
|
| 266 | + $this->fonts = array_map(function($file) { |
|
| 267 | 267 | /* @var File $file */ |
| 268 | 268 | return $file->getPathName(); |
| 269 | 269 | }, $this->fonts); |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | $generator = $this->generate(); |
| 277 | 277 | $this->text = $generator['value']; |
| 278 | 278 | |
| 279 | - $this->canvas = $this->imageManager->create($this->width , $this->height)->fill($this->fill); |
|
| 279 | + $this->canvas = $this->imageManager->create($this->width, $this->height)->fill($this->fill); |
|
| 280 | 280 | |
| 281 | 281 | |
| 282 | 282 | if ($this->bgImage) { |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | $hash = $this->hasher->make($key); |
| 359 | - if($this->encrypt) $hash = Crypt::encrypt($hash); |
|
| 359 | + if ($this->encrypt) $hash = Crypt::encrypt($hash); |
|
| 360 | 360 | |
| 361 | 361 | $this->session->put('captcha', [ |
| 362 | 362 | 'sensitive' => $this->sensitive, |
@@ -391,7 +391,7 @@ discard block |
||
| 391 | 391 | foreach ($text as $key => $char) { |
| 392 | 392 | $marginLeft = $this->textLeftPadding + ($key * ($this->image->width() - $this->textLeftPadding) / $this->length); |
| 393 | 393 | |
| 394 | - $this->image->text($char, $marginLeft, $marginTop, function ($font) { |
|
| 394 | + $this->image->text($char, $marginLeft, $marginTop, function($font) { |
|
| 395 | 395 | /* @var Font $font */ |
| 396 | 396 | $font->file($this->font()); |
| 397 | 397 | $font->size($this->fontSize()); |
@@ -430,10 +430,10 @@ discard block |
||
| 430 | 430 | */ |
| 431 | 431 | protected function fontColor(): string |
| 432 | 432 | { |
| 433 | - if (!empty($this->fontColors)) { |
|
| 433 | + if ( ! empty($this->fontColors)) { |
|
| 434 | 434 | $color = $this->fontColors[rand(0, count($this->fontColors) - 1)]; |
| 435 | 435 | } else { |
| 436 | - $color = '#' . str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT); |
|
| 436 | + $color = '#'.str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT); |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | return $color; |
@@ -457,9 +457,9 @@ discard block |
||
| 457 | 457 | protected function lines() |
| 458 | 458 | { |
| 459 | 459 | for ($i = 0; $i <= $this->lines; $i++) { |
| 460 | - $this->image->drawLine(function (LineFactory $line) use ($i) { |
|
| 461 | - $line->from(rand(0, $this->image->width()) + $i * rand(0, $this->image->height()) , rand(0, $this->image->height())); |
|
| 462 | - $line->to( rand(0, $this->image->width()), rand(0, $this->image->height())); |
|
| 460 | + $this->image->drawLine(function(LineFactory $line) use ($i) { |
|
| 461 | + $line->from(rand(0, $this->image->width()) + $i * rand(0, $this->image->height()), rand(0, $this->image->height())); |
|
| 462 | + $line->to(rand(0, $this->image->width()), rand(0, $this->image->height())); |
|
| 463 | 463 | $line->color($this->fontColor()); // color of line |
| 464 | 464 | $line->width($this->lineWidth); // line width in pixels |
| 465 | 465 | }); |
@@ -476,7 +476,7 @@ discard block |
||
| 476 | 476 | */ |
| 477 | 477 | public function check(string $value): bool |
| 478 | 478 | { |
| 479 | - if (!$this->session->has('captcha')) { |
|
| 479 | + if ( ! $this->session->has('captcha')) { |
|
| 480 | 480 | return false; |
| 481 | 481 | } |
| 482 | 482 | |
@@ -484,16 +484,16 @@ discard block |
||
| 484 | 484 | $sensitive = $this->session->get('captcha.sensitive'); |
| 485 | 485 | $encrypt = $this->session->get('captcha.encrypt'); |
| 486 | 486 | |
| 487 | - if (!Cache::pull($this->get_cache_key($key))) { |
|
| 487 | + if ( ! Cache::pull($this->get_cache_key($key))) { |
|
| 488 | 488 | $this->session->remove('captcha'); |
| 489 | 489 | return false; |
| 490 | 490 | } |
| 491 | 491 | |
| 492 | - if (!$sensitive) { |
|
| 492 | + if ( ! $sensitive) { |
|
| 493 | 493 | $value = $this->str->lower($value); |
| 494 | 494 | } |
| 495 | 495 | |
| 496 | - if($encrypt) $key = Crypt::decrypt($key); |
|
| 496 | + if ($encrypt) $key = Crypt::decrypt($key); |
|
| 497 | 497 | $check = $this->hasher->check($value, $key); |
| 498 | 498 | // if verify pass,remove session |
| 499 | 499 | if ($check) { |
@@ -510,7 +510,7 @@ discard block |
||
| 510 | 510 | * @return string |
| 511 | 511 | */ |
| 512 | 512 | protected function get_cache_key($key) { |
| 513 | - return 'captcha_' . md5($key); |
|
| 513 | + return 'captcha_'.md5($key); |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | /** |
@@ -523,14 +523,14 @@ discard block |
||
| 523 | 523 | */ |
| 524 | 524 | public function check_api($value, $key, $config = 'default'): bool |
| 525 | 525 | { |
| 526 | - if (!Cache::pull($this->get_cache_key($key))) { |
|
| 526 | + if ( ! Cache::pull($this->get_cache_key($key))) { |
|
| 527 | 527 | return false; |
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | $this->configure($config); |
| 531 | 531 | |
| 532 | - if(!$this->sensitive) $value = $this->str->lower($value); |
|
| 533 | - if($this->encrypt) $key = Crypt::decrypt($key); |
|
| 532 | + if ( ! $this->sensitive) $value = $this->str->lower($value); |
|
| 533 | + if ($this->encrypt) $key = Crypt::decrypt($key); |
|
| 534 | 534 | return $this->hasher->check($value, $key); |
| 535 | 535 | } |
| 536 | 536 | |
@@ -542,7 +542,7 @@ discard block |
||
| 542 | 542 | */ |
| 543 | 543 | public function src(string $config = 'default'): string |
| 544 | 544 | { |
| 545 | - return url('captcha/' . $config) . '?' . $this->str->random(8); |
|
| 545 | + return url('captcha/'.$config).'?'.$this->str->random(8); |
|
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | /** |
@@ -562,8 +562,8 @@ discard block |
||
| 562 | 562 | continue; |
| 563 | 563 | } |
| 564 | 564 | |
| 565 | - $attrs_str .= $attr . '="' . $value . '" '; |
|
| 565 | + $attrs_str .= $attr.'="'.$value.'" '; |
|
| 566 | 566 | } |
| 567 | - return new HtmlString('<img src="' . $this->src($config) . '" ' . trim($attrs_str) . '>'); |
|
| 567 | + return new HtmlString('<img src="'.$this->src($config).'" '.trim($attrs_str).'>'); |
|
| 568 | 568 | } |
| 569 | 569 | } |
@@ -21,11 +21,11 @@ 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 |
| 28 | - if(!config('captcha.disable')){ |
|
| 28 | + if ( ! config('captcha.disable')) { |
|
| 29 | 29 | if (strpos($this->app->version(), 'Lumen') !== false) { |
| 30 | 30 | /* @var Router $router */ |
| 31 | 31 | $router = $this->app; |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | } else { |
| 35 | 35 | /* @var Router $router */ |
| 36 | 36 | $router = $this->app['router']; |
| 37 | - if ((double)$this->app->version() >= 5.2) { |
|
| 37 | + if ((double) $this->app->version() >= 5.2) { |
|
| 38 | 38 | $router->get('captcha/api/{config?}', '\Mews\Captcha\CaptchaController@getCaptchaApi')->middleware('web'); |
| 39 | 39 | $router->get('captcha/{config?}', '\Mews\Captcha\CaptchaController@getCaptcha')->middleware('web'); |
| 40 | 40 | } else { |
@@ -48,12 +48,12 @@ discard block |
||
| 48 | 48 | $validator = $this->app['validator']; |
| 49 | 49 | |
| 50 | 50 | // Validator extensions |
| 51 | - $validator->extend('captcha', function ($attribute, $value, $parameters) { |
|
| 51 | + $validator->extend('captcha', function($attribute, $value, $parameters) { |
|
| 52 | 52 | return config('captcha.disable') || ($value && captcha_check($value)); |
| 53 | 53 | }); |
| 54 | 54 | |
| 55 | 55 | // Validator extensions |
| 56 | - $validator->extend('captcha_api', function ($attribute, $value, $parameters) { |
|
| 56 | + $validator->extend('captcha_api', function($attribute, $value, $parameters) { |
|
| 57 | 57 | return config('captcha.disable') || ($value && captcha_api_check($value, $parameters[0], $parameters[1] ?? 'default')); |
| 58 | 58 | }); |
| 59 | 59 | } |
@@ -67,12 +67,12 @@ discard block |
||
| 67 | 67 | { |
| 68 | 68 | // Merge configs |
| 69 | 69 | $this->mergeConfigFrom( |
| 70 | - __DIR__ . '/../config/captcha.php', |
|
| 70 | + __DIR__.'/../config/captcha.php', |
|
| 71 | 71 | 'captcha' |
| 72 | 72 | ); |
| 73 | 73 | |
| 74 | 74 | // Bind captcha |
| 75 | - $this->app->bind('captcha', function ($app) { |
|
| 75 | + $this->app->bind('captcha', function($app) { |
|
| 76 | 76 | return new Captcha( |
| 77 | 77 | $app['Illuminate\Filesystem\Filesystem'], |
| 78 | 78 | $app['Illuminate\Contracts\Config\Repository'], |