Completed
Push — master ( a3ae36...7f78e2 )
by
unknown
02:34
created

EmailReminder_NotificationSchedule::sendEmailNow()   B

Complexity

Conditions 6
Paths 14

Size

Total Lines 55
Code Lines 36

Duplication

Lines 8
Ratio 14.55 %

Importance

Changes 0
Metric Value
dl 8
loc 55
rs 8.7752
c 0
b 0
f 0
cc 6
eloc 36
nc 14
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
class EmailReminder_NotificationSchedule 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
6
    /**
7
     * @var int
8
     */
9
    private static $grace_days = 3;
0 ignored issues
show
Unused Code introduced by
The property $grace_days 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...
10
11
    /**
12
     * @var string
13
     */
14
    private static $default_data_object = 'Member';
0 ignored issues
show
Unused Code introduced by
The property $default_data_object 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...
15
16
    /**
17
     * @var string
18
     */
19
    private static $default_date_field = '';
0 ignored issues
show
Unused Code introduced by
The property $default_date_field 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
21
    /**
22
     * @var string
23
     */
24
    private static $default_email_field = '';
0 ignored issues
show
Unused Code introduced by
The property $default_email_field 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...
25
    /**
26
     * @var string
27
     */
28
    private static $replaceable_record_fields = array('FirstName', 'Surname', 'Email');
0 ignored issues
show
Unused Code introduced by
The property $replaceable_record_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...
29
30
    /**
31
     * @var string
32
     */
33
    private static $mail_out_class = 'EmailReminder_DailyMailOut';
0 ignored issues
show
Unused Code introduced by
The property $mail_out_class 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...
34
35
    private static $singular_name = 'Email Reminder Schedule';
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...
36
    public function i18n_singular_name()
37
    {
38
        return self::$singular_name;
39
    }
40
41
    private static $plural_name = 'Email Reminder Schedules';
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...
42
    public function i18n_plural_name()
43
    {
44
        return self::$plural_name;
45
    }
46
47
    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...
48
        'DataObject' => 'Varchar(100)',
49
        'EmailField' => 'Varchar(100)',
50
        'DateField' => 'Varchar(100)',
51
        'Days' => 'Int',
52
        'RepeatDays' => 'Int',
53
        'BeforeAfter' => "Enum('before,after,immediately','before')",
54
        'EmailFrom' => 'Varchar(100)',
55
        'EmailSubject' => 'Varchar(100)',
56
        'Content' => 'HTMLText',
57
        'Disable' => 'Boolean',
58
        'SendTestTo' => 'Text'
59
    );
60
61
62
    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...
63
        'EmailsSent' => 'EmailReminder_EmailRecord'
64
    );
65
66
    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...
67
        'EmailSubject',
68
        'Days'
69
    );
70
71
    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...
Unused Code introduced by
The property $field_labels 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...
72
        'DataObject' => 'Class/Table',
73
        'Days' => 'Days from Expiry',
74
        'RepeatDays' => 'Repeat cycle days'
75
    );
76
77
    public function populateDefaults()
78
    {
79
        parent::populateDefaults();
80
        $this->DataObject = $this->Config()->get('default_data_object');
0 ignored issues
show
Documentation introduced by
The property DataObject does not exist on object<EmailReminder_NotificationSchedule>. 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...
81
        $this->EmailField = $this->Config()->get('default_email_field');
0 ignored issues
show
Documentation introduced by
The property EmailField does not exist on object<EmailReminder_NotificationSchedule>. 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...
82
        $this->DateField = $this->Config()->get('default_date_field');
0 ignored issues
show
Documentation introduced by
The property DateField does not exist on object<EmailReminder_NotificationSchedule>. 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...
83
        $this->Days = 7;
0 ignored issues
show
Documentation introduced by
The property Days does not exist on object<EmailReminder_NotificationSchedule>. 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...
84
        $this->RepeatDays = 300;
0 ignored issues
show
Documentation introduced by
The property RepeatDays does not exist on object<EmailReminder_NotificationSchedule>. 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...
85
        $this->BeforeAfter = 'before';
0 ignored issues
show
Documentation introduced by
The property BeforeAfter does not exist on object<EmailReminder_NotificationSchedule>. 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...
86
        $this->EmailFrom = Config::inst()->get('Email', 'admin_email');
0 ignored issues
show
Documentation introduced by
The property EmailFrom does not exist on object<EmailReminder_NotificationSchedule>. 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...
87
        $this->EmailSubject = 'Your memberships expires in [days] days';
0 ignored issues
show
Documentation introduced by
The property EmailSubject does not exist on object<EmailReminder_NotificationSchedule>. 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...
88
    }
