@@ -6,8 +6,8 @@ |
||
| 6 | 6 | 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', |
| 7 | 7 | 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', |
| 8 | 8 | 't', 'u', 'v', 'w', 'x', 'y', 'z', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], |
| 9 | - 'fontsDirectory' => dirname(__DIR__) . '/assets/fonts', |
|
| 10 | - 'bgsDirectory' => dirname(__DIR__) . '/assets/backgrounds', |
|
| 9 | + 'fontsDirectory' => dirname(__DIR__).'/assets/fonts', |
|
| 10 | + 'bgsDirectory' => dirname(__DIR__).'/assets/backgrounds', |
|
| 11 | 11 | 'default' => [ |
| 12 | 12 | 'length' => 6, |
| 13 | 13 | 'width' => 345, |
@@ -158,8 +158,8 @@ |
||
| 158 | 158 | protected $blur = 0; |
| 159 | 159 | |
| 160 | 160 | /** |
| 161 | - * @var string |
|
| 162 | - */ |
|
| 161 | + * @var string |
|
| 162 | + */ |
|
| 163 | 163 | protected $bgsDirectory; |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -239,8 +239,8 @@ discard block |
||
| 239 | 239 | $this->hasher = $hasher; |
| 240 | 240 | $this->str = $str; |
| 241 | 241 | $this->characters = config('captcha.characters', ['1', '2', '3', '4', '6', '7', '8', '9']); |
| 242 | - $this->fontsDirectory = config('captcha.fontsDirectory', dirname(__DIR__) . '/assets/fonts'); |
|
| 243 | - $this->bgsDirectory = config('captcha.bgsDirectory', dirname(__DIR__) . '/assets/backgrounds'); |
|
| 242 | + $this->fontsDirectory = config('captcha.fontsDirectory', dirname(__DIR__).'/assets/fonts'); |
|
| 243 | + $this->bgsDirectory = config('captcha.bgsDirectory', dirname(__DIR__).'/assets/backgrounds'); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | /** |
@@ -249,8 +249,8 @@ discard block |
||
| 249 | 249 | */ |
| 250 | 250 | protected function configure($config) |
| 251 | 251 | { |
| 252 | - if ($this->config->has('captcha.' . $config)) { |
|
| 253 | - foreach ($this->config->get('captcha.' . $config) as $key => $val) { |
|
| 252 | + if ($this->config->has('captcha.'.$config)) { |
|
| 253 | + foreach ($this->config->get('captcha.'.$config) as $key => $val) { |
|
| 254 | 254 | $this->{$key} = $val; |
| 255 | 255 | } |
| 256 | 256 | } |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | $this->fonts = $this->files->files($this->fontsDirectory); |
| 271 | 271 | |
| 272 | 272 | if (version_compare(app()->version(), '5.5.0', '>=')) { |
| 273 | - $this->fonts = array_map(function ($file) { |
|
| 273 | + $this->fonts = array_map(function($file) { |
|
| 274 | 274 | /* @var File $file */ |
| 275 | 275 | return $file->getPathName(); |
| 276 | 276 | }, $this->fonts); |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | $generator = $this->generate(); |
| 284 | 284 | $this->text = $generator['value']; |
| 285 | 285 | |
| 286 | - $this->canvas = $this->imageManager->create($this->width , $this->height)->fill($this->bgColor); |
|
| 286 | + $this->canvas = $this->imageManager->create($this->width, $this->height)->fill($this->bgColor); |
|
| 287 | 287 | |
| 288 | 288 | if ($this->bgImage) { |
| 289 | 289 | $this->image = $this->imageManager->read($this->background())->resize( |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | $hash = $this->hasher->make($key); |
| 365 | - if($this->encrypt) $hash = Crypt::encrypt($hash); |
|
| 365 | + if ($this->encrypt) $hash = Crypt::encrypt($hash); |
|
| 366 | 366 | |
| 367 | 367 | $this->session->put('captcha', [ |
| 368 | 368 | 'sensitive' => $this->sensitive, |
@@ -397,7 +397,7 @@ discard block |
||
| 397 | 397 | foreach ($text as $key => $char) { |
| 398 | 398 | $marginLeft = $this->textLeftPadding + ($key * ($this->image->width() - $this->textLeftPadding) / $this->length); |
| 399 | 399 | |
| 400 | - $this->image->text($char, $marginLeft, $marginTop, function ($font) { |
|
| 400 | + $this->image->text($char, $marginLeft, $marginTop, function($font) { |
|
| 401 | 401 | /* @var Font $font */ |
| 402 | 402 | $font->file($this->font()); |
| 403 | 403 | $font->size($this->fontSize()); |
@@ -436,10 +436,10 @@ discard block |
||
| 436 | 436 | */ |
| 437 | 437 | protected function fontColor(): string |
| 438 | 438 | { |
| 439 | - if (!empty($this->fontColors)) { |
|
| 439 | + if ( ! empty($this->fontColors)) { |
|
| 440 | 440 | $color = $this->fontColors[rand(0, count($this->fontColors) - 1)]; |
| 441 | 441 | } else { |
| 442 | - $color = '#' . str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT); |
|
| 442 | + $color = '#'.str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT); |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | return $color; |
@@ -463,9 +463,9 @@ discard block |
||
| 463 | 463 | protected function lines() |
| 464 | 464 | { |
| 465 | 465 | for ($i = 0; $i <= $this->lines; $i++) { |
| 466 | - $this->image->drawLine(function (LineFactory $line) use ($i) { |
|
| 467 | - $line->from(rand(0, $this->image->width()) + $i * rand(0, $this->image->height()) , rand(0, $this->image->height())); |
|
| 468 | - $line->to( rand(0, $this->image->width()), rand(0, $this->image->height())); |
|
| 466 | + $this->image->drawLine(function(LineFactory $line) use ($i) { |
|
| 467 | + $line->from(rand(0, $this->image->width()) + $i * rand(0, $this->image->height()), rand(0, $this->image->height())); |
|
| 468 | + $line->to(rand(0, $this->image->width()), rand(0, $this->image->height())); |
|
| 469 | 469 | $line->color($this->lineColor); // color of line |
| 470 | 470 | $line->width($this->lineWidth); // line width in pixels |
| 471 | 471 | }); |
@@ -482,7 +482,7 @@ discard block |
||
| 482 | 482 | */ |
| 483 | 483 | public function check(string $value): bool |
| 484 | 484 | { |
| 485 | - if (!$this->session->has('captcha')) { |
|
| 485 | + if ( ! $this->session->has('captcha')) { |
|
| 486 | 486 | return false; |
| 487 | 487 | } |
| 488 | 488 | |
@@ -490,16 +490,16 @@ discard block |
||
| 490 | 490 | $sensitive = $this->session->get('captcha.sensitive'); |
| 491 | 491 | $encrypt = $this->session->get('captcha.encrypt'); |
| 492 | 492 | |
| 493 | - if (!Cache::pull($this->get_cache_key($key))) { |
|
| 493 | + if ( ! Cache::pull($this->get_cache_key($key))) { |
|
| 494 | 494 | $this->session->remove('captcha'); |
| 495 | 495 | return false; |
| 496 | 496 | } |
| 497 | 497 | |
| 498 | - if (!$sensitive) { |
|
| 498 | + if ( ! $sensitive) { |
|
| 499 | 499 | $value = $this->str->lower($value); |
| 500 | 500 | } |
| 501 | 501 | |
| 502 | - if($encrypt) $key = Crypt::decrypt($key); |
|
| 502 | + if ($encrypt) $key = Crypt::decrypt($key); |
|
| 503 | 503 | $check = $this->hasher->check($value, $key); |
| 504 | 504 | // if verify pass,remove session |
| 505 | 505 | if ($check) { |
@@ -516,7 +516,7 @@ discard block |
||
| 516 | 516 | * @return string |
| 517 | 517 | */ |
| 518 | 518 | protected function get_cache_key($key) { |
| 519 | - return 'captcha_' . md5($key); |
|
| 519 | + return 'captcha_'.md5($key); |
|
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | /** |
@@ -529,14 +529,14 @@ discard block |
||
| 529 | 529 | */ |
| 530 | 530 | public function check_api($value, $key, $config = 'default'): bool |
| 531 | 531 | { |
| 532 | - if (!Cache::pull($this->get_cache_key($key))) { |
|
| 532 | + if ( ! Cache::pull($this->get_cache_key($key))) { |
|
| 533 | 533 | return false; |
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | $this->configure($config); |
| 537 | 537 | |
| 538 | - if(!$this->sensitive) $value = $this->str->lower($value); |
|
| 539 | - if($this->encrypt) $key = Crypt::decrypt($key); |
|
| 538 | + if ( ! $this->sensitive) $value = $this->str->lower($value); |
|
| 539 | + if ($this->encrypt) $key = Crypt::decrypt($key); |
|
| 540 | 540 | return $this->hasher->check($value, $key); |
| 541 | 541 | } |
| 542 | 542 | |
@@ -548,7 +548,7 @@ discard block |
||
| 548 | 548 | */ |
| 549 | 549 | public function src(string $config = 'default'): string |
| 550 | 550 | { |
| 551 | - return url('captcha/' . $config) . '?' . $this->str->random(8); |
|
| 551 | + return url('captcha/'.$config).'?'.$this->str->random(8); |
|
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | /** |
@@ -568,8 +568,8 @@ discard block |
||
| 568 | 568 | continue; |
| 569 | 569 | } |
| 570 | 570 | |
| 571 | - $attrs_str .= $attr . '="' . $value . '" '; |
|
| 571 | + $attrs_str .= $attr.'="'.$value.'" '; |
|
| 572 | 572 | } |
| 573 | - return new HtmlString('<img src="' . $this->src($config) . '" ' . trim($attrs_str) . '>'); |
|
| 573 | + return new HtmlString('<img src="'.$this->src($config).'" '.trim($attrs_str).'>'); |
|
| 574 | 574 | } |
| 575 | 575 | } |