Completed
Pull Request — master (#300)
by
unknown
16s
created
src/Captcha.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
         $this->hasher = $hasher;
234 234
         $this->str = $str;
235 235
         $this->characters = config('captcha.characters', ['1', '2', '3', '4', '6', '7', '8', '9']);
236
-        $this->fontsDirectory = config('captcha.fontsDirectory',  dirname(__DIR__) . '/assets/fonts');
236
+        $this->fontsDirectory = config('captcha.fontsDirectory', dirname(__DIR__).'/assets/fonts');
237 237
     }
238 238
 
239 239
     /**
@@ -242,8 +242,8 @@  discard block
 block discarded – undo
242 242
      */
243 243
     protected function configure($config)
244 244
     {
245
-        if ($this->config->has('captcha.' . $config)) {
246
-            foreach ($this->config->get('captcha.' . $config) as $key => $val) {
245
+        if ($this->config->has('captcha.'.$config)) {
246
+            foreach ($this->config->get('captcha.'.$config) as $key => $val) {
247 247
                 $this->{$key} = $val;
248 248
             }
249 249
         }
@@ -259,11 +259,11 @@  discard block
 block discarded – undo
259 259
      */
260 260
     public function create(string $config = 'default', bool $api = false)
261 261
     {
262
-        $this->backgrounds = $this->files->files(__DIR__ . '/../assets/backgrounds');
262
+        $this->backgrounds = $this->files->files(__DIR__.'/../assets/backgrounds');
263 263
         $this->fonts = $this->files->files($this->fontsDirectory);
264 264
 
265 265
         if (version_compare(app()->version(), '5.5.0', '>=')) {
266
-            $this->fonts = array_map(function ($file) {
266
+            $this->fonts = array_map(function($file) {
267 267
                 /* @var File $file */
268 268
                 return $file->getPathName();
269 269
             }, $this->fonts);
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
         $generator = $this->generate();
277 277
         $this->text = $generator['value'];
278 278
 
279
-        $this->canvas = $this->imageManager->create($this->width , $this->height)->fill($this->fill);
279
+        $this->canvas = $this->imageManager->create($this->width, $this->height)->fill($this->fill);
280 280
 
281 281
 
282 282
         if ($this->bgImage) {
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
         }
357 357
 
358 358
         $hash = $this->hasher->make($key);
359
-        if($this->encrypt) $hash = Crypt::encrypt($hash);
359
+        if ($this->encrypt) $hash = Crypt::encrypt($hash);
360 360
 
361 361
         $this->session->put('captcha', [
362 362
             'sensitive' => $this->sensitive,
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
         foreach ($text as $key => $char) {
392 392
             $marginLeft = $this->textLeftPadding + ($key * ($this->image->width() - $this->textLeftPadding) / $this->length);
393 393
 
394
-            $this->image->text($char, $marginLeft, $marginTop, function ($font) {
394
+            $this->image->text($char, $marginLeft, $marginTop, function($font) {
395 395
                 /* @var Font $font */
396 396
                 $font->file($this->font());
397 397
                 $font->size($this->fontSize());
@@ -430,10 +430,10 @@  discard block
 block discarded – undo
430 430
      */
431 431
     protected function fontColor(): string
432 432
     {
433
-        if (!empty($this->fontColors)) {
433
+        if ( ! empty($this->fontColors)) {
434 434
             $color = $this->fontColors[rand(0, count($this->fontColors) - 1)];
435 435
         } else {
436
-            $color = '#' . str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT);
436
+            $color = '#'.str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT);
437 437
         }
438 438
 
439 439
         return $color;
@@ -457,9 +457,9 @@  discard block
 block discarded – undo
457 457
     protected function lines()
458 458
     {
459 459
         for ($i = 0; $i <= $this->lines; $i++) {
460
-            $this->image->drawLine(function (LineFactory $line) use ($i) {
461
-                $line->from(rand(0, $this->image->width()) + $i * rand(0, $this->image->height()) , rand(0, $this->image->height()));
462
-                $line->to( rand(0, $this->image->width()), rand(0, $this->image->height()));
460
+            $this->image->drawLine(function(LineFactory $line) use ($i) {
461
+                $line->from(rand(0, $this->image->width()) + $i * rand(0, $this->image->height()), rand(0, $this->image->height()));
462
+                $line->to(rand(0, $this->image->width()), rand(0, $this->image->height()));
463 463
                 $line->color($this->fontColor()); // color of line
464 464
                 $line->width($this->lineWidth); // line width in pixels
465 465
             });
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
      */
477 477
     public function check(string $value): bool
478 478
     {
479
-        if (!$this->session->has('captcha')) {
479
+        if ( ! $this->session->has('captcha')) {
480 480
             return false;
481 481
         }
482 482
 
@@ -484,16 +484,16 @@  discard block
 block discarded – undo
484 484
         $sensitive = $this->session->get('captcha.sensitive');
485 485
         $encrypt = $this->session->get('captcha.encrypt');
486 486
 
487
-        if (!Cache::pull($this->get_cache_key($key))) {
487
+        if ( ! Cache::pull($this->get_cache_key($key))) {
488 488
             $this->session->remove('captcha');
489 489
             return false;
490 490
         }
491 491
 
492
-        if (!$sensitive) {
492
+        if ( ! $sensitive) {
493 493
             $value = $this->str->lower($value);
494 494
         }
495 495
 
496
-        if($encrypt) $key = Crypt::decrypt($key);
496
+        if ($encrypt) $key = Crypt::decrypt($key);
497 497
         $check = $this->hasher->check($value, $key);
498 498
         // if verify pass,remove session
499 499
         if ($check) {
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
      * @return string
511 511
      */
512 512
     protected function get_cache_key($key) {
513
-        return 'captcha_' . md5($key);
513
+        return 'captcha_'.md5($key);
514 514
     }
515 515
 
516 516
     /**
@@ -523,14 +523,14 @@  discard block
 block discarded – undo
523 523
      */
524 524
     public function check_api($value, $key, $config = 'default'): bool
525 525
     {
526
-        if (!Cache::pull($this->get_cache_key($key))) {
526
+        if ( ! Cache::pull($this->get_cache_key($key))) {
527 527
             return false;
528 528
         }
529 529
 
530 530
         $this->configure($config);
531 531
 
532
-        if(!$this->sensitive) $value = $this->str->lower($value);
533
-        if($this->encrypt) $key = Crypt::decrypt($key);
532
+        if ( ! $this->sensitive) $value = $this->str->lower($value);
533
+        if ($this->encrypt) $key = Crypt::decrypt($key);
534 534
         return $this->hasher->check($value, $key);
535 535
     }
536 536
 
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
      */
543 543
     public function src(string $config = 'default'): string
544 544
     {
545
-        return url('captcha/' . $config) . '?' . $this->str->random(8);
545
+        return url('captcha/'.$config).'?'.$this->str->random(8);
546 546
     }
547 547
 
548 548
     /**
@@ -562,8 +562,8 @@  discard block
 block discarded – undo
562 562
                 continue;
563 563
             }
564 564
 
565
-            $attrs_str .= $attr . '="' . $value . '" ';
565
+            $attrs_str .= $attr.'="'.$value.'" ';
566 566
         }
567
-        return new HtmlString('<img src="' . $this->src($config) . '" ' . trim($attrs_str) . '>');
567
+        return new HtmlString('<img src="'.$this->src($config).'" '.trim($attrs_str).'>');
568 568
     }
569 569
 }
Please login to merge, or discard this patch.