ResetPasswordFormFields   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 61
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 52 3
1
<?php namespace Anomaly\UsersModule\User\Password;
2
3
/**
4
 * Class ResetPasswordFormFields
5
 *
6
 * @link          http://pyrocms.com/
7
 * @author        PyroCMS, Inc. <[email protected]>
8
 * @author        Ryan Thompson <[email protected]>
9
 */
10
class ResetPasswordFormFields
11
{
12
13
    /**
14
     * Handle the fields.
15
     *
16
     * @param ResetPasswordFormBuilder $builder
17
     */
18
    public function handle(ResetPasswordFormBuilder $builder)
19
    {
20
        $builder->setFields([]);
21
22
        if (!$builder->getEmail()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $builder->getEmail() of type null|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
23
            $builder->addField(
24
                [
25
                    'field'    => 'email',
26
                    'type'     => 'anomaly.field_type.email',
27
                    'label'    => 'anomaly.module.users::field.email.name',
28
                    'required' => true,
29
                ]
30
            );
31
        }
32
33
        if (!$builder->getCode()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $builder->getCode() of type null|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
34
            $builder->addField(
35
                [
36
                    'field'    => 'code',
37
                    'type'     => 'anomaly.field_type.text',
38
                    'label'    => 'anomaly.module.users::field.reset_code.name',
39
                    'required' => true,
40
                ]
41
            );
42
        }
43
44
        $builder->addFields(
45
            [
46
                [
47
                    'field'    => 'password',
48
                    'type'     => 'anomaly.field_type.text',
49
                    'label'    => 'anomaly.module.users::field.password.name',
50
                    'required' => true,
51
                    'rules'    => [
52
                        'confirmed',
53
                    ],
54
                    'config'   => [
55
                        'type' => 'password',
56
                    ],
57
                ],
58
                [
59
                    'field'    => 'password_confirmation',
60
                    'type'     => 'anomaly.field_type.text',
61
                    'label'    => 'anomaly.module.users::field.confirm_password.name',
62
                    'required' => true,
63
                    'config'   => [
64
                        'type' => 'password',
65
                    ],
66
                ],
67
            ]
68
        );
69
    }
70
}
71