CreatorOnlyCanEditFormExtension::updateEditForm()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 21
rs 9.3142
cc 3
eloc 11
nc 3
nop 1
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