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

ResetPasswordFormFields::handle()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 52
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 52
rs 9.4929
cc 3
eloc 29
nc 4
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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