Completed
Push — master ( 1cde98...dfb6a0 )
by Ryan
02:03
created

ResetPasswordFormFields   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 3
c 2
b 1
f 0
lcom 0
cbo 1
dl 0
loc 61
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
 * @package       Anomaly\UsersModule\User\Password
10
 */
11
class ResetPasswordFormFields
12
{
13
14
    /**
15
     * Handle the fields.
16
     *
17
     * @param ResetPasswordFormBuilder $builder
18
     */
19
    public function handle(ResetPasswordFormBuilder $builder)
20
    {
21
        $builder->setFields([]);
22
23
        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...
24
            $builder->addField(
25
                [
26
                    'field'    => 'email',
27
                    'type'     => 'anomaly.field_type.email',
28
                    'label'    => 'anomaly.module.users::field.email.name',
29
                    'required' => true,
30
                ]
31
            );
32
        }
33
34
        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...
35
            $builder->addField(
36
                [
37
                    'field'    => 'code',
38
                    'type'     => 'anomaly.field_type.text',
39
                    'label'    => 'anomaly.module.users::field.reset_code.name',
40
                    'required' => true,
41
                ]
42
            );
43
        }
44
45
        $builder->addFields(
46
            [
47
                [
48
                    'field'    => 'password',
49
                    'type'     => 'anomaly.field_type.text',
50
                    'label'    => 'anomaly.module.users::field.password.name',
51
                    'required' => true,
52
                    'rules'    => [
53
                        'confirmed'
54
                    ],
55
                    'config'   => [
56
                        'type' => 'password'
57
                    ]
58
                ],
59
                [
60
                    'field'    => 'password_confirmation',
61
                    'type'     => 'anomaly.field_type.text',
62
                    'label'    => 'anomaly.module.users::field.confirm_password.name',
63
                    'required' => true,
64
                    'config'   => [
65
                        'type' => 'password'
66
                    ],
67
                ]
68
            ]
69
        );
70
    }
71
}
72