@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | $this->hasher = $hasher; |
231 | 231 | $this->str = $str; |
232 | 232 | $this->characters = config('captcha.characters', ['1', '2', '3', '4', '6', '7', '8', '9']); |
233 | - $this->fontsDirectory = config('captcha.fontsDirectory', dirname(__DIR__) . '/assets/fonts'); |
|
233 | + $this->fontsDirectory = config('captcha.fontsDirectory', dirname(__DIR__).'/assets/fonts'); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
@@ -239,8 +239,8 @@ discard block |
||
239 | 239 | */ |
240 | 240 | protected function configure($config) |
241 | 241 | { |
242 | - if ($this->config->has('captcha.' . $config)) { |
|
243 | - foreach ($this->config->get('captcha.' . $config) as $key => $val) { |
|
242 | + if ($this->config->has('captcha.'.$config)) { |
|
243 | + foreach ($this->config->get('captcha.'.$config) as $key => $val) { |
|
244 | 244 | $this->{$key} = $val; |
245 | 245 | } |
246 | 246 | } |
@@ -256,11 +256,11 @@ discard block |
||
256 | 256 | */ |
257 | 257 | public function create(string $config = 'default', bool $api = false) |
258 | 258 | { |
259 | - $this->backgrounds = $this->files->files(__DIR__ . '/../assets/backgrounds'); |
|
259 | + $this->backgrounds = $this->files->files(__DIR__.'/../assets/backgrounds'); |
|
260 | 260 | $this->fonts = $this->files->files($this->fontsDirectory); |
261 | 261 | |
262 | 262 | if (version_compare(app()->version(), '5.5.0', '>=')) { |
263 | - $this->fonts = array_map(function ($file) { |
|
263 | + $this->fonts = array_map(function($file) { |
|
264 | 264 | /* @var File $file */ |
265 | 265 | return $file->getPathName(); |
266 | 266 | }, $this->fonts); |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | $generator = $this->generate(); |
274 | 274 | $this->text = $generator['value']; |
275 | 275 | |
276 | - $this->canvas = $this->imageManager->create($this->width , $this->height)->fill($this->fill); |
|
276 | + $this->canvas = $this->imageManager->create($this->width, $this->height)->fill($this->fill); |
|
277 | 277 | |
278 | 278 | |
279 | 279 | if ($this->bgImage) { |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | } |
354 | 354 | |
355 | 355 | $hash = $this->hasher->make($key); |
356 | - if($this->encrypt) $hash = Crypt::encrypt($hash); |
|
356 | + if ($this->encrypt) $hash = Crypt::encrypt($hash); |
|
357 | 357 | |
358 | 358 | $this->session->put('captcha', [ |
359 | 359 | 'sensitive' => $this->sensitive, |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | foreach ($text as $key => $char) { |
389 | 389 | $marginLeft = $this->textLeftPadding + ($key * ($this->image->width() - $this->textLeftPadding) / $this->length); |
390 | 390 | |
391 | - $this->image->text($char, $marginLeft, $marginTop, function ($font) { |
|
391 | + $this->image->text($char, $marginLeft, $marginTop, function($font) { |
|
392 | 392 | /* @var Font $font */ |
393 | 393 | $font->file($this->font()); |
394 | 394 | $font->size($this->fontSize()); |
@@ -427,10 +427,10 @@ discard block |
||
427 | 427 | */ |
428 | 428 | protected function fontColor(): string |
429 | 429 | { |
430 | - if (!empty($this->fontColors)) { |
|
430 | + if ( ! empty($this->fontColors)) { |
|
431 | 431 | $color = $this->fontColors[rand(0, count($this->fontColors) - 1)]; |
432 | 432 | } else { |
433 | - $color = '#' . str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT); |
|
433 | + $color = '#'.str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | return $color; |
@@ -454,9 +454,9 @@ discard block |
||
454 | 454 | protected function lines() |
455 | 455 | { |
456 | 456 | for ($i = 0; $i <= $this->lines; $i++) { |
457 | - $this->image->drawLine(function (LineFactory $line) use ($i) { |
|
458 | - $line->from(rand(0, $this->image->width()) + $i * rand(0, $this->image->height()) , rand(0, $this->image->height())); |
|
459 | - $line->to( rand(0, $this->image->width()), rand(0, $this->image->height())); |
|
457 | + $this->image->drawLine(function(LineFactory $line) use ($i) { |
|
458 | + $line->from(rand(0, $this->image->width()) + $i * rand(0, $this->image->height()), rand(0, $this->image->height())); |
|
459 | + $line->to(rand(0, $this->image->width()), rand(0, $this->image->height())); |
|
460 | 460 | $line->color('ff00ff'); // color of line |
461 | 461 | $line->width(5); // line width in pixels |
462 | 462 | }); |
@@ -473,7 +473,7 @@ discard block |
||
473 | 473 | */ |
474 | 474 | public function check(string $value): bool |
475 | 475 | { |
476 | - if (!$this->session->has('captcha')) { |
|
476 | + if ( ! $this->session->has('captcha')) { |
|
477 | 477 | return false; |
478 | 478 | } |
479 | 479 | |
@@ -481,16 +481,16 @@ discard block |
||
481 | 481 | $sensitive = $this->session->get('captcha.sensitive'); |
482 | 482 | $encrypt = $this->session->get('captcha.encrypt'); |
483 | 483 | |
484 | - if (!Cache::pull($this->get_cache_key($key))) { |
|
484 | + if ( ! Cache::pull($this->get_cache_key($key))) { |
|
485 | 485 | $this->session->remove('captcha'); |
486 | 486 | return false; |
487 | 487 | } |
488 | 488 | |
489 | - if (!$sensitive) { |
|
489 | + if ( ! $sensitive) { |
|
490 | 490 | $value = $this->str->lower($value); |
491 | 491 | } |
492 | 492 | |
493 | - if($encrypt) $key = Crypt::decrypt($key); |
|
493 | + if ($encrypt) $key = Crypt::decrypt($key); |
|
494 | 494 | $check = $this->hasher->check($value, $key); |
495 | 495 | // if verify pass,remove session |
496 | 496 | if ($check) { |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | * @return string |
508 | 508 | */ |
509 | 509 | protected function get_cache_key($key) { |
510 | - return 'captcha_' . md5($key); |
|
510 | + return 'captcha_'.md5($key); |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | /** |
@@ -520,14 +520,14 @@ discard block |
||
520 | 520 | */ |
521 | 521 | public function check_api($value, $key, $config = 'default'): bool |
522 | 522 | { |
523 | - if (!Cache::pull($this->get_cache_key($key))) { |
|
523 | + if ( ! Cache::pull($this->get_cache_key($key))) { |
|
524 | 524 | return false; |
525 | 525 | } |
526 | 526 | |
527 | 527 | $this->configure($config); |
528 | 528 | |
529 | - if(!$this->sensitive) $value = $this->str->lower($value); |
|
530 | - if($this->encrypt) $key = Crypt::decrypt($key); |
|
529 | + if ( ! $this->sensitive) $value = $this->str->lower($value); |
|
530 | + if ($this->encrypt) $key = Crypt::decrypt($key); |
|
531 | 531 | return $this->hasher->check($value, $key); |
532 | 532 | } |
533 | 533 | |
@@ -539,7 +539,7 @@ discard block |
||
539 | 539 | */ |
540 | 540 | public function src(string $config = 'default'): string |
541 | 541 | { |
542 | - return url('captcha/' . $config) . '?' . $this->str->random(8); |
|
542 | + return url('captcha/'.$config).'?'.$this->str->random(8); |
|
543 | 543 | } |
544 | 544 | |
545 | 545 | /** |
@@ -559,8 +559,8 @@ discard block |
||
559 | 559 | continue; |
560 | 560 | } |
561 | 561 | |
562 | - $attrs_str .= $attr . '="' . $value . '" '; |
|
562 | + $attrs_str .= $attr.'="'.$value.'" '; |
|
563 | 563 | } |
564 | - return new HtmlString('<img src="' . $this->src($config) . '" ' . trim($attrs_str) . '>'); |
|
564 | + return new HtmlString('<img src="'.$this->src($config).'" '.trim($attrs_str).'>'); |
|
565 | 565 | } |
566 | 566 | } |