Passed
Push — master ( 291050...8bc8e6 )
by Simon
01:52
created

MemberExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
dl 0
loc 29
rs 10
c 2
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A updateCMSFields() 0 9 2
A onBeforeWrite() 0 5 2
1
<?php
2
3
namespace Firesphere\GraphQLJWT\Extensions;
4
5
use SilverStripe\Forms\CheckboxField;
6
use SilverStripe\Forms\FieldList;
7
use SilverStripe\ORM\DataExtension;
8
9
/**
10
 * Class MemberExtension
11
 * Add a unique token to the Member for extra validation
12
 */
13
class MemberExtension extends DataExtension
14
{
15
    private static $db = [
0 ignored issues
show
Unused Code introduced by
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
16
        'JWTUniqueID' => 'Varchar(255)',
17
    ];
18
19
    private static $indexes = [
0 ignored issues
show
Unused Code introduced by
The property $indexes is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
20
        'JWTUniqueID' => 'unique'
21
    ];
22
23
    public function updateCMSFields(FieldList $fields)
24
    {
25
        parent::updateCMSFields($fields);
26
        $fields->removeByName(['JWTUniqueID']);
27
        if ($this->owner->JWTUniqueID) {
28
            $fields->addFieldsToTab(
29
                'Root.Main',
30
                [
31
                    CheckboxField::create('reset', 'Reset the Token ID to disable this user\'s remote login')
0 ignored issues
show
Bug introduced by
'reset' of type string is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

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

31
                    CheckboxField::create(/** @scrutinizer ignore-type */ 'reset', 'Reset the Token ID to disable this user\'s remote login')
Loading history...
32
                ]
33
            );
34
        }
35
    }
36
37
    public function onBeforeWrite()
38
    {
39
        parent::onBeforeWrite();
40
        if ($this->owner->reset) {
41
            $this->owner->JWTUniqueID = null;
42
        }
43
    }
44
}
45