@@ -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'], |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | $this->hasher = $hasher; |
| 211 | 211 | $this->str = $str; |
| 212 | 212 | $this->characters = config('captcha.characters', ['1', '2', '3', '4', '6', '7', '8', '9']); |
| 213 | - $this->fontsDirectory = config('captcha.fontsDirectory', __DIR__ . '/../assets/fonts'); |
|
| 213 | + $this->fontsDirectory = config('captcha.fontsDirectory', __DIR__.'/../assets/fonts'); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | /** |
@@ -219,8 +219,8 @@ discard block |
||
| 219 | 219 | */ |
| 220 | 220 | protected function configure($config) |
| 221 | 221 | { |
| 222 | - if ($this->config->has('captcha.' . $config)) { |
|
| 223 | - foreach ($this->config->get('captcha.' . $config) as $key => $val) { |
|
| 222 | + if ($this->config->has('captcha.'.$config)) { |
|
| 223 | + foreach ($this->config->get('captcha.'.$config) as $key => $val) { |
|
| 224 | 224 | $this->{$key} = $val; |
| 225 | 225 | } |
| 226 | 226 | } |
@@ -236,11 +236,11 @@ discard block |
||
| 236 | 236 | */ |
| 237 | 237 | public function create(string $config = 'default', bool $api = false) |
| 238 | 238 | { |
| 239 | - $this->backgrounds = $this->files->files(__DIR__ . '/../assets/backgrounds'); |
|
| 239 | + $this->backgrounds = $this->files->files(__DIR__.'/../assets/backgrounds'); |
|
| 240 | 240 | $this->fonts = $this->files->files($this->fontsDirectory); |
| 241 | 241 | |
| 242 | 242 | if (version_compare(app()->version(), '5.5.0', '>=')) { |
| 243 | - $this->fonts = array_map(function ($file) { |
|
| 243 | + $this->fonts = array_map(function($file) { |
|
| 244 | 244 | /* @var File $file */ |
| 245 | 245 | return $file->getPathName(); |
| 246 | 246 | }, $this->fonts); |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | if ($api) { |
| 291 | - Cache::put('captcha_record_' . $generator['key'], $generator['value'], $this->expire); |
|
| 291 | + Cache::put('captcha_record_'.$generator['key'], $generator['value'], $this->expire); |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | return $api ? [ |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | foreach ($text as $key => $char) { |
| 365 | 365 | $marginLeft = $this->textLeftPadding + ($key * ($this->image->width() - $this->textLeftPadding) / $this->length); |
| 366 | 366 | |
| 367 | - $this->image->text($char, $marginLeft, $marginTop, function ($font) { |
|
| 367 | + $this->image->text($char, $marginLeft, $marginTop, function($font) { |
|
| 368 | 368 | /* @var Font $font */ |
| 369 | 369 | $font->file($this->font()); |
| 370 | 370 | $font->size($this->fontSize()); |
@@ -403,10 +403,10 @@ discard block |
||
| 403 | 403 | */ |
| 404 | 404 | protected function fontColor(): string |
| 405 | 405 | { |
| 406 | - if (!empty($this->fontColors)) { |
|
| 406 | + if ( ! empty($this->fontColors)) { |
|
| 407 | 407 | $color = $this->fontColors[rand(0, count($this->fontColors) - 1)]; |
| 408 | 408 | } else { |
| 409 | - $color = '#' . str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT); |
|
| 409 | + $color = '#'.str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT); |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | return $color; |
@@ -435,7 +435,7 @@ discard block |
||
| 435 | 435 | rand(0, $this->image->height()), |
| 436 | 436 | rand(0, $this->image->width()), |
| 437 | 437 | rand(0, $this->image->height()), |
| 438 | - function ($draw) { |
|
| 438 | + function($draw) { |
|
| 439 | 439 | /* @var Font $draw */ |
| 440 | 440 | $draw->color($this->fontColor()); |
| 441 | 441 | } |
@@ -453,14 +453,14 @@ discard block |
||
| 453 | 453 | */ |
| 454 | 454 | public function check(string $value): bool |
| 455 | 455 | { |
| 456 | - if (!$this->session->has('captcha')) { |
|
| 456 | + if ( ! $this->session->has('captcha')) { |
|
| 457 | 457 | return false; |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | $key = $this->session->get('captcha.key'); |
| 461 | 461 | $sensitive = $this->session->get('captcha.sensitive'); |
| 462 | 462 | |
| 463 | - if (!$sensitive) { |
|
| 463 | + if ( ! $sensitive) { |
|
| 464 | 464 | $value = $this->str->lower($value); |
| 465 | 465 | } |
| 466 | 466 | |
@@ -482,7 +482,7 @@ discard block |
||
| 482 | 482 | */ |
| 483 | 483 | public function check_api($value, $key): bool |
| 484 | 484 | { |
| 485 | - if (!Cache::pull('captcha_record_' . $key)) { |
|
| 485 | + if ( ! Cache::pull('captcha_record_'.$key)) { |
|
| 486 | 486 | return false; |
| 487 | 487 | } |
| 488 | 488 | |
@@ -497,7 +497,7 @@ discard block |
||
| 497 | 497 | */ |
| 498 | 498 | public function src(string $config = 'default'): string |
| 499 | 499 | { |
| 500 | - return url('captcha/' . $config) . '?' . $this->str->random(8); |
|
| 500 | + return url('captcha/'.$config).'?'.$this->str->random(8); |
|
| 501 | 501 | } |
| 502 | 502 | |
| 503 | 503 | /** |
@@ -517,8 +517,8 @@ discard block |
||
| 517 | 517 | continue; |
| 518 | 518 | } |
| 519 | 519 | |
| 520 | - $attrs_str .= $attr . '="' . $value . '" '; |
|
| 520 | + $attrs_str .= $attr.'="'.$value.'" '; |
|
| 521 | 521 | } |
| 522 | - return new HtmlString('<img src="' . $this->src($config) . '" ' . trim($attrs_str) . '>'); |
|
| 522 | + return new HtmlString('<img src="'.$this->src($config).'" '.trim($attrs_str).'>'); |
|
| 523 | 523 | } |
| 524 | 524 | } |