@@ -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); |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | } |
347 | 347 | |
348 | 348 | $hash = $this->hasher->make($key); |
349 | - if($this->encrypt) $hash = Crypt::encrypt($hash); |
|
349 | + if ($this->encrypt) $hash = Crypt::encrypt($hash); |
|
350 | 350 | |
351 | 351 | $this->session->put('captcha', [ |
352 | 352 | 'sensitive' => $this->sensitive, |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | foreach ($text as $key => $char) { |
382 | 382 | $marginLeft = $this->textLeftPadding + ($key * ($this->image->width() - $this->textLeftPadding) / $this->length); |
383 | 383 | |
384 | - $this->image->text($char, $marginLeft, $marginTop, function ($font) { |
|
384 | + $this->image->text($char, $marginLeft, $marginTop, function($font) { |
|
385 | 385 | /* @var Font $font */ |
386 | 386 | $font->file($this->font()); |
387 | 387 | $font->size($this->fontSize()); |
@@ -420,10 +420,10 @@ discard block |
||
420 | 420 | */ |
421 | 421 | protected function fontColor(): string |
422 | 422 | { |
423 | - if (!empty($this->fontColors)) { |
|
423 | + if ( ! empty($this->fontColors)) { |
|
424 | 424 | $color = $this->fontColors[rand(0, count($this->fontColors) - 1)]; |
425 | 425 | } else { |
426 | - $color = '#' . str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT); |
|
426 | + $color = '#'.str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT); |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | return $color; |
@@ -452,7 +452,7 @@ discard block |
||
452 | 452 | rand(0, $this->image->height()), |
453 | 453 | rand(0, $this->image->width()), |
454 | 454 | rand(0, $this->image->height()), |
455 | - function ($draw) { |
|
455 | + function($draw) { |
|
456 | 456 | /* @var Font $draw */ |
457 | 457 | $draw->color($this->fontColor()); |
458 | 458 | } |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | */ |
471 | 471 | public function check(string $value): bool |
472 | 472 | { |
473 | - if (!$this->session->has('captcha')) { |
|
473 | + if ( ! $this->session->has('captcha')) { |
|
474 | 474 | return false; |
475 | 475 | } |
476 | 476 | |
@@ -478,11 +478,11 @@ discard block |
||
478 | 478 | $sensitive = $this->session->get('captcha.sensitive'); |
479 | 479 | $encrypt = $this->session->get('captcha.encrypt'); |
480 | 480 | |
481 | - if (!$sensitive) { |
|
481 | + if ( ! $sensitive) { |
|
482 | 482 | $value = $this->str->lower($value); |
483 | 483 | } |
484 | 484 | |
485 | - if($encrypt) $key = Crypt::decrypt($key); |
|
485 | + if ($encrypt) $key = Crypt::decrypt($key); |
|
486 | 486 | $check = $this->hasher->check($value, $key); |
487 | 487 | // if verify pass,remove session |
488 | 488 | if ($check) { |
@@ -499,7 +499,7 @@ discard block |
||
499 | 499 | * @return string |
500 | 500 | */ |
501 | 501 | protected function get_cache_key($key) { |
502 | - return 'captcha_' . md5($key); |
|
502 | + return 'captcha_'.md5($key); |
|
503 | 503 | } |
504 | 504 | |
505 | 505 | /** |
@@ -512,14 +512,14 @@ discard block |
||
512 | 512 | */ |
513 | 513 | public function check_api($value, $key, $config = 'default'): bool |
514 | 514 | { |
515 | - if (!Cache::pull($this->get_cache_key($key))) { |
|
515 | + if ( ! Cache::pull($this->get_cache_key($key))) { |
|
516 | 516 | return false; |
517 | 517 | } |
518 | 518 | |
519 | 519 | $this->configure($config); |
520 | 520 | |
521 | - if(!$this->sensitive) $value = $this->str->lower($value); |
|
522 | - if($this->encrypt) $key = Crypt::decrypt($key); |
|
521 | + if ( ! $this->sensitive) $value = $this->str->lower($value); |
|
522 | + if ($this->encrypt) $key = Crypt::decrypt($key); |
|
523 | 523 | return $this->hasher->check($value, $key); |
524 | 524 | } |
525 | 525 | |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | */ |
532 | 532 | public function src(string $config = 'default'): string |
533 | 533 | { |
534 | - return url('captcha/' . $config) . '?' . $this->str->random(8); |
|
534 | + return url('captcha/'.$config).'?'.$this->str->random(8); |
|
535 | 535 | } |
536 | 536 | |
537 | 537 | /** |
@@ -551,8 +551,8 @@ discard block |
||
551 | 551 | continue; |
552 | 552 | } |
553 | 553 | |
554 | - $attrs_str .= $attr . '="' . $value . '" '; |
|
554 | + $attrs_str .= $attr.'="'.$value.'" '; |
|
555 | 555 | } |
556 | - return new HtmlString('<img src="' . $this->src($config) . '" ' . trim($attrs_str) . '>'); |
|
556 | + return new HtmlString('<img src="'.$this->src($config).'" '.trim($attrs_str).'>'); |
|
557 | 557 | } |
558 | 558 | } |