GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Password::guard()   B
last analyzed

Complexity

Conditions 8
Paths 128

Size

Total Lines 32
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
eloc 17
c 1
b 0
f 0
nc 128
nop 2
dl 0
loc 32
ccs 18
cts 18
cp 1
crap 8
rs 8.2111
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DBUnt1tled\VO\VObjects\Person;
6
7
use DBUnt1tled\VO\Exception\InvalidVOArgumentException;
8
use DBUnt1tled\VO\VObjects\Scalar\Strings;
9
use DBUnt1tled\VO\VObjects\ValueObjectComplex;
10
use DBUnt1tled\VO\VObjects\ValueObjectInterface;
11
12
class Password extends ValueObjectComplex
13
{
14
    public const PASSWORD_MIN_LENGTH = 8;
15
    public const PASSWORD_MAX_LENGTH = 20;
16
17
    /**
18
     * @param mixed $value
19
     * @param mixed ...$other
20
     * @throws \ReflectionException
21
     */
22 2
    public function guard($value, ...$other): void
23
    {
24 2
        parent::guard($value);
25
        /** @var ValueObjectInterface $value*/
26 2
        $pwd = $value->getValue();
27 2
        $error = '';
28 2
        if (mb_strlen($pwd) < 8) {
29 1
            $error .= 'Password too short!';
30
        }
31
32 2
        if (mb_strlen($pwd) > 20) {
33 1
            $error .= "Password too long!\n";
34
        }
35
36 2
        if (!preg_match('#[\d]+#', $pwd)) {
37 1
            $error .= "Password must include at least one number!\n";
38
        }
39
40 2
        if (!preg_match('#[a-z]+#', $pwd)) {
41 1
            $error .= "Password must include at least one letter!\n";
42
        }
43
44 2
        if (!preg_match('#[A-Z]+#', $pwd)) {
45 1
            $error .= "Password must include at least one CAPS!\n";
46
        }
47
48 2
        if (!preg_match('#\W+#', $pwd)) {
49 1
            $error .= "Password must include at least one symbol!\n";
50
        }
51
52 2
        if ($error !== '') {
53 1
            throw new InvalidVOArgumentException($error, $value);
54
        }
55 1
    }
56
57
    /**
58
     * @param string $value
59
     * @return Password
60
     * @throws \ReflectionException
61
     */
62 2
    public static function createFromString(string $value): self
63
    {
64 2
        return new static(new Strings($value));
65
    }
66
}
67