CreatorOnlyCanEditFormExtension   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5
Metric Value
wmc 3
lcom 0
cbo 5
dl 0
loc 24
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A updateEditForm() 0 21 3
1
<?php
2
3
class CreatorOnlyCanEditFormExtension extends Extension
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    public function updateEditForm(&$form)
6
    {
7
        //error_log('Creator id:'.$this->owner->CreatorID);
8
        //error_log('Current member id:'.Member::currentUserID());
9
10
        $creatorID = Member::currentUserID();
0 ignored issues
show
Unused Code introduced by
$creatorID is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
11
        $formfields = $form->fields;
12
        $formid = $formfields->fieldbyName('ID');
13
        //error_log($formid->value());
14
        $sql = 'select CreatorID from SiteTree where ID='.$formid->value().' Limit 1';
15
        $result = DB::query($sql);
16
        $first = $result->first();
17
        $creatorID = $first['CreatorID'];
18
        //error_log('CREATOR: '.$creatorID);
19
20
        if (!(Permission::check('ADMIN'))) {
21
            if ($creatorID != Member::currentUserID()) {
22
                $form->makeReadonly();
23
            }
24
        }
25
    }
26
}
27