Login::__construct()   B
last analyzed

Complexity

Conditions 5
Paths 12

Size

Total Lines 77

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 77
rs 8.1907
c 0
b 0
f 0
cc 5
nc 12
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 Laminas\Form\Element;
6
use LmcUser\Options\AuthenticationOptionsInterface;
7
8
class Login extends ProvidesEventsForm
9
{
10
    /**
11
     * @var AuthenticationOptionsInterface
12
     */
13
    protected $authOptions;
14
15
    public function __construct($name, AuthenticationOptionsInterface $options)
16
    {
17
        $this->setAuthenticationOptions($options);
18
19
        parent::__construct($name);
20
21
        $this->add(
22
            array(
23
            'name' => 'identity',
24
            'options' => array(
25
                'label' => '',
26
            ),
27
            'attributes' => array(
28
                'type' => 'text'
29
            ),
30
            )
31
        );
32
33
        $emailElement = $this->get('identity');
34
        $label = $emailElement->getLabel('label');
0 ignored issues
show
Unused Code introduced by
The call to ElementInterface::getLabel() has too many arguments starting with 'label'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
35
        // @TODO: make translation-friendly
36
        foreach ($this->getAuthenticationOptions()->getAuthIdentityFields() as $mode) {
37
            $label = (!empty($label) ? $label . ' or ' : '') . ucfirst($mode);
38
        }
39
        $emailElement->setLabel($label);
40
        //
41
        $this->add(
42
            array(
43
            'name' => 'credential',
44
            'type' => 'password',
45
            'options' => array(
46
                'label' => 'Password',
47
            ),
48
            'attributes' => array(
49
                'type' => 'password',
50
            ),
51
            )
52
        );
53
54
        if ($this->getAuthenticationOptions()->getUseLoginFormCsrf()) {
55
            $this->add([
56
                'type' => '\Laminas\Form\Element\Csrf',
57
                'name' => 'security',
58
                'options' => [
59
                    'csrf_options' => [
60
                        'timeout' => $this->getAuthenticationOptions()->getLoginFormTimeout()
61
                    ]
62
                ]
63
            ]);
64
        }
65
        if ($this->getAuthenticationOptions()->getUseLoginFormCaptcha()) {
66
            $this->add([
67
                'name' => 'captcha',
68
                'type' => 'Laminas\Form\Element\Captcha',
69
                'options' => [
70
                    'label' => 'Human check',
71
                    'captcha' => $this->getAuthenticationOptions()->getFormCaptchaOptions(),
72
                ]
73
            ]);
74
        }
75
76
        $submitElement = new Element\Button('submit');
77
        $submitElement
78
            ->setLabel('Sign In')
79
            ->setAttributes(
80
                array(
81
                'type'  => 'submit',
82
                )
83
            );
84
85
        $this->add(
86
            $submitElement,
87
            array(
88
            'priority' => -100,
89
            )
90
        );
91
    }
92
93
    /**
94
     * Set Authentication-related Options
95
     *
96
     * @param  AuthenticationOptionsInterface $authOptions
97
     * @return Login
98
     */
99
    public function setAuthenticationOptions(AuthenticationOptionsInterface $authOptions)
100
    {
101
        $this->authOptions = $authOptions;
102
103
        return $this;
104
    }
105
106
    /**
107
     * Get Authentication-related Options
108
     *
109
     * @return AuthenticationOptionsInterface
110
     */
111
    public function getAuthenticationOptions()
112
    {
113
        return $this->authOptions;
114
    }
115
}
116