89
90
    public function getCMSFields()
91
    {
92
        $fields = parent::getCMSFields();
93
94
        $emailsSentField = $fields->dataFieldByName('EmailsSent');
95
        $fields->removeFieldFromTab('Root', 'EmailsSent');
96
97
        $fields->addFieldToTab(
98
            'Root.Main',
99
            CheckboxField::create('Disable')
100
        );
101
        $fields->addFieldToTab(
102
            'Root.Main',
103
            $dataObjecField = DropdownField::create(
104
                'DataObject',
105
                'Table/Class Name',
106
                $this->dataObjectOptions()
107
            )
108
            ->setRightTitle('Type a valid table/class name')
109
        );
110
        if ($this->Config()->get('default_data_object')) {
111
            $fields->replaceField('DataObject', $dataObjecField->performReadonlyTransformation());
112
        }
113
114
115
116
        $fields->addFieldToTab(
117
            'Root.Main',
118
            $emailFieldField = DropdownField::create(
119
                'EmailField',
120
                'Email Field',
121
                $this->emailFieldOptions()
122
            )
123
            ->setRightTitle('Select the field that will contain a valid email address')
124
            ->setEmptyString('[ Please select ]')
125
        );
126
        if ($this->Config()->get('default_email_field')) {
127
128
            $fields->replaceField('EmailField', $emailFieldField->performReadonlyTransformation());
129
        }
130
131
        $fields->addFieldToTab(
132
            'Root.Main',
133
            $dateFieldField = DropdownField::create(
134
                'DateField',
135
                'Date Field',
136
                $this->dateFieldOptions()
137
            )
138
            ->setRightTitle('Select a valid Date field to calculate when reminders should be sent')
139
            ->setEmptyString('[ Please select ]')
140
        );
141
        if ($this->Config()->get('default_date_field')) {
142
            $fields->replaceField('DateField', $dateFieldField->performReadonlyTransformation());
143
        }
144
145
        $fields->removeFieldsFromTab(
146
            'Root.Main',
147
            array('Days', 'BeforeAfter', 'RepeatDays')
148
        );
149
        $fields->addFieldsToTab(
150
            'Root.Main',
151
            array(
152
                DropdownField::create('BeforeAfter', 'Before / After Expiration', array('before' => 'before', 'after' => 'after', 'immediately' => 'immediately'))
153
                    ->setRightTitle('Are the days listed above before or after the actual expiration date.'),
154
                NumericField::create('Days', 'Days')
155
                    ->setRightTitle('How many days in advance (before) or in arrears (after) of the expiration date should this email be sent? </br>This field is ignored if set to send immediately.'),
156
                NumericField::create('RepeatDays', 'Repeat Cycle Days')
157
                    ->setRightTitle('
158
                        Number of days after which the same reminder can be sent to the same email address.
159
                        <br />We allow an e-mail to be sent to one specific email address for one specific reminder only once.
160
                        <br />In this field you can indicate for how long we will apply this rule.'
161
                )
162
            )
163
        );
164
        $fields->addFieldsToTab(
165
            'Root.EmailContent',
166
            array(
167
                TextField::create('EmailFrom', 'Email From Address')
168
                    ->setRightTitle('The email from address, eg: "My Company &lt;[email protected]&gt;"'),
169
                $subjectField = TextField::create('EmailSubject', 'Email Subject Line')
170
                    ->setRightTitle('The subject of the email'),
171
                $contentField = HTMLEditorField::create('Content', 'Email Content')
172
                    ->SetRows(20)
173
            )
174
        );
175
        if ($obj = $this->getReplacerObject()) {
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $obj is correct as $this->getReplacerObject() (which targets EmailReminder_Notificati...le::getReplacerObject()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
176
            $html = $obj->replaceHelpList($asHTML = true);
177
            $otherFieldsThatCanBeUsed = $this->getFieldsFromDataObject(array('*'));
178
            $replaceableFields = $this->Config()->get('replaceable_record_fields');
179
            if (count($otherFieldsThatCanBeUsed)) {
180
                $html .= '<h3>You can also use the record fields (not replaced in tests):</h3><ul>';
181
                foreach ($otherFieldsThatCanBeUsed as $key => $value) {
182
                    if (in_array($key, $replaceableFields)) {
183
                        $html .= '<li><strong>$'.$key.'</strong> <span>'.$value.'</span></li>';
184
                    }
185
                }
186
            }
187
            $html .= '</ul>';
188
            $subjectField->setRightTitle('for replacement options, please see below ...');
189
            $contentField->setRightTitle($html);
190
        }
191
        $fields->addFieldsToTab(
192
            'Root.Sent',
193
            array(
194
                TextareaField::create('SendTestTo', 'Send test email to ...')
195
                    ->setRightTitle('
196
                        Separate emails by commas, a test email will be sent every time you save this Email Reminder, if you do not want test emails to be sent make sure this field is empty
197
                        '
198
                    )
199
                    ->SetRows(3)
200
            )
201
        );
202
        if ($emailsSentField) {
203
            $config = $emailsSentField->getConfig();
0 ignored issues
show
Bug introduced by
The method getConfig() does not exist on FormField. Did you maybe mean config()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
204
            $config->removeComponentsByType('GridFieldAddExistingAutocompleter');
205
            $fields->addFieldToTab(
206
                'Root.Sent',
207
                $emailsSentField
208
            );
209
        }
210
        $records = $this->CurrentRecords();
211
        if ($records) {
212
            $fields->addFieldsToTab(
213
                'Root.Review',
214
                array(
215
                    GridField::create(
216
                        'CurrentRecords',
217
                        'Today we are sending to ...',
218
                        $records
219
                    ),
220
                    LiteralField::create(
221
                        'SampleSelectStatement',
222
                        '<h3>Here is a sample statement used to select records:</h3>
223
                        <pre>'.$this->whereStatementForDays().'</pre>'
224
                    ),
225
                    LiteralField::create(
226
                        'SampleFieldDataForRecords',
227
                        '<h3>sample of '.$this->DateField.' field values:</h3>
0 ignored issues
show
Documentation introduced by
The property DateField does not exist on object<EmailReminder_NotificationSchedule>. 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...
228
                        <li>'.implode('</li><li>', $this->SampleFieldDataForRecords()).'</li>'
229
                    )
230
                )
231
            );
232
        }
233
        return $fields;
234
    }
235
236
    /**
237
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be null|array?

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...
238
     */
239
    protected function dataObjectOptions()
240
    {
241
        return ClassInfo::subclassesFor("DataObject");
242
    }
243
244
    /**
245
     * @return array
246
     */
247
    protected function emailFieldOptions()
248
    {
249
        return $this->getFieldsFromDataObject(array('Varchar', 'Email'));
250
    }
251
252
    /**
253
     * @return array
254
     */
255
    protected function dateFieldOptions()
256
    {
257
        return $this->getFieldsFromDataObject(array('Date'));
258
    }
259
260
261
    /**
262
     * list of database fields available
263
     * @param  array $fieldTypeMatchArray - strpos filter
264
     * @return array
265
     */
266
    protected function getFieldsFromDataObject($fieldTypeMatchArray = array())
267
    {
268
        $array = array();
269
        if ($this->hasValidDataObject()) {
270
            $object = Injector::inst()->get($this->DataObject);
0 ignored issues
show
Documentation introduced by
The property DataObject does not exist on object<EmailReminder_NotificationSchedule>. 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...
271
            if ($object) {
272
                $allOptions = $object->stat('db');
273
                $fieldLabels = $object->fieldLabels();
274
                foreach ($allOptions as $fieldName => $fieldType) {
275
                    foreach ($fieldTypeMatchArray as $matchString) {
276
                        if ((strpos($fieldType, $matchString) !== false) || $matchString == '*') {
277
                            if (isset($fieldLabels[$fieldName])) {
278
                                $label = $fieldLabels[$fieldName];
279
                            } else {
280
                                $label = $fieldName;
281
                            }
282
                            $array[$fieldName] = $label;
283
                        }
284
                    }
285
                }
286
            }
287
        }
288
        return $array;
289
    }
290
291
292
    /**
293
     * Test if valid classname has been set
294
     * @param null
295
     * @return Boolean
296
     */
297
    public function hasValidDataObject()
298
    {
299
        return (! $this->DataObject) || ClassInfo::exists($this->DataObject) ? true : false;
0 ignored issues
show
Documentation introduced by
The property DataObject does not exist on object<EmailReminder_NotificationSchedule>. 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...
300
    }
301
302
    /**
303
     * Test if valid fields have been set
304
     * @param null
305
     * @return Boolean
306
     */
307
    public function hasValidDataObjectFields()
308
    {
309
        if (!$this->hasValidDataObject()) {
310
            return false;
311
        }
312
        $emailFieldOptions = $this->emailFieldOptions();
313
        if (!isset($emailFieldOptions[$this->EmailField])) {
0 ignored issues
show
Documentation introduced by
The property EmailField does not exist on object<EmailReminder_NotificationSchedule>. 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...
314
            return false;
315
        }
316
        $dateFieldOptions = $this->dateFieldOptions();
317
        if (!isset($dateFieldOptions[$this->DateField])) {
0 ignored issues
show
Documentation introduced by
The property DateField does not exist on object<EmailReminder_NotificationSchedule>. 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...
Unused Code introduced by
This if statement, and the following return statement can be replaced with return isset($dateFieldO...ons[$this->DateField]);.
Loading history...
318
            return false;
319
        }
320
        return true;
321
    }
322
323
    /**
324
     * @return string
325
     */
326
    public function getTitle()
327
    {
328
        return (
329
            $this->hasValidDataObjectFields()) ?
330
            '[' . $this->EmailSubject . '] // send ' . $this->Days . ' days '.$this->BeforeAfter.' Expiration Date'
0 ignored issues
show
Documentation introduced by
The property EmailSubject does not exist on object<EmailReminder_NotificationSchedule>. 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...
Documentation introduced by
The property Days does not exist on object<EmailReminder_NotificationSchedule>. 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...
Documentation introduced by
The property BeforeAfter does not exist on object<EmailReminder_NotificationSchedule>. 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...
331
            :
332
            'uncompleted';
333
    }
334
335
    /**
336
     * @return boolean
337
     */
338
    public function hasValidFields()
339
    {
340
        if (!$this->hasValidDataObject()) {
341
            return false;
342
        }
343
        if (!$this->hasValidDataObjectFields()) {
344
            return false;
345
        }
346
        if ($this->EmailFrom && $this->EmailSubject && $this->Content) {
0 ignored issues
show
Documentation introduced by
The property EmailFrom does not exist on object<EmailReminder_NotificationSchedule>. 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...
Documentation introduced by
The property EmailSubject does not exist on object<EmailReminder_NotificationSchedule>. 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...
Documentation introduced by
The property Content does not exist on object<EmailReminder_NotificationSchedule>. 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...
Unused Code introduced by
This if statement, and the following return statement can be replaced with return $this->EmailFrom ...ject && $this->Content;.
Loading history...
347
            return true;
348
        }
349
        return false;
350
    }
351
352
    /**
353
     * @return boolean
0 ignored issues
show
Documentation introduced by
Should the return type not be ValidationResult?

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...
354
     */
355
    public function validate()
356
    {
357
        $valid = parent::validate();
358
        if ($this->exists()) {
359
            if (! $this->hasValidDataObject()) {
360
                $valid->error('Please enter valid Tabe/Class name ("' . htmlspecialchars($this->DataObject) .'" does not exist)');
0 ignored issues
show
Documentation introduced by
The property DataObject does not exist on object<EmailReminder_NotificationSchedule>. 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...
361
            } elseif (! $this->hasValidDataObjectFields()) {
362
                $valid->error('Please select valid fields for both Email & Date');
363
            } elseif (! $this->hasValidFields()) {
364
                $valid->error('Please fill in all fields.  Make sure not to forget the email details (from who, subject, content)');
365
            }
366
        }
367
        return $valid;
368
    }
369
370
    public function onBeforeWrite()
371
    {
372
        parent::onBeforeWrite();
373
        if ($this->RepeatDays < ($this->Days * 3)) {
0 ignored issues
show
Documentation introduced by
The property RepeatDays does not exist on object<EmailReminder_NotificationSchedule>. 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...
Documentation introduced by
The property Days does not exist on object<EmailReminder_NotificationSchedule>. 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...
374
            $this->RepeatDays = ($this->Days * 3);
0 ignored issues
show
Documentation introduced by
The property RepeatDays does not exist on object<EmailReminder_NotificationSchedule>. 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...
Documentation introduced by
The property Days does not exist on object<EmailReminder_NotificationSchedule>. 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...
375
        }
376
    }
377
378
    public function onAfterWrite()
379
    {
380
        parent::onAfterWrite();
381
        if ($this->SendTestTo) {
0 ignored issues
show
Documentation introduced by
The property SendTestTo does not exist on object<EmailReminder_NotificationSchedule>. 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...
382
            if ($mailOutObject = $this->getMailOutObject()) {
383
                $mailOutObject->setTestOnly(true);
384
                $mailOutObject->setVerbose(true);
385
                $mailOutObject->run(null);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<SS_HTTPRequest>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
386
            }
387
        }
388
    }
389
390
    /**
391
     *
392
     * @return null | EmailReminder_ReplacerClassInterface
393
     */
394
    public function getReplacerObject()
395
    {
396
        if ($mailOutObject = $this->getMailOutObject()) {
397
            return $mailOutObject->getReplacerObject();
398
        }
399
    }
400
401
    /**
402
     *
403
     * @return null | ScheduledTask
0 ignored issues
show
Documentation introduced by
Should the return type not be BuildTask|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...
404
     */
405
    public function getMailOutObject()
406
    {
407
        $mailOutClass = $this->Config()->get('mail_out_class');
408
        if (class_exists($mailOutClass)) {
409
            $obj = Injector::inst()->get($mailOutClass);
410
            if ($obj instanceof BuildTask) {
411
                return $obj;
412
            } else {
413
                user_error($mailOutClass.' needs to be an instance of a Scheduled Task');
414
            }
415
        }
416
    }
417
418
    /**
419
     * @param int $limit
420
     * @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...
421
     */
422
    public function SampleFieldDataForRecords($limit = 200)
423
    {
424
        if ($this->hasValidFields()) {
425
            $className = $this->DataObject;
0 ignored issues
show
Documentation introduced by
The property DataObject does not exist on object<EmailReminder_NotificationSchedule>. 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...
426
            $objects = $className::get()->sort('RAND()')
427
                ->where('"'.$this->DateField.'" IS NOT NULL AND "'.$this->DateField.'" <> \'\' AND "'.$this->DateField.'" <> 0')
0 ignored issues
show
Documentation introduced by
The property DateField does not exist on object<EmailReminder_NotificationSchedule>. 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...
428
                ->limit($limit);
429
            if ($objects->count()) {
430
                return array_unique($objects->column($this->DateField));
0 ignored issues
show
Documentation introduced by
The property DateField does not exist on object<EmailReminder_NotificationSchedule>. 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...
431
            } else {
432
                return array();
433
            }
434
        }
435
    }
436
437
438
    /**
439
     * @return DataList | null
440
     */
441
    public function CurrentRecords()
442
    {
443
        if ($this->hasValidFields()) {
444
            $className = $this->DataObject;
0 ignored issues
show
Documentation introduced by
The property DataObject does not exist on object<EmailReminder_NotificationSchedule>. 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...
445
446
            // Use StartsWith to match Date and DateTime fields
447
            $records = $className::get()->where($this->whereStatementForDays());
448
            return $records;
449
        }
450
    }
451
452
    /**
453
     * BeforeAfter = 'after'
454
     * Days = 3
455
     * GraceDays = 2
456
     *  -> minDays = -5 days start of day
457
     *  -> maxDays = -3 days end of day
458
     *
459
     * @return string
460
     */
461
    protected function whereStatementForDays()
462
    {
463
        if ($this->hasValidFields()) {
464
            $sign = $this->BeforeAfter == 'before' ? '+' : '-';
0 ignored issues
show
Documentation introduced by
The property BeforeAfter does not exist on object<EmailReminder_NotificationSchedule>. 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...
465
            $graceDays = 10; //Config::inst()->get('EmailReminder_NotificationSchedule', 'grace_days');
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
466
467
            if ($sign == '+') {
468
                $minDays = $sign . ($this->Days - $graceDays) . ' days';
0 ignored issues
show
Documentation introduced by
The property Days does not exist on object<EmailReminder_NotificationSchedule>. 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...
469
                $maxDays = $sign . $this->Days . ' days';
0 ignored issues
show
Documentation introduced by
The property Days does not exist on object<EmailReminder_NotificationSchedule>. 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...
470
                $minDate = date('Y-m-d', strtotime($minDays)).' 00:00:00';
471
                $maxDate = date('Y-m-d', strtotime($maxDays)).' 23:59:59';
472
            } else {
473
                $minDays = $sign . ($this->Days ) . ' days';
0 ignored issues
show
Documentation introduced by
The property Days does not exist on object<EmailReminder_NotificationSchedule>. 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...
474
                $maxDays = $sign . $this->Days - $graceDays . ' days';
0 ignored issues
show
Documentation introduced by
The property Days does not exist on object<EmailReminder_NotificationSchedule>. 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...
475
                //we purposely change these days around here ...
476
                $minDate = date('Y-m-d', strtotime($maxDays)).' 00:00:00';
477
                $maxDate = date('Y-m-d', strtotime($minDays)).' 23:59:59';
478
            }
479
480
            return '("'. $this->DateField.'" BETWEEN \''.$minDate.'\' AND \''.$maxDate.'\')';
0 ignored issues
show
Documentation introduced by
The property DateField does not exist on object<EmailReminder_NotificationSchedule>. 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...
481
        }
482
        return '1 == 2';
483
    }
484
485
    public function sendEmailNow($recordOrEmail)
486
    {
487 View Code Duplication
        if (is_object($recordOrEmail)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
488
            $email_field = $this->EmailField;
0 ignored issues
show
Documentation introduced by
The property EmailField does not exist on object<EmailReminder_NotificationSchedule>. 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...
489
            $email = $recordOrEmail->$email_field;
490
            $record = $recordOrEmail;
0 ignored issues
show
Unused Code introduced by
$record is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
491
        } else {
492
            $email = strtolower(trim($recordOrEmail));
493
            $record = Injector::inst()->get($reminder->DataObject);
0 ignored issues
show
Bug introduced by
The variable $reminder does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Unused Code introduced by
$record is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
494
        }
495
        if (Email::validEmailAddress($email)) {
0 ignored issues
show
Deprecated Code introduced by
The method Email::validEmailAddress() has been deprecated with message: 4.0 Use the "is_valid_address" method instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
496
            $send = true;
0 ignored issues
show
Unused Code introduced by
$send is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
497
            $filter = array(
498
                'EmailTo' => $email,
499
                'EmailReminder_NotificationScheduleID' => $this->ID
500
            );
501
            $logs = EmailReminder_EmailRecord::get()->filter($filter);
502
            $send = true;
503
            foreach ($logs as $log) {
504
                if (! $log->canSendAgain()) {
505
                    $send = false;
506
                    break;
507
                }
508
            }
509
            if ($send) {
510
                $log = EmailReminder_EmailRecord::create($filter);
511
512
                $subject = $this->EmailSubject;
0 ignored issues
show
Documentation introduced by
The property EmailSubject does not exist on object<EmailReminder_NotificationSchedule>. 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...
513
                $email_content = $this->Content;
0 ignored issues
show
Documentation introduced by
The property Content does not exist on object<EmailReminder_NotificationSchedule>. 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...
514
515
                /* Parse HTML like a template, and translate any internal links */
516
                $data = ArrayData::create(array(
517
                    'Content' => $email_content
518
                ));
519
520
                // $email_body = $record->renderWith(SSViewer::fromString($reminder->Content));
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
521
                // echo $record->renderWith('Email_Reminder_Standard_Template');//$email_body;
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
522
                $email = new Email(
523
                    $this->EmailFrom,
0 ignored issues
show
Documentation introduced by
The property EmailFrom does not exist on object<EmailReminder_NotificationSchedule>. 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...
524
                    $email,
525
                    $subject
526
                );
527
528
                $email->setTemplate('Email_Reminder_Standard_Template');
529
530
                $email->populateTemplate($data);
531
532
                $log->IsTestOnly = $isTestOnly;
0 ignored issues
show
Documentation introduced by
The property IsTestOnly does not exist on object<EmailReminder_EmailRecord>. 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 variable $isTestOnly does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
533
                $log->Result = $email->send();
0 ignored issues
show
Documentation introduced by
The property Result does not exist on object<EmailReminder_EmailRecord>. 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...
534
                $log->EmailReminder_NotificationScheduleID = $this->ID;
0 ignored issues
show
Documentation introduced by
The property EmailReminder_NotificationScheduleID does not exist on object<EmailReminder_EmailRecord>. 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...
535
                $log->write();
536
            }
537
        }
538
        return false;
539
    }
540
}
541