Completed
Push — master ( 254925...5d79ce )
by Lhalaa
14s queued 10s
created

PasswordForm   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 5
dl 0
loc 64
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 23 4
A getFields() 0 6 1
A getActions() 0 6 1
A getFormValidator() 0 4 1
1
<?php
2
3
namespace Firesphere\PartialUserforms\Forms;
4
5
use Firesphere\PartialUserforms\Controllers\PartialUserFormVerifyController;
6
use SilverStripe\Forms\FieldList;
7
use SilverStripe\Forms\Form;
8
use SilverStripe\Forms\FormAction;
9
use SilverStripe\Forms\PasswordField;
10
use SilverStripe\Forms\RequiredFields;
11
use SilverStripe\Forms\Validator;
12
13
class PasswordForm extends Form
14
{
15
    public const PASSWORD_SESSION_KEY = 'PartialFormSession';
16
17
    /**
18
     * PasswordForm constructor.
19
     * @param PartialUserFormVerifyController|null $controller
20
     * @param string $name
21
     * @param FieldList|null $fields
22
     * @param FieldList|null $actions
23
     * @param Validator|null $validator
24
     */
25 3
    public function __construct(
26
        PartialUserFormVerifyController $controller = null,
27
        $name = self::DEFAULT_NAME,
28
        FieldList $fields = null,
29
        FieldList $actions = null,
30
        Validator $validator = null
31
    ) {
32 3
        if (!$fields) {
33 3
            $fields = $this->getFields();
34
        }
35 3
        if (!$actions) {
36 3
            $actions = $this->getActions();
37
        }
38 3
        if (!$validator) {
39 3
            $validator = $this->getFormValidator();
40
        }
41 3
        parent::__construct($controller, $name, $fields, $actions, $validator);
42
43 3
        $this->setFormAction(sprintf('/verify/%s', $name));
44
45
        // Add the userform class to the form, so it's can be styled similar to the actual userforms more easily
46 3
        $this->addExtraClass('userform');
47 3
    }
48
49
    /**
50
     * @return FieldList
51
     */
52 3
    protected function getFields()
53
    {
54 3
        return FieldList::create([
55 3
            PasswordField::create('Password', _t(__CLASS__ . '.PasswordField', 'Password'))
56
        ]);
57
    }
58
59
    /**
60
     * @return FieldList
61
     */
62 3
    protected function getActions()
63
    {
64 3
        return FieldList::create([
65 3
            FormAction::create('doValidate', _t(__CLASS__ . '.Validate', 'Submit'))
66
        ]);
67
    }
68
69
    /**
70
     * @return RequiredFields
71
     */
72 3
    public function getFormValidator()
73
    {
74 3
        return RequiredFields::create(['Password']);
75
    }
76
}
77