EcommerceOrderStepCountryData   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 8
dl 0
loc 81
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A i18n_singular_name() 0 4 1
A i18n_plural_name() 0 4 1
A getCMSFields() 0 22 1
A validate() 0 13 2
1
<?php
2
3
/**
4
 * Data for each in orderstep
5
 * for each country
6
 *
7
 */
8
9
class EcommerceOrderStepCountryData extends DataObject
10
{
11
    private static $singular_name = "Country specific Order Step Information";
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...
12
    public function i18n_singular_name()
13
    {
14
        return "Country specific Order Step Information";
15
    }
16
17
    private static $plural_name = "Country specific Order Step Information Items";
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...
18
    public function i18n_plural_name()
19
    {
20
        return "Country specific Order Step Information Items";
21
    }
22
23
    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...
24
        'CountrySpecificEmailSubject' => 'Varchar(255)',
25
        'CountrySpecificEmailMessage' => 'HTMLText'
26
    );
27
28
    private static $has_one = 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...
29
        "OrderStep" => "OrderStep",
30
        "EcommerceCountry" => "EcommerceCountry"
31
    );
32
33
    private static $required_fields = array(
34
        "EcommerceCountryID"
35
    );
36
37
    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...
38
        "EcommerceCountry.Title" => "Country",
39
        "OrderStep.Title" => "Step",
40
        "CountrySpecificEmailSubject" => "Subject"
41
42
    );
43
44
    private static $field_labels = 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...
45
        "CountrySpecificEmailSubject" => "Email Subject",
46
        "CountrySpecificEmailMessage" => "Email Message"
47
    );
48
49
50
    public function getCMSFields()
51
    {
52
        $fields = parent::getCMSFields();
53
        $messageField = new HtmlEditorField('CountrySpecificEmailMessage', "Email Content");
54
        $messageField->setRows(7);
55
        $fields->addFieldsToTab(
56
            'Root.Main',
57
            array(
58
            new TextField('CountrySpecificEmailSubject', "Subject"),
59
            $messageField
60
        )
61
        );
62
        $fields->addFieldToTab(
63
            "Root.Main",
64
            new DropdownField(
65
                "EcommerceCountryID",
66
                "Country",
67
                EcommerceCountry::get()->map()
68
            )
69
        );
70
        return $fields;
71
    }
72
73
    /**
74
     * make sure this entry does not exist yet...
75
     */
76
    public function validate()
77
    {
78
        $valid = parent::validate();
79
        $filter = array(
80
            "OrderStepID" => $this->OrderStepID,
0 ignored issues
show
Documentation introduced by
The property OrderStepID does not exist on object<EcommerceOrderStepCountryData>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
81
            "EcommerceCountryID" => $this->EcommerceCountryID
0 ignored issues
show
Documentation introduced by
The property EcommerceCountryID does not exist on object<EcommerceOrderStepCountryData>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
82
        );
83
        $exclude = array("ID" => $this->ID);
84
        if (EcommerceOrderStepCountryData::get()->filter($filter)->exclude($exclude)->count()) {
85
            $valid->error('An entry for this country and order step already exists. Please change the country or review existing records.');
86
        }
87
        return $valid;
88
    }
89
}
90