PasswordValidation   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 46
ccs 0
cts 29
cp 0
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 37 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Canvas\Validations;
5
6
use Phalcon\Validation;
0 ignored issues
show
Bug introduced by
The type Phalcon\Validation was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Phalcon\Validation\Validator\PresenceOf;
0 ignored issues
show
Bug introduced by
The type Phalcon\Validation\Validator\PresenceOf was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Phalcon\Validation\Validator\Confirmation;
0 ignored issues
show
Bug introduced by
The type Phalcon\Validation\Validator\Confirmation was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Phalcon\Validation\Validator\StringLength;
0 ignored issues
show
Bug introduced by
The type Phalcon\Validation\Validator\StringLength was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Exception;
11
use Canvas\Validation as CanvasValidation;
12
13
class PasswordValidation
14
{
15
    /**
16
     * Validate the password given.
17
     *
18
     * @param string $newPassword
19
     * @param string $verifyPassword
20
     * @return boolean
21
     */
22
    public static function validate(string $newPassword, string $verifyPassword): bool
23
    {
24
        $data = [
25
            'new_password' => $newPassword,
26
            'verify_password' => $verifyPassword,
27
        ];
28
29
        //Ok let validate user password
30
        $validation = new CanvasValidation();
31
32
        $validation->add(
33
            'new_password',
34
            new PresenceOf([
35
                'message' => 'The password is required.'
36
            ])
37
        );
38
39
        $validation->add(
40
            'new_password',
41
            new StringLength([
42
                'min' => 8,
43
                'messageMinimum' => 'Password is too short. Minimum 8 characters.',
44
            ])
45
        );
46
47
        $validation->add(
48
            'new_password',
49
            new Confirmation([
50
                'message' => 'New password and confirmation do not match.',
51
                'with' => 'verify_password',
52
            ])
53
        );
54
55
        //validate this form for password
56
        $validation->validate($data);
57
58
        return true;
59
    }
60
}
61