EcommerceSecurityOrderDecoration   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 7
dl 0
loc 49
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A updateCMSFields() 0 25 4
A onBeforeWrite() 0 13 3
1
<?php
2
3
class EcommerceSecurityOrderDecoration 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 $db = array(
0 ignored issues
show
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
        'SkipToSecurityChecks' => 'Boolean'
7
    );
8
9
    public function updateCMSFields(FieldList $fields)
10
    {
11
        if ($this->owner->IsSubmitted()) {
12
            $currentStep = $this->owner->MyStep()->Sort;
13
            $securityStep = OrderStep::get()->filter(['ClassName' => 'OrderStep_SecurityCheck'])->first()->Sort;
14
            if (! $this->owner->IsPaid() && $currentStep < $securityStep) {
15
                $fields->addFieldsToTab(
16
                    'Root.Next',
17
                    [
18
                        HeaderField::create(
19
                            'SkipToSecurityChecksHeader',
20
                            'Skip To Security Checks'
21
                        ),
22
                        CheckboxField::create(
23
                            'SkipToSecurityChecks',
24
                            'Skip To Security Checks'
25
                        )->setDescription(
26
                            'Ticking this checkbox will skip the payment step, allowing security checks to be conducted for orders that do not have successful payments.'
27
                        )
28
                    ],
29
                    'ActionNextStepManually'
30
                );
31
            }
32
        }
33
    }
34
35
    /**
36
     * Event handler called before writing to the database.
37
     */
38
    public function onBeforeWrite()
39
    {
40
        parent::onBeforeWrite();
41
        if ($this->owner->SkipToSecurityChecks) {
0 ignored issues
show
Bug introduced by
The property SkipToSecurityChecks does not seem to exist in SS_Object.

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...
42
            $securityCheck = OrderStatusLog_SecurityCheck::create();
43
            $securityCheck->OrderID = $this->owner->ID;
0 ignored issues
show
Documentation introduced by
The property OrderID does not exist on object<OrderStatusLog_SecurityCheck>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
The property ID does not seem to exist in SS_Object.

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...
44
            $securityCheck->write();
45
            $securityStepID = OrderStep::get()->filter(['ClassName' => 'OrderStep_SecurityCheck'])->first()->ID;
46
            if($securityStepID){
47
                $this->owner->StatusID = $securityStepID;
0 ignored issues
show
Bug introduced by
The property StatusID does not seem to exist in SS_Object.

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...
48
            }
49
        }
50
    }
51
}
52