EmailReminder_EmailRecord   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 147
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 3
dl 0
loc 147
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A i18n_singular_name() 0 4 1
A i18n_plural_name() 0 4 1
A canCreate() 0 4 1
A canEdit() 0 4 1
A canDelete() 0 4 1
A getCMSFields() 0 23 1
A canSendAgain() 0 20 4
A CMSEditLink() 0 3 1
A getExportFields() 0 3 1
1
<?php
2
3
class EmailReminder_EmailRecord extends DataObject
4
{
5
    private static $singular_name = "Email Reminder Record";
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...
6
    public function i18n_singular_name()
7
    {
8
        return self::$singular_name;
9
    }
10
11
    private static $plural_name = "Email Reminder Records";
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_plural_name()
13
    {
14
        return self::$plural_name;
15
    }
16
17
    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...
18
        'EmailTo' => 'Varchar(100)',
19
        'ExternalRecordClassName' => 'Varchar(100)',
20
        'ExternalRecordID' => 'Int',
21
        'Result' => 'Boolean',
22
        'IsTestOnly' => 'Boolean',
23
        'EmailContent' => 'HTMLText'
24
    );
25
26
    private static $indexes = 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...
27
        'EmailTo' => true,
28
        'ExternalRecordClassName' => true,
29
        'ExternalRecordID' => true,
30
        'Result' => true,
31
        'Created' => true
32
    );
33
34
    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...
35
        'EmailReminder_NotificationSchedule' => 'EmailReminder_NotificationSchedule'
36
    );
37
38
    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...
39
        'Created.Nice' => 'When',
40
        'EmailTo' => 'Sent to',
41
        'Result.Nice' => 'Sent Succesfully',
42
        'IsTestOnly.Nice' => 'Test Only'
43
    );
44
45
    public static $default_sort = [
46
        'Created' => 'DESC',
47
        'ID' => 'DESC'
48
    ];
49
50
51
    public function canCreate($member = null)
52
    {
53
        return false;
54
    }
55
56
    public function canEdit($member = null)
57
    {
58
        return false;
59
    }
60
61
    public function canDelete($member = null)
62
    {
63
        return false;
64
    }
65
66
    /**
67
     * standard SS method.
68
     *
69
     * @return FieldList
70
     */
71
    public function getCMSFields()
72
    {
73
        $fields = parent::getCMSFields();
74
        $fields->addFieldsToTab(
75
            'Root.Details',
76
            array(
77
                $fields->dataFieldByName("EmailTo"),
78
                $fields->dataFieldByName("ExternalRecordClassName"),
79
                $fields->dataFieldByName("ExternalRecordID"),
80
                $fields->dataFieldByName("Result"),
81
                $fields->dataFieldByName("IsTestOnly"),
82
                $fields->dataFieldByName("EmailReminder_NotificationScheduleID"),
83
            )
84
        );
85
        $fields->replaceField(
86
            'EmailContent',
87
            LiteralField::create(
88
                'EmailContent',
89
                $this->EmailContent
0 ignored issues
show
Documentation introduced by
The property EmailContent does not exist on object<EmailReminder_EmailRecord>. 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...
90
            )
91
        );
92
        return $fields;
93
    }
94
95
    /**
96
     *
97
     * tests to see if an email can be sent
98
     * the emails can only be sent once unless previous attempts have failed
99
     */
100
    public function canSendAgain()
101
    {
102
        $send = true;
103
        if ($this->Result) {
0 ignored issues
show
Documentation introduced by
The property Result does not exist on object<EmailReminder_EmailRecord>. 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...
104
            if ($this->IsTestOnly) {
0 ignored issues
show
Documentation introduced by
The property IsTestOnly does not exist on object<EmailReminder_EmailRecord>. 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...
105
                return true;
106
            } else {
107
                $send = false;
108
                $numberOfSecondsBeforeYouCanSendAgain = $this->EmailReminder_NotificationSchedule()->RepeatDays * 86400;
0 ignored issues
show
Documentation Bug introduced by
The method EmailReminder_NotificationSchedule does not exist on object<EmailReminder_EmailRecord>? 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...
109
                $todaysTS = strtotime('NOW');
110
111
                $creationTS = strtotime($this->Created);
112
                $difference = ($todaysTS - $creationTS);
113
                if ($difference > $numberOfSecondsBeforeYouCanSendAgain) {
114
                    $send = true;
115
                }
116
            }
117
        }
118
        return $send;
119
    }
120
121
    /**
122
     *
123
     * PartialMatchFilter
124
     */
125
    private static $searchable_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...
126
        'EmailTo' => 'PartialMatchFilter',
127
        'Result' => 'ExactMatchFilter',
128
        'IsTestOnly' => 'ExactMatchFilter',
129
    );
130
131
    /**
132
     * e.g.
133
     *    $controller = singleton("MyModelAdmin");
134
     *    return $controller->Link().$this->ClassName."/EditForm/field/".$this->ClassName."/item/".$this->ID."/edit";
135
      */
136
    public function CMSEditLink()
137
    {
138
    }
139
140
141
    /**
142
     * returns list of fields as they are exported
143
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be array|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
144
     * Field => Label
145
     */
146
    public function getExportFields()
147
    {
148
    }
149
}
150