@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | $this->hasher = $hasher; |
217 | 217 | $this->str = $str; |
218 | 218 | $this->characters = config('captcha.characters', ['1', '2', '3', '4', '6', '7', '8', '9']); |
219 | - $this->fontsDirectory = config('captcha.fontsDirectory', dirname(__DIR__) . '/assets/fonts'); |
|
219 | + $this->fontsDirectory = config('captcha.fontsDirectory', dirname(__DIR__).'/assets/fonts'); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -225,8 +225,8 @@ discard block |
||
225 | 225 | */ |
226 | 226 | protected function configure($config) |
227 | 227 | { |
228 | - if ($this->config->has('captcha.' . $config)) { |
|
229 | - foreach ($this->config->get('captcha.' . $config) as $key => $val) { |
|
228 | + if ($this->config->has('captcha.'.$config)) { |
|
229 | + foreach ($this->config->get('captcha.'.$config) as $key => $val) { |
|
230 | 230 | $this->{$key} = $val; |
231 | 231 | } |
232 | 232 | } |
@@ -242,11 +242,11 @@ discard block |
||
242 | 242 | */ |
243 | 243 | public function create(string $config = 'default', bool $api = false) |
244 | 244 | { |
245 | - $this->backgrounds = $this->files->files(__DIR__ . '/../assets/backgrounds'); |
|
245 | + $this->backgrounds = $this->files->files(__DIR__.'/../assets/backgrounds'); |
|
246 | 246 | $this->fonts = $this->files->files($this->fontsDirectory); |
247 | 247 | |
248 | 248 | if (version_compare(app()->version(), '5.5.0', '>=')) { |
249 | - $this->fonts = array_map(function ($file) { |
|
249 | + $this->fonts = array_map(function($file) { |
|
250 | 250 | /* @var File $file */ |
251 | 251 | return $file->getPathName(); |
252 | 252 | }, $this->fonts); |
@@ -341,7 +341,7 @@ 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) $hash = Crypt::encrypt($hash); |
|
345 | 345 | |
346 | 346 | $this->session->put('captcha', [ |
347 | 347 | 'sensitive' => $this->sensitive, |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | foreach ($text as $key => $char) { |
374 | 374 | $marginLeft = $this->textLeftPadding + ($key * ($this->image->width() - $this->textLeftPadding) / $this->length); |
375 | 375 | |
376 | - $this->image->text($char, $marginLeft, $marginTop, function ($font) { |
|
376 | + $this->image->text($char, $marginLeft, $marginTop, function($font) { |
|
377 | 377 | /* @var Font $font */ |
378 | 378 | $font->file($this->font()); |
379 | 379 | $font->size($this->fontSize()); |
@@ -412,10 +412,10 @@ discard block |
||
412 | 412 | */ |
413 | 413 | protected function fontColor(): string |
414 | 414 | { |
415 | - if (!empty($this->fontColors)) { |
|
415 | + if ( ! empty($this->fontColors)) { |
|
416 | 416 | $color = $this->fontColors[rand(0, count($this->fontColors) - 1)]; |
417 | 417 | } else { |
418 | - $color = '#' . str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT); |
|
418 | + $color = '#'.str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT); |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | return $color; |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | rand(0, $this->image->height()), |
445 | 445 | rand(0, $this->image->width()), |
446 | 446 | rand(0, $this->image->height()), |
447 | - function ($draw) { |
|
447 | + function($draw) { |
|
448 | 448 | /* @var Font $draw */ |
449 | 449 | $draw->color($this->fontColor()); |
450 | 450 | } |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | */ |
463 | 463 | public function check(string $value): bool |
464 | 464 | { |
465 | - if (!$this->session->has('captcha')) { |
|
465 | + if ( ! $this->session->has('captcha')) { |
|
466 | 466 | return false; |
467 | 467 | } |
468 | 468 | |
@@ -470,11 +470,11 @@ discard block |
||
470 | 470 | $sensitive = $this->session->get('captcha.sensitive'); |
471 | 471 | $encrypt = $this->session->get('captcha.encrypt'); |
472 | 472 | |
473 | - if (!$sensitive) { |
|
473 | + if ( ! $sensitive) { |
|
474 | 474 | $value = $this->str->lower($value); |
475 | 475 | } |
476 | 476 | |
477 | - if($encrypt) $key = Crypt::decrypt($key); |
|
477 | + if ($encrypt) $key = Crypt::decrypt($key); |
|
478 | 478 | $check = $this->hasher->check($value, $key); |
479 | 479 | // if verify pass,remove session |
480 | 480 | if ($check) { |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | * @return string |
492 | 492 | */ |
493 | 493 | protected function get_cache_key($key) { |
494 | - return 'captcha_' . md5($key); |
|
494 | + return 'captcha_'.md5($key); |
|
495 | 495 | } |
496 | 496 | |
497 | 497 | /** |
@@ -504,14 +504,14 @@ discard block |
||
504 | 504 | */ |
505 | 505 | public function check_api($value, $key, $config = 'default'): bool |
506 | 506 | { |
507 | - if (!Cache::pull($this->get_cache_key($key))) { |
|
507 | + if ( ! Cache::pull($this->get_cache_key($key))) { |
|
508 | 508 | return false; |
509 | 509 | } |
510 | 510 | |
511 | 511 | $this->configure($config); |
512 | 512 | |
513 | - if(!$this->sensitive) $value = $this->str->lower($value); |
|
514 | - if($this->encrypt) $key = Crypt::decrypt($key); |
|
513 | + if ( ! $this->sensitive) $value = $this->str->lower($value); |
|
514 | + if ($this->encrypt) $key = Crypt::decrypt($key); |
|
515 | 515 | return $this->hasher->check($value, $key); |
516 | 516 | } |
517 | 517 | |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | */ |
524 | 524 | public function src(string $config = 'default'): string |
525 | 525 | { |
526 | - return url('captcha/' . $config) . '?' . $this->str->random(8); |
|
526 | + return url('captcha/'.$config).'?'.$this->str->random(8); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | /** |
@@ -543,8 +543,8 @@ discard block |
||
543 | 543 | continue; |
544 | 544 | } |
545 | 545 | |
546 | - $attrs_str .= $attr . '="' . $value . '" '; |
|
546 | + $attrs_str .= $attr.'="'.$value.'" '; |
|
547 | 547 | } |
548 | - return new HtmlString('<img src="' . $this->src($config) . '" ' . trim($attrs_str) . '>'); |
|
548 | + return new HtmlString('<img src="'.$this->src($config).'" '.trim($attrs_str).'>'); |
|
549 | 549 | } |
550 | 550 | } |