CreatorLastEditorExtension   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6
Metric Value
wmc 4
lcom 1
cbo 6
dl 0
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A onBeforeWrite() 0 7 2
A updateCMSFields() 0 9 2
1
<?php
2
3
class CreatorLastEditorExtension extends DataExtension
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
    private static $has_one = array(
0 ignored issues
show
Unused Code introduced by
The property $has_one 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...
6
        'Creator' => 'Member',
7
        'LastEditor' => 'Member',
8
    );
9
10
    /*
11
    1) Save the creator as the current editing member if there is not creator already assigned
12
    2) Save the last editor (e.g. an admin) as the person who last edited this document
13
    */
14
    public function onBeforeWrite()
15
    {
16
        if ($this->owner->CreatorID == 0) {
17
            $this->owner->CreatorID = Member::currentUserID();
18
        }
19
        $this->owner->LastEditorID = Member::currentUserID();
20
    }
21
22
    /*
23
    Allow the admin to override the creator and last editor
24
    */
25
    public function updateCMSFields(FieldList $fields)
26
    {
27
        if (Permission::check('ADMIN')) {
28
            $memberField = new DropdownField('CreatorID', 'Creator', Member::get()->map('ID', 'Username', '-- Please select --'));
0 ignored issues
show
Unused Code introduced by
The call to DataList::map() has too many arguments starting with '-- Please select --'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
29
            $fields->addFieldToTab('Root.Creator', $memberField);
30
        }
31
32
        return $fields;
33
    }
34
}
35