HashCheckCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 54
ccs 17
cts 17
cp 1
rs 10
c 1
b 0
f 0
wmc 6
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
B handle() 0 23 4
A isHashed() 0 4 2
1
<?php
2
3
namespace LaravelPlus\Extension\Commands;
4
5
use Illuminate\Console\Command;
6
7
/**
8
 * @author Fumio Furukawa <[email protected]>
9
 */
10
class HashCheckCommand extends Command
11
{
12
    /**
13
     * The console command signature.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'hash:check
18
        {string1 : Plain or Hashed string one.}
19
        {string2 : Plain or Hashed string two.}
20
        {--cost=10 : Cost of generate.}
21
    ';
22
23
    /**
24
     * The console command description.
25
     *
26
     * @var string
27
     */
28
    protected $description = '[+] Check hashed value';
29
30
    /**
31
     * Execute the console command.
32
     *
33
     * @return mixed
34
     */
35 4
    public function handle()
36
    {
37 4
        $cost = $this->option('cost');
38
39 4
        $string1 = $this->argument('string1');
40 4
        $string2 = $this->argument('string2');
41
42 4
        if ($this->isHashed($string1)) {
43 2
            $rawString = $string2;
44 2
            $hashedString = $string1;
45 2
        } elseif ($this->isHashed($string2)) {
46 1
            $rawString = $string1;
47 1
            $hashedString = $string2;
48
        } else {
49 1
            $this->error(sprintf('Error: both "%s" and "%s" are not hashed string.', $string1, $string2));
50
51 1
            return;
52
        }
53
54 3
        $result = app('hash')->check($string1, $string2);
55
56 3
        $this->info($result ? 'Check OK!' : 'Check NG.');
57 3
    }
58
59 4
    protected function isHashed($string)
60
    {
61 4
        return strlen($string) == 60 && starts_with($string, '$2y$');
62
    }
63
}
64