DMSDocumentCartSubmission   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 5
dl 0
loc 50
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getCMSFields() 0 16 2
1
<?php
2
3
class DMSDocumentCartSubmission extends DataObject
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 $db = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
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...
6
        'ReceiverName'            => 'Varchar(100)',
7
        'ReceiverPhone'           => 'Varchar(20)',
8
        'ReceiverEmail'           => 'Varchar(254)',
9
        'DeliveryAddressLine1'    => 'Varchar(200)',
10
        'DeliveryAddressLine2'    => 'Varchar(200)',
11
        'DeliveryAddressCountry'  => 'Varchar(50)',
12
        'DeliveryAddressPostCode' => 'Varchar(20)',
13
    );
14
15
    private static $has_many = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $has_many 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
        'Items' => 'DMSDocumentCartSubmissionItem',
17
    );
18
19
    private static $summary_fields = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $summary_fields 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
        'ReceiverName' => 'Receiver Name',
21
        'ReceiverPhone' => 'Receiver Phone',
22
        'ReceiverEmail' => 'Receiver Email',
23
        'Items.Count' => 'No. Items',
24
        'Created.Nice' => 'Created At'
25
    );
26
27
    private static $singular_name = 'Cart Submission';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $singular_name 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...
28
    private static $plural_name = 'Cart Submissions';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $plural_name 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...
29
30
    /**
31
     * Removing the add and existing GridField components to ensure that the model admin for submissions doesn't
32
     * let you add new records
33
     *
34
     * @return FieldList
35
     */
36
    public function getCMSFields()
37
    {
38
        // PHP 5.3 support
39
        $self = $this;
40
        $this->beforeUpdateCMSFields(function (FieldList $fields) use ($self) {
41
            $fields->addFieldToTab('Root.Main', ReadonlyField::create('Created'));
42
43
            $gridField = GridField::create('Items', null, $self->Items(), $config = new GridFieldConfig_RecordEditor);
0 ignored issues
show
Documentation Bug introduced by
The method Items does not exist on object<DMSDocumentCartSubmission>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
44
            $fields->addFieldToTab('Root.Items', $gridField);
45
46
            foreach (array('GridFieldAddExistingAutocompleter', 'GridFieldAddNewButton') as $component) {
47
                $config->removeComponentsByType($component);
48
            }
49
        });
50
        return parent::getCMSFields();
51
    }
52
}
53