AskForPassword::comparePasswords()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 13
ccs 0
cts 7
cp 0
rs 10
cc 4
nc 3
nop 2
crap 20
1
<?php
2
3
namespace App\Console\Commands\Traits;
4
5
/**
6
 * @method void error($message, $verbosity = null)
7
 * @method mixed secret($message, $fallback = true)
8
 */
9
trait AskForPassword
10
{
11
    private function askForPassword(): string
12
    {
13
        do {
14
            $password = $this->secret('Your desired password');
15
16
            if (!$password) {
17
                $this->error('Passwords cannot be empty. You know that.');
18
                continue;
19
            }
20
21
            $confirmedPassword = $this->secret('Again, just to be sure');
22
        } while (!$this->comparePasswords($password, $confirmedPassword ?? null));
23
24
        return $password;
25
    }
26
27
    private function comparePasswords(?string $password, ?string $confirmedPassword): bool
28
    {
29
        if (!$password || !$confirmedPassword) {
30
            return false;
31
        }
32
33
        if (strcmp($password, $confirmedPassword) !== 0) {
34
            $this->error('The passwords do not match. Try again maybe?');
35
36
            return false;
37
        }
38
39
        return true;
40
    }
41
}
42