Completed
Push — master ( 023bd4...0eb96d )
by Simon
01:43
created

MemberExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 32
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A updateCMSFields() 0 13 2
A onBeforeWrite() 0 7 2
1
<?php
2
3
namespace Firesphere\GraphQLJWT;
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')
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