Completed
Push — master ( b78fb6...9af9b2 )
by
unknown
12s
created

DMSDocumentCartSubmission::onBeforeWrite()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
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
        'CreatedAt'               => 'Datetime',
14
    );
15
16
    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...
17
        'Items' => 'DMSDocumentCartSubmissionItem',
18
    );
19
20
    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...
21
        'ReceiverName' => 'Receiver Name',
22
        'ReceiverPhone' => 'Receiver Phone',
23
        'ReceiverEmail' => 'Receiver Email',
24
        'Items.Count' => 'No. Items',
25
        'CreatedAt.Nice' => 'Created At'
26
    );
27
28
    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...
29
    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...
30
31
    /**
32
     * Removing the add and existing GridField components to ensure that the model admin for submissions doesn't
33
     * let you add new records
34
     *
35
     * @return FieldList
36
     */
37
    public function getCMSFields()
38
    {
39
        // PHP 5.3 support
40
        $self = $this;
41
        $this->beforeUpdateCMSFields(function (FieldList $fields) use ($self) {
42
            $fields->addFieldToTab(
43
                'Root.Main',
44
                $fields->fieldByName('Root.Main.CreatedAt')->performReadonlyTransformation()
45
            );
46
47
            $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...
48
            $fields->addFieldToTab('Root.Items', $gridField);
49
50
            foreach (array('GridFieldAddExistingAutocompleter', 'GridFieldAddNewButton') as $component) {
51
                $config->removeComponentsByType($component);
52
            }
53
        });
54
        return parent::getCMSFields();
55
    }
56
57
    /**
58
     * Set the created at datetime if it hasn't been set already
59
     */
60
    public function onBeforeWrite()
61
    {
62
        if (!$this->CreatedAt) {
0 ignored issues
show
Bug introduced by
The property CreatedAt does not seem to exist. Did you mean Created?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
63
            $this->CreatedAt = SS_Datetime::now();
0 ignored issues
show
Bug introduced by
The property CreatedAt does not seem to exist. Did you mean Created?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
64
        }
65
        return parent::onBeforeWrite();
66
    }
67
}
68