Completed
Push — master ( bafc8d...4dabfd )
by Phan
08:25
created

AskForPassword   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 15
c 1
b 0
f 0
dl 0
loc 31
ccs 0
cts 15
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A askForPassword() 0 14 3
A comparePasswords() 0 13 4
1
<?php
2
3
namespace App\Console\Commands\Traits;
4
5
trait AskForPassword
6
{
7
    private function askForPassword(): string
8
    {
9
        do {
10
            $password = $this->secret('Your desired password');
0 ignored issues
show
Bug introduced by
It seems like secret() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

10
            /** @scrutinizer ignore-call */ 
11
            $password = $this->secret('Your desired password');
Loading history...
11
12
            if (!$password) {
13
                $this->error('Passwords cannot be empty. You know that.');
0 ignored issues
show
Bug introduced by
It seems like error() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

13
                $this->/** @scrutinizer ignore-call */ 
14
                       error('Passwords cannot be empty. You know that.');
Loading history...
14
                continue;
15
            }
16
17
            $confirmedPassword = $this->secret('Again, just to be sure');
18
        } while (!$this->comparePasswords($password, $confirmedPassword ?? null));
19
20
        return $password;
21
    }
22
23
    private function comparePasswords(?string $password, ?string $confirmedPassword): bool
24
    {
25
        if (!$password || !$confirmedPassword) {
26
            return false;
27
        }
28
29
        if (strcmp($password, $confirmedPassword) !== 0) {
30
            $this->error('The passwords do not match. Try again maybe?');
31
32
            return false;
33
        }
34
35
        return true;
36
    }
37
}
38