Passed
Push — master ( afdc6b...e39cc4 )
by Adrien
03:24
created

User::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 53
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 30
c 0
b 0
f 0
dl 0
loc 53
ccs 0
cts 40
cp 0
rs 9.44
cc 1
nc 1
nop 0
crap 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 mQueue\Form;
4
5
use Zend_Form;
6
use Zend_Validate_Db_NoRecordExists;
7
8
class User extends Zend_Form
9
{
10
    public function init(): void
11
    {
12
        // Set the method for the display form to POST
13
        $this->setMethod('post');
14
15
        // Add the nickname element
16
        $this->addElement('text', 'nickname', [
17
            'label' => _tr('Nickname:'),
18
            'autofocus' => true,
19
            'required' => true,
20
            'filters' => ['filter' => ['filter' => 'stringTrim']],
21
            'validators' => [
22
                ['validator' => new Zend_Validate_Db_NoRecordExists(['table' => 'user', 'field' => 'nickname'])],
23
            ],
24
        ]);
25
26
        // Add the email element
27
        $this->addElement('text', 'email', [
28
            'label' => _tr('Email:'),
29
            'required' => true,
30
            'filters' => ['filter' => ['filter' => 'stringTrim']],
31
            'validators' => [
32
                ['validator' => 'emailAddress'],
33
                ['validator' => new Zend_Validate_Db_NoRecordExists(['table' => 'user', 'field' => 'email'])],
34
            ],
35
        ]);
36
37
        // Add the password ail element
38
        $this->addElement('password', 'password', [
39
            'label' => _tr('Password:'),
40
            'required' => true,
41
        ]);
42
43
        // Add a captcha
44
        $this->addElement('captcha', 'captcha', [
45
            'label' => _tr('Are you a robot?'),
46
            'required' => true,
47
            'captcha' => 'figlet',
48
            'captchaOptions' => [
49
                'outputWidth' => 2000,
50
            ],
51
        ]);
52
53
        // Add the submit button
54
        $this->addElement('submit', 'submit', [
55
            'ignore' => true,
56
            'label' => _tr('Subscribe'),
57
        ]);
58
59
        // And finally add some CSRF protection
60
        $this->addElement('hash', 'csrf', [
61
            'ignore' => true,
62
            'decorators' => ['ViewHelper'],
63
        ]);
64
    }
65
}
66