@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | $this->hasher = $hasher; |
| 222 | 222 | $this->str = $str; |
| 223 | 223 | $this->characters = config('captcha.characters', ['1', '2', '3', '4', '6', '7', '8', '9']); |
| 224 | - $this->fontsDirectory = config('captcha.fontsDirectory', dirname(__DIR__) . '/assets/fonts'); |
|
| 224 | + $this->fontsDirectory = config('captcha.fontsDirectory', dirname(__DIR__).'/assets/fonts'); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | /** |
@@ -230,8 +230,8 @@ discard block |
||
| 230 | 230 | */ |
| 231 | 231 | protected function configure($config) |
| 232 | 232 | { |
| 233 | - if ($this->config->has('captcha.' . $config)) { |
|
| 234 | - foreach ($this->config->get('captcha.' . $config) as $key => $val) { |
|
| 233 | + if ($this->config->has('captcha.'.$config)) { |
|
| 234 | + foreach ($this->config->get('captcha.'.$config) as $key => $val) { |
|
| 235 | 235 | $this->{$key} = $val; |
| 236 | 236 | } |
| 237 | 237 | } |
@@ -247,11 +247,11 @@ discard block |
||
| 247 | 247 | */ |
| 248 | 248 | public function create(string $config = 'default', bool $api = false) |
| 249 | 249 | { |
| 250 | - $this->backgrounds = $this->files->files(__DIR__ . '/../assets/backgrounds'); |
|
| 250 | + $this->backgrounds = $this->files->files(__DIR__.'/../assets/backgrounds'); |
|
| 251 | 251 | $this->fonts = $this->files->files($this->fontsDirectory); |
| 252 | 252 | |
| 253 | 253 | if (version_compare(app()->version(), '5.5.0', '>=')) { |
| 254 | - $this->fonts = array_map(function ($file) { |
|
| 254 | + $this->fonts = array_map(function($file) { |
|
| 255 | 255 | /* @var File $file */ |
| 256 | 256 | return $file->getPathName(); |
| 257 | 257 | }, $this->fonts); |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | $hash = $this->hasher->make($key); |
| 347 | - if($this->encrypt) $hash = Crypt::encrypt($hash); |
|
| 347 | + if ($this->encrypt) $hash = Crypt::encrypt($hash); |
|
| 348 | 348 | |
| 349 | 349 | $this->session->put('captcha', [ |
| 350 | 350 | 'sensitive' => $this->sensitive, |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | foreach ($text as $key => $char) { |
| 380 | 380 | $marginLeft = $this->textLeftPadding + ($key * ($this->image->width() - $this->textLeftPadding) / $this->length); |
| 381 | 381 | |
| 382 | - $this->image->text($char, $marginLeft, $marginTop, function ($font) { |
|
| 382 | + $this->image->text($char, $marginLeft, $marginTop, function($font) { |
|
| 383 | 383 | /* @var Font $font */ |
| 384 | 384 | $font->file($this->font()); |
| 385 | 385 | $font->size($this->fontSize()); |
@@ -418,10 +418,10 @@ discard block |
||
| 418 | 418 | */ |
| 419 | 419 | protected function fontColor(): string |
| 420 | 420 | { |
| 421 | - if (!empty($this->fontColors)) { |
|
| 421 | + if ( ! empty($this->fontColors)) { |
|
| 422 | 422 | $color = $this->fontColors[rand(0, count($this->fontColors) - 1)]; |
| 423 | 423 | } else { |
| 424 | - $color = '#' . str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT); |
|
| 424 | + $color = '#'.str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT); |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | return $color; |
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | rand(0, $this->image->height()), |
| 451 | 451 | rand(0, $this->image->width()), |
| 452 | 452 | rand(0, $this->image->height()), |
| 453 | - function ($draw) { |
|
| 453 | + function($draw) { |
|
| 454 | 454 | /* @var Font $draw */ |
| 455 | 455 | $draw->color($this->fontColor()); |
| 456 | 456 | } |
@@ -468,7 +468,7 @@ discard block |
||
| 468 | 468 | */ |
| 469 | 469 | public function check(string $value): bool |
| 470 | 470 | { |
| 471 | - if (!$this->session->has('captcha')) { |
|
| 471 | + if ( ! $this->session->has('captcha')) { |
|
| 472 | 472 | return false; |
| 473 | 473 | } |
| 474 | 474 | |
@@ -476,16 +476,16 @@ discard block |
||
| 476 | 476 | $sensitive = $this->session->get('captcha.sensitive'); |
| 477 | 477 | $encrypt = $this->session->get('captcha.encrypt'); |
| 478 | 478 | |
| 479 | - if (!Cache::pull($this->get_cache_key($key))) { |
|
| 479 | + if ( ! Cache::pull($this->get_cache_key($key))) { |
|
| 480 | 480 | $this->session->remove('captcha'); |
| 481 | 481 | return false; |
| 482 | 482 | } |
| 483 | 483 | |
| 484 | - if (!$sensitive) { |
|
| 484 | + if ( ! $sensitive) { |
|
| 485 | 485 | $value = $this->str->lower($value); |
| 486 | 486 | } |
| 487 | 487 | |
| 488 | - if($encrypt) $key = Crypt::decrypt($key); |
|
| 488 | + if ($encrypt) $key = Crypt::decrypt($key); |
|
| 489 | 489 | $check = $this->hasher->check($value, $key); |
| 490 | 490 | // if verify pass,remove session |
| 491 | 491 | if ($check) { |
@@ -502,7 +502,7 @@ discard block |
||
| 502 | 502 | * @return string |
| 503 | 503 | */ |
| 504 | 504 | protected function get_cache_key($key) { |
| 505 | - return 'captcha_' . md5($key); |
|
| 505 | + return 'captcha_'.md5($key); |
|
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | /** |
@@ -515,14 +515,14 @@ discard block |
||
| 515 | 515 | */ |
| 516 | 516 | public function check_api($value, $key, $config = 'default'): bool |
| 517 | 517 | { |
| 518 | - if (!Cache::pull($this->get_cache_key($key))) { |
|
| 518 | + if ( ! Cache::pull($this->get_cache_key($key))) { |
|
| 519 | 519 | return false; |
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | $this->configure($config); |
| 523 | 523 | |
| 524 | - if(!$this->sensitive) $value = $this->str->lower($value); |
|
| 525 | - if($this->encrypt) $key = Crypt::decrypt($key); |
|
| 524 | + if ( ! $this->sensitive) $value = $this->str->lower($value); |
|
| 525 | + if ($this->encrypt) $key = Crypt::decrypt($key); |
|
| 526 | 526 | return $this->hasher->check($value, $key); |
| 527 | 527 | } |
| 528 | 528 | |
@@ -534,7 +534,7 @@ discard block |
||
| 534 | 534 | */ |
| 535 | 535 | public function src(string $config = 'default'): string |
| 536 | 536 | { |
| 537 | - return url('captcha/' . $config) . '?' . $this->str->random(8); |
|
| 537 | + return url('captcha/'.$config).'?'.$this->str->random(8); |
|
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | /** |
@@ -554,8 +554,8 @@ discard block |
||
| 554 | 554 | continue; |
| 555 | 555 | } |
| 556 | 556 | |
| 557 | - $attrs_str .= $attr . '="' . $value . '" '; |
|
| 557 | + $attrs_str .= $attr.'="'.$value.'" '; |
|
| 558 | 558 | } |
| 559 | - return new HtmlString('<img src="' . $this->src($config) . '" ' . trim($attrs_str) . '>'); |
|
| 559 | + return new HtmlString('<img src="'.$this->src($config).'" '.trim($attrs_str).'>'); |
|
| 560 | 560 | } |
| 561 | 561 | } |