ChangeEmail::__construct()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 65

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 65
rs 8.7636
c 0
b 0
f 0
cc 1
nc 1
nop 2

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
2
3
namespace LmcUser\Form;
4
5
use LmcUser\Options\AuthenticationOptionsInterface;
6
7
class ChangeEmail extends ProvidesEventsForm
8
{
9
    /**
10
     * @var AuthenticationOptionsInterface
11
     */
12
    protected $authOptions;
13
14
    public function __construct($name, AuthenticationOptionsInterface $options)
15
    {
16
        $this->setAuthenticationOptions($options);
17
18
        parent::__construct($name);
19
20
        $this->add(
21
            array(
22
            'name' => 'identity',
23
            'options' => array(
24
                'label' => '',
25
            ),
26
            'attributes' => array(
27
                'type' => 'hidden',
28
            ),
29
            )
30
        );
31
32
        $this->add(
33
            array(
34
            'name' => 'newIdentity',
35
            'options' => array(
36
                'label' => 'New Email',
37
            ),
38
            'attributes' => array(
39
                'type' => 'text',
40
            ),
41
            )
42
        );
43
44
        $this->add(
45
            array(
46
            'name' => 'newIdentityVerify',
47
            'options' => array(
48
                'label' => 'Verify New Email',
49
            ),
50
            'attributes' => array(
51
                'type' => 'text',
52
            ),
53
            )
54
        );
55
56
        $this->add(
57
            array(
58
            'name' => 'credential',
59
            'type' => 'password',
60
            'options' => array(
61
                'label' => 'Password',
62
            ),
63
            'attributes' => array(
64
                'type' => 'password',
65
            ),
66
            )
67
        );
68
69
        $this->add(
70
            array(
71
            'name' => 'submit',
72
            'attributes' => array(
73
                'value' => 'Submit',
74
                'type'  => 'submit'
75
            ),
76
            )
77
        );
78
    }
79
80
    /**
81
     * Set Authentication-related Options
82
     *
83
     * @param  AuthenticationOptionsInterface $authOptions
84
     * @return ChangeEmail
85
     */
86
    public function setAuthenticationOptions(AuthenticationOptionsInterface $authOptions)
87
    {
88
        $this->authOptions = $authOptions;
89
90
        return $this;
91
    }
92
93
    /**
94
     * Get Authentication-related Options
95
     *
96
     * @return AuthenticationOptionsInterface
97
     */
98
    public function getAuthenticationOptions()
99
    {
100
        return $this->authOptions;
101
    }
102
}
103