YubikeyForm   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 60
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFormActions() 0 9 1
A __construct() 0 10 1
A getAuthenticatorName() 0 3 1
A getFormFields() 0 16 2
1
<?php
2
3
namespace Firesphere\YubiAuth\Forms;
4
5
use SilverStripe\Control\RequestHandler;
6
use SilverStripe\Forms\FieldList;
7
use SilverStripe\Forms\FormAction;
8
use SilverStripe\Forms\HiddenField;
9
use SilverStripe\Forms\PasswordField;
10
use SilverStripe\Forms\RequiredFields;
11
use SilverStripe\Security\LoginForm;
12
13
/**
14
 * Class YubikeyForm
15
 * @package Firesphere\YubiAuth\Forms
16
 */
17
class YubikeyForm extends LoginForm
18
{
19
    /**
20
     * YubikeyForm constructor.
21
     * @param RequestHandler|null $controller
22
     * @param string $name
23
     */
24
    public function __construct(
25
        RequestHandler $controller = null,
26
        $name = self::DEFAULT_NAME
27
    ) {
28
        $this->controller = $controller;
29
        $fields = $this->getFormFields();
30
        $actions = $this->getFormActions();
31
        $validator = RequiredFields::create(['yubiauth']);
32
33
        parent::__construct($controller, $name, $fields, $actions, $validator);
0 ignored issues
show
Bug introduced by
It seems like $actions can also be of type Firesphere\YubiAuth\Forms\YubikeyForm; however, parameter $actions of SilverStripe\Forms\Form::__construct() does only seem to accept null|SilverStripe\Forms\FieldList, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
        parent::__construct($controller, $name, $fields, /** @scrutinizer ignore-type */ $actions, $validator);
Loading history...
Bug introduced by
It seems like $fields can also be of type Firesphere\YubiAuth\Forms\YubikeyForm; however, parameter $fields of SilverStripe\Forms\Form::__construct() does only seem to accept null|SilverStripe\Forms\FieldList, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
        parent::__construct($controller, $name, /** @scrutinizer ignore-type */ $fields, $actions, $validator);
Loading history...
34
    }
35
36
    /**
37
     * @return FieldList|static
38
     */
39
    public function getFormFields()
40
    {
41
        $fields = FieldList::create(
42
            [
43
                PasswordField::create(
44
                    'yubiauth',
45
                    _t(self::class . '.YUBIKEYSECONDFACTORFIELD', 'Yubikey second factor authentication')
46
                )
47
            ]
48
        );
49
        $backURL = $this->controller->getRequest()->getVar('BackURL');
50
        if ($backURL) {
51
            $fields->push(HiddenField::create('BackURL', $backURL));
52
        }
53
54
        return $fields;
55
    }
56
57
    /**
58
     * @return FieldList|static
59
     */
60
    public function getFormActions()
61
    {
62
        $action = FieldList::create(
63
            [
64
                FormAction::create('validateToken', _t(self::class . '.VALIDATE', 'Validate'))
65
            ]
66
        );
67
68
        return $action;
69
    }
70
71
    /**
72
     * @return string
73
     */
74
    public function getAuthenticatorName()
75
    {
76
        return _t(self::class . '.TITLE', 'Yubikey authentication');
77
    }
78
}
79