TOTPForm   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A getFormFields() 0 11 2
A getAuthenticatorName() 0 3 1
A getFormActions() 0 9 1
1
<?php
2
3
namespace ElliotSawyer\TOTPAuthenticator;
4
5
use Firesphere\BootstrapMFA\Forms\BootstrapMFALoginForm;
6
use SilverStripe\Control\RequestHandler;
7
use SilverStripe\Forms\FieldList;
8
use SilverStripe\Forms\FormAction;
9
use SilverStripe\Forms\HiddenField;
10
use SilverStripe\Forms\PasswordField;
11
12
/**
13
 * Class TOTPForm
14
 * @package ElliotSawyer\TOTPAuthenticator
15
 */
16
class TOTPForm extends BootstrapMFALoginForm
17
{
18
    /**
19
     * TOTPForm constructor.
20
     * @param RequestHandler|null $controller
21
     * @param null $validator
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $validator is correct as it would always require null to be passed?
Loading history...
22
     * @param string $name
23
     */
24
    public function __construct(
25
        RequestHandler $controller = null,
26
        $validator = null,
27
        $name = self::DEFAULT_NAME
28
    ) {
29
        $this->controller = $controller;
30
        $fields = $this->getFormFields();
31
        $actions = $this->getFormActions();
32
33
        parent::__construct($controller, $validator, $name, $fields, $actions);
0 ignored issues
show
Bug introduced by
It seems like $fields can also be of type ElliotSawyer\TOTPAuthenticator\TOTPForm; however, parameter $fields of SilverStripe\Security\Me...oginForm::__construct() does only seem to accept 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, $validator, $name, /** @scrutinizer ignore-type */ $fields, $actions);
Loading history...
Bug introduced by
It seems like $actions can also be of type ElliotSawyer\TOTPAuthenticator\TOTPForm; however, parameter $actions of SilverStripe\Security\Me...oginForm::__construct() does only seem to accept SilverStripe\Forms\Field...Stripe\Forms\FormAction, 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, $validator, $name, $fields, /** @scrutinizer ignore-type */ $actions);
Loading history...
34
    }
35
36
    /**
37
     * @return FieldList|static
38
     */
39
    public function getFormFields()
40
    {
41
        $fields = FieldList::create();
42
        $fields->push(PasswordField::create('token', _t(self::class . '.TOTPCODE', 'TOTP Code')));
43
44
        $backURL = $this->controller->getRequest()->getVar('BackURL');
45
        if ($backURL) {
46
            $fields->push(HiddenField::create('BackURL', $backURL));
47
        }
48
49
        return $fields;
50
    }
51
52
    /**
53
     * @return FieldList|static
54
     */
55
    public function getFormActions()
56
    {
57
        $action = FieldList::create(
58
            [
59
                FormAction::create('validateTOTP', _t(self::class . '.VALIDATETOTP', 'Validate'))
60
            ]
61
        );
62
63
        return $action;
64
    }
65
66
    /**
67
     * @return string
68
     */
69
    public function getAuthenticatorName()
70
    {
71
        return _t(self::class . '.TITLE', 'TOTP Second factor authentication');
72
    }
73
}
74