@@ -22,11 +22,11 @@ discard block  | 
                                                    ||
| 22 | 22 |      { | 
                                                        
| 23 | 23 | // Publish configuration files  | 
                                                        
| 24 | 24 | $this->publishes([  | 
                                                        
| 25 | -            __DIR__ . '/../config/captcha.php' => config_path('captcha.php') | 
                                                        |
| 25 | +            __DIR__.'/../config/captcha.php' => config_path('captcha.php') | 
                                                        |
| 26 | 26 | ], 'config');  | 
                                                        
| 27 | 27 | |
| 28 | 28 | // HTTP routing  | 
                                                        
| 29 | -        if (!config('captcha.disable')) { | 
                                                        |
| 29 | +        if ( ! config('captcha.disable')) { | 
                                                        |
| 30 | 30 |              if (strpos($this->app->version(), 'Lumen') !== false) { | 
                                                        
| 31 | 31 | /* @var Router $router */  | 
                                                        
| 32 | 32 | $router = $this->app;  | 
                                                        
@@ -35,7 +35,7 @@ discard block  | 
                                                    ||
| 35 | 35 |              } else { | 
                                                        
| 36 | 36 | /* @var Router $router */  | 
                                                        
| 37 | 37 | $router = $this->app['router'];  | 
                                                        
| 38 | -                if ((float)$this->app->version() >= 5.2) { | 
                                                        |
| 38 | +                if ((float) $this->app->version() >= 5.2) { | 
                                                        |
| 39 | 39 |                      $router->get('captcha/api/{config?}', '\Mews\Captcha\CaptchaController@getCaptchaApi')->middleware('web'); | 
                                                        
| 40 | 40 |                      $router->get('captcha/{config?}', '\Mews\Captcha\CaptchaController@getCaptcha')->middleware('web'); | 
                                                        
| 41 | 41 |                  } else { | 
                                                        
@@ -49,12 +49,12 @@ discard block  | 
                                                    ||
| 49 | 49 | $validator = $this->app['validator'];  | 
                                                        
| 50 | 50 | |
| 51 | 51 | // Validator extensions  | 
                                                        
| 52 | -        $validator->extend('captcha', function ($attribute, $value, $parameters) { | 
                                                        |
| 52 | +        $validator->extend('captcha', function($attribute, $value, $parameters) { | 
                                                        |
| 53 | 53 |              return config('captcha.disable') || ($value && captcha_check($value)); | 
                                                        
| 54 | 54 | });  | 
                                                        
| 55 | 55 | |
| 56 | 56 | // Validator extensions  | 
                                                        
| 57 | -        $validator->extend('captcha_api', function ($attribute, $value, $parameters) { | 
                                                        |
| 57 | +        $validator->extend('captcha_api', function($attribute, $value, $parameters) { | 
                                                        |
| 58 | 58 |              return config('captcha.disable') || ($value && captcha_api_check($value, $parameters[0], $parameters[1] ?? 'default')); | 
                                                        
| 59 | 59 | });  | 
                                                        
| 60 | 60 | }  | 
                                                        
@@ -68,19 +68,19 @@ discard block  | 
                                                    ||
| 68 | 68 |      { | 
                                                        
| 69 | 69 | // Merge configs  | 
                                                        
| 70 | 70 | $this->mergeConfigFrom(  | 
                                                        
| 71 | - __DIR__ . '/../config/captcha.php',  | 
                                                        |
| 71 | + __DIR__.'/../config/captcha.php',  | 
                                                        |
| 72 | 72 | 'captcha'  | 
                                                        
| 73 | 73 | );  | 
                                                        
| 74 | 74 | |
| 75 | 75 | // if Intervention\Image\ImageManager is not bound  | 
                                                        
| 76 | -        if (!$this->app->bound('Intervention\Image\ImageManager')) { | 
                                                        |
| 77 | -            $this->app->singleton('Intervention\Image\ImageManager', function ($app) { | 
                                                        |
| 76 | +        if ( ! $this->app->bound('Intervention\Image\ImageManager')) { | 
                                                        |
| 77 | +            $this->app->singleton('Intervention\Image\ImageManager', function($app) { | 
                                                        |
| 78 | 78 | return new \Intervention\Image\ImageManager(new Driver());  | 
                                                        
| 79 | 79 | });  | 
                                                        
| 80 | 80 | }  | 
                                                        
| 81 | 81 | |
| 82 | 82 | // Bind captcha  | 
                                                        
| 83 | -        $this->app->bind('captcha', function ($app) { | 
                                                        |
| 83 | +        $this->app->bind('captcha', function($app) { | 
                                                        |
| 84 | 84 | return new Captcha(  | 
                                                        
| 85 | 85 | $app['Illuminate\Filesystem\Filesystem'],  | 
                                                        
| 86 | 86 | $app['Illuminate\Contracts\Config\Repository'],  | 
                                                        
@@ -229,7 +229,7 @@ discard block  | 
                                                    ||
| 229 | 229 | $this->hasher = $hasher;  | 
                                                        
| 230 | 230 | $this->str = $str;  | 
                                                        
| 231 | 231 |          $this->characters = config('captcha.characters', ['1', '2', '3', '4', '6', '7', '8', '9']); | 
                                                        
| 232 | -        $this->fontsDirectory = config('captcha.fontsDirectory',  dirname(__DIR__) . '/assets/fonts'); | 
                                                        |
| 232 | +        $this->fontsDirectory = config('captcha.fontsDirectory', dirname(__DIR__).'/assets/fonts'); | 
                                                        |
| 233 | 233 | }  | 
                                                        
| 234 | 234 | |
| 235 | 235 | /**  | 
                                                        
@@ -238,8 +238,8 @@ discard block  | 
                                                    ||
| 238 | 238 | */  | 
                                                        
| 239 | 239 | protected function configure($config)  | 
                                                        
| 240 | 240 |      { | 
                                                        
| 241 | -        if ($this->config->has('captcha.' . $config)) { | 
                                                        |
| 242 | -            foreach ($this->config->get('captcha.' . $config) as $key => $val) { | 
                                                        |
| 241 | +        if ($this->config->has('captcha.'.$config)) { | 
                                                        |
| 242 | +            foreach ($this->config->get('captcha.'.$config) as $key => $val) { | 
                                                        |
| 243 | 243 |                  $this->{$key} = $val; | 
                                                        
| 244 | 244 | }  | 
                                                        
| 245 | 245 | }  | 
                                                        
@@ -255,11 +255,11 @@ discard block  | 
                                                    ||
| 255 | 255 | */  | 
                                                        
| 256 | 256 | public function create(string $config = 'default', bool $api = false)  | 
                                                        
| 257 | 257 |      { | 
                                                        
| 258 | - $this->backgrounds = $this->files->files(__DIR__ . '/../assets/backgrounds');  | 
                                                        |
| 258 | + $this->backgrounds = $this->files->files(__DIR__.'/../assets/backgrounds');  | 
                                                        |
| 259 | 259 | $this->fonts = $this->files->files($this->fontsDirectory);  | 
                                                        
| 260 | 260 | |
| 261 | 261 |          if (version_compare(app()->version(), '5.5.0', '>=')) { | 
                                                        
| 262 | -            $this->fonts = array_map(function ($file) { | 
                                                        |
| 262 | +            $this->fonts = array_map(function($file) { | 
                                                        |
| 263 | 263 | /* @var File $file */  | 
                                                        
| 264 | 264 | return $file->getPathName();  | 
                                                        
| 265 | 265 | }, $this->fonts);  | 
                                                        
@@ -387,7 +387,7 @@ discard block  | 
                                                    ||
| 387 | 387 |          foreach ($text as $key => $char) { | 
                                                        
| 388 | 388 | $marginLeft = $this->textLeftPadding + ($key * ($this->image->width() - $this->textLeftPadding) / $this->length);  | 
                                                        
| 389 | 389 | |
| 390 | -            $this->image->text($char, $marginLeft, $marginTop, function ($font) { | 
                                                        |
| 390 | +            $this->image->text($char, $marginLeft, $marginTop, function($font) { | 
                                                        |
| 391 | 391 | /* @var Font $font */  | 
                                                        
| 392 | 392 | $font->file($this->font());  | 
                                                        
| 393 | 393 | $font->size($this->fontSize());  | 
                                                        
@@ -426,10 +426,10 @@ discard block  | 
                                                    ||
| 426 | 426 | */  | 
                                                        
| 427 | 427 | protected function fontColor(): string  | 
                                                        
| 428 | 428 |      { | 
                                                        
| 429 | -        if (!empty($this->fontColors)) { | 
                                                        |
| 429 | +        if ( ! empty($this->fontColors)) { | 
                                                        |
| 430 | 430 | $color = $this->fontColors[rand(0, count($this->fontColors) - 1)];  | 
                                                        
| 431 | 431 |          } else { | 
                                                        
| 432 | - $color = '#' . str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT);  | 
                                                        |
| 432 | + $color = '#'.str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT);  | 
                                                        |
| 433 | 433 | }  | 
                                                        
| 434 | 434 | |
| 435 | 435 | return $color;  | 
                                                        
@@ -453,7 +453,7 @@ discard block  | 
                                                    ||
| 453 | 453 | protected function lines()  | 
                                                        
| 454 | 454 |      { | 
                                                        
| 455 | 455 |          for ($i = 0; $i <= $this->lines; $i++) { | 
                                                        
| 456 | -            $this->image->drawLine(function (LineFactory $line) use ($i) { | 
                                                        |
| 456 | +            $this->image->drawLine(function(LineFactory $line) use ($i) { | 
                                                        |
| 457 | 457 | $line->from(rand(0, $this->image->width()) + $i * rand(0, $this->image->height()), rand(0, $this->image->height()));  | 
                                                        
| 458 | 458 | $line->to(rand(0, $this->image->width()), rand(0, $this->image->height()));  | 
                                                        
| 459 | 459 |                  $line->color('ff00ff'); // color of line | 
                                                        
@@ -472,7 +472,7 @@ discard block  | 
                                                    ||
| 472 | 472 | */  | 
                                                        
| 473 | 473 | public function check(string $value): bool  | 
                                                        
| 474 | 474 |      { | 
                                                        
| 475 | -        if (!$this->session->has('captcha')) { | 
                                                        |
| 475 | +        if ( ! $this->session->has('captcha')) { | 
                                                        |
| 476 | 476 | return false;  | 
                                                        
| 477 | 477 | }  | 
                                                        
| 478 | 478 | |
@@ -480,12 +480,12 @@ discard block  | 
                                                    ||
| 480 | 480 |          $sensitive = $this->session->get('captcha.sensitive'); | 
                                                        
| 481 | 481 |          $encrypt = $this->session->get('captcha.encrypt'); | 
                                                        
| 482 | 482 | |
| 483 | -        if (!Cache::pull($this->get_cache_key($key))) { | 
                                                        |
| 483 | +        if ( ! Cache::pull($this->get_cache_key($key))) { | 
                                                        |
| 484 | 484 |              $this->session->remove('captcha'); | 
                                                        
| 485 | 485 | return false;  | 
                                                        
| 486 | 486 | }  | 
                                                        
| 487 | 487 | |
| 488 | -        if (!$sensitive) { | 
                                                        |
| 488 | +        if ( ! $sensitive) { | 
                                                        |
| 489 | 489 | $value = $this->str->lower($value);  | 
                                                        
| 490 | 490 | }  | 
                                                        
| 491 | 491 | |
@@ -507,7 +507,7 @@ discard block  | 
                                                    ||
| 507 | 507 | */  | 
                                                        
| 508 | 508 | protected function get_cache_key($key)  | 
                                                        
| 509 | 509 |      { | 
                                                        
| 510 | - return 'captcha_' . md5($key);  | 
                                                        |
| 510 | + return 'captcha_'.md5($key);  | 
                                                        |
| 511 | 511 | }  | 
                                                        
| 512 | 512 | |
| 513 | 513 | /**  | 
                                                        
@@ -520,13 +520,13 @@ 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);  | 
                                                        |
| 529 | + if ( ! $this->sensitive) $value = $this->str->lower($value);  | 
                                                        |
| 530 | 530 | if ($this->encrypt) $key = Crypt::decrypt($key);  | 
                                                        
| 531 | 531 | return $this->hasher->check($value, $key);  | 
                                                        
| 532 | 532 | }  | 
                                                        
@@ -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 | }  | 
                                                        
@@ -352,7 +352,9 @@ discard block  | 
                                                    ||
| 352 | 352 | }  | 
                                                        
| 353 | 353 | |
| 354 | 354 | $hash = $this->hasher->make($key);  | 
                                                        
| 355 | - if ($this->encrypt) $hash = Crypt::encrypt($hash);  | 
                                                        |
| 355 | +        if ($this->encrypt) { | 
                                                        |
| 356 | + $hash = Crypt::encrypt($hash);  | 
                                                        |
| 357 | + }  | 
                                                        |
| 356 | 358 | |
| 357 | 359 |          $this->session->put('captcha', [ | 
                                                        
| 358 | 360 | 'sensitive' => $this->sensitive,  | 
                                                        
@@ -489,7 +491,9 @@ discard block  | 
                                                    ||
| 489 | 491 | $value = $this->str->lower($value);  | 
                                                        
| 490 | 492 | }  | 
                                                        
| 491 | 493 | |
| 492 | - if ($encrypt) $key = Crypt::decrypt($key);  | 
                                                        |
| 494 | +        if ($encrypt) { | 
                                                        |
| 495 | + $key = Crypt::decrypt($key);  | 
                                                        |
| 496 | + }  | 
                                                        |
| 493 | 497 | $check = $this->hasher->check($value, $key);  | 
                                                        
| 494 | 498 | // if verify pass,remove session  | 
                                                        
| 495 | 499 |          if ($check) { | 
                                                        
@@ -526,8 +530,12 @@ discard block  | 
                                                    ||
| 526 | 530 | |
| 527 | 531 | $this->configure($config);  | 
                                                        
| 528 | 532 | |
| 529 | - if (!$this->sensitive) $value = $this->str->lower($value);  | 
                                                        |
| 530 | - if ($this->encrypt) $key = Crypt::decrypt($key);  | 
                                                        |
| 533 | +        if (!$this->sensitive) { | 
                                                        |
| 534 | + $value = $this->str->lower($value);  | 
                                                        |
| 535 | + }  | 
                                                        |
| 536 | +        if ($this->encrypt) { | 
                                                        |
| 537 | + $key = Crypt::decrypt($key);  | 
                                                        |
| 538 | + }  | 
                                                        |
| 531 | 539 | return $this->hasher->check($value, $key);  | 
                                                        
| 532 | 540 | }  | 
                                                        
| 533 | 541 | |