Completed
Push — master ( a9845d...cc3347 )
by Adrien
02:02
created

User::init()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 55

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 55
ccs 19
cts 19
cp 1
crap 1
rs 8.9818
c 0
b 0
f 0

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