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.

ValidNewPasswordValidator   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 12

2 Methods

Rating   Name   Duplication   Size   Complexity  
B validate() 0 35 11
A addError() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LM\AuthAbstractor\Form\Constraint;
6
7
use Symfony\Component\Validator\Constraint;
8
use Symfony\Component\Validator\ConstraintValidator;
9
10
/**
11
 * The validator class associated with ValidNewPassword.
12
 *
13
 * @see \LM\AuthAbstractor\Form\Constraint\ValidNewPassword
14
 */
15
class ValidNewPasswordValidator extends ConstraintValidator
16
{
17
    /**
18
     * Validates a given password and adds errors to the form if it has errors.
19
     *
20
     * @internal
21
     */
22
    public function validate($password, Constraint $constraint)
23
    {
24
        $pwdValidator = $constraint->getPwdValidator();
0 ignored issues
show
Bug introduced by
The method getPwdValidator() does not exist on Symfony\Component\Validator\Constraint. It seems like you code against a sub-type of Symfony\Component\Validator\Constraint such as LM\AuthAbstractor\Form\Constraint\ValidNewPassword. ( Ignorable by Annotation )

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

24
        /** @scrutinizer ignore-call */ 
25
        $pwdValidator = $constraint->getPwdValidator();
Loading history...
25
        $pwdConfig = $constraint->getConfig()->getPwdSettings();
0 ignored issues
show
Bug introduced by
The method getConfig() does not exist on Symfony\Component\Validator\Constraint. It seems like you code against a sub-type of Symfony\Component\Validator\Constraint such as LM\AuthAbstractor\Form\Constraint\ValidNewPassword. ( Ignorable by Annotation )

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

25
        $pwdConfig = $constraint->/** @scrutinizer ignore-call */ getConfig()->getPwdSettings();
Loading history...
26
        if (true === $pwdConfig['enforce_min_length']) {
27
            $pwdMinLength = $pwdConfig['min_length'];
28
            if (mb_strlen($password, 'utf-8') < $pwdMinLength) {
29
                $this->addError("Your password needs to be at least {$pwdMinLength} characters long", $password);
30
            }
31
        }
32
        if (true === $pwdConfig['numbers']) {
33
            switch (preg_match('/[0-9]/', $password)) {
34
                case 0:
35
                    $this->addError('Your password needs to contain numbers.', $password);
36
                    break;
37
38
                case false:
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match('/[0-9]/', $password) of type integer to the boolean false. If you are specifically checking for 0, consider using something more explicit like === 0 instead.
Loading history...
39
                    throw new Exception();
0 ignored issues
show
Bug introduced by
The type LM\AuthAbstractor\Form\Constraint\Exception was not found. Did you mean Exception? If so, make sure to prefix the type with \.
Loading history...
40
                    break;
41
            }
42
        }
43
        if (true === $pwdConfig['special_chars']) {
44
            if (false === $pwdValidator->hasSpecialChars($password)) {
45
                $this->addError('Your password needs to contain special characters', $password);
46
            }
47
        }
48
        if (true === $pwdConfig['uppercase']) {
49
            switch (preg_match('/[A-Z]/', $password)) {
50
                case 0:
51
                    $this->addError('Your password needs to contain uppercase letters.', $password);
52
                    break;
53
54
                case false:
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing preg_match('/[A-Z]/', $password) of type integer to the boolean false. If you are specifically checking for 0, consider using something more explicit like === 0 instead.
Loading history...
55
                    throw new Exception();
56
                    break;
57
            }
58
        }
59
    }
60
61
    /**
62
     * @internal
63
     */
64
    private function addError(string $message, string $password): void
65
    {
66
        $this
67
            ->context
68
            ->buildViolation($message)
69
            ->setParameter('{{ string }}', $password)
70
            ->addViolation()
71
        ;
72
    }
73
}
74