Completed
Push — master ( 700ce5...16d566 )
by MeWebStudio - Muharrem
12s queued 10s
created
src/Captcha.php 2 patches
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
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', __DIR__ . '/../assets/fonts');
219
+        $this->fontsDirectory = config('captcha.fontsDirectory', __DIR__.'/../assets/fonts');
220 220
     }
221 221
 
222 222
     /**
@@ -225,8 +225,8 @@  discard block
 block discarded – undo
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
 block discarded – undo
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);
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
         }
295 295
 
296 296
         if ($api) {
297
-            Cache::put('captcha_record_' . $generator['key'], $generator['value'], $this->expire);
297
+            Cache::put('captcha_record_'.$generator['key'], $generator['value'], $this->expire);
298 298
         }
299 299
 
300 300
         return $api ? [
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
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,
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
         foreach ($text as $key => $char) {
373 373
             $marginLeft = $this->textLeftPadding + ($key * ($this->image->width() - $this->textLeftPadding) / $this->length);
374 374
 
375
-            $this->image->text($char, $marginLeft, $marginTop, function ($font) {
375
+            $this->image->text($char, $marginLeft, $marginTop, function($font) {
376 376
                 /* @var Font $font */
377 377
                 $font->file($this->font());
378 378
                 $font->size($this->fontSize());
@@ -411,10 +411,10 @@  discard block
 block discarded – undo
411 411
      */
412 412
     protected function fontColor(): string
413 413
     {
414
-        if (!empty($this->fontColors)) {
414
+        if ( ! empty($this->fontColors)) {
415 415
             $color = $this->fontColors[rand(0, count($this->fontColors) - 1)];
416 416
         } else {
417
-            $color = '#' . str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT);
417
+            $color = '#'.str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT);
418 418
         }
419 419
 
420 420
         return $color;
@@ -443,7 +443,7 @@  discard block
 block discarded – undo
443 443
                 rand(0, $this->image->height()),
444 444
                 rand(0, $this->image->width()),
445 445
                 rand(0, $this->image->height()),
446
-                function ($draw) {
446
+                function($draw) {
447 447
                     /* @var Font $draw */
448 448
                     $draw->color($this->fontColor());
449 449
                 }
@@ -461,18 +461,18 @@  discard block
 block discarded – undo
461 461
      */
462 462
     public function check(string $value): bool
463 463
     {
464
-        if (!$this->session->has('captcha')) {
464
+        if ( ! $this->session->has('captcha')) {
465 465
             return false;
466 466
         }
467 467
 
468 468
         $key = $this->session->get('captcha.key');
469 469
         $sensitive = $this->session->get('captcha.sensitive');
470 470
 
471
-        if (!$sensitive) {
471
+        if ( ! $sensitive) {
472 472
             $value = $this->str->lower($value);
473 473
         }
474 474
 
475
-        if($this->encrypt) $key = Crypt::decrypt($key);
475
+        if ($this->encrypt) $key = Crypt::decrypt($key);
476 476
         $check = $this->hasher->check($value, $key);
477 477
         // if verify pass,remove session
478 478
         if ($check) {
@@ -491,11 +491,11 @@  discard block
 block discarded – undo
491 491
      */
492 492
     public function check_api($value, $key): bool
493 493
     {
494
-        if (!Cache::pull('captcha_record_' . $key)) {
494
+        if ( ! Cache::pull('captcha_record_'.$key)) {
495 495
             return false;
496 496
         }
497 497
 
498
-        if($this->encrypt) $key = Crypt::decrypt($key);
498
+        if ($this->encrypt) $key = Crypt::decrypt($key);
499 499
         return $this->hasher->check($value, $key);
500 500
     }
501 501
 
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
      */
508 508
     public function src(string $config = 'default'): string
509 509
     {
510
-        return url('captcha/' . $config) . '?' . $this->str->random(8);
510
+        return url('captcha/'.$config).'?'.$this->str->random(8);
511 511
     }
512 512
 
513 513
     /**
@@ -527,8 +527,8 @@  discard block
 block discarded – undo
527 527
                 continue;
528 528
             }
529 529
 
530
-            $attrs_str .= $attr . '="' . $value . '" ';
530
+            $attrs_str .= $attr.'="'.$value.'" ';
531 531
         }
532
-        return new HtmlString('<img src="' . $this->src($config) . '" ' . trim($attrs_str) . '>');
532
+        return new HtmlString('<img src="'.$this->src($config).'" '.trim($attrs_str).'>');
533 533
     }
534 534
 }
Please login to merge, or discard this patch.
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -341,7 +341,9 @@  discard block
 block discarded – undo
341 341
         }
342 342
 
343 343
         $hash = $this->hasher->make($key);
344
-        if($this->encrypt) $hash = Crypt::encrypt($hash);
344
+        if($this->encrypt) {
345
+            $hash = Crypt::encrypt($hash);
346
+        }
345 347
         
346 348
         $this->session->put('captcha', [
347 349
             'sensitive' => $this->sensitive,
@@ -472,7 +474,9 @@  discard block
 block discarded – undo
472 474
             $value = $this->str->lower($value);
473 475
         }
474 476
 
475
-        if($this->encrypt) $key = Crypt::decrypt($key);
477
+        if($this->encrypt) {
478
+            $key = Crypt::decrypt($key);
479
+        }
476 480
         $check = $this->hasher->check($value, $key);
477 481
         // if verify pass,remove session
478 482
         if ($check) {
@@ -495,7 +499,9 @@  discard block
 block discarded – undo
495 499
             return false;
496 500
         }
497 501
 
498
-        if($this->encrypt) $key = Crypt::decrypt($key);
502
+        if($this->encrypt) {
503
+            $key = Crypt::decrypt($key);
504
+        }
499 505
         return $this->hasher->check($value, $key);
500 506
     }
501 507
 
Please login to merge, or discard this patch.