EmailReminder_NotificationSchedule   F
last analyzed

Complexity

Total Complexity 81

Size/Duplication

Total Lines 566
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 15

Importance

Changes 0
Metric Value
wmc 81
lcom 2
cbo 15
dl 0
loc 566
rs 2
c 0
b 0
f 0

21 Methods

Rating   Name   Duplication   Size   Complexity  
A i18n_singular_name() 0 4 1
A i18n_plural_name() 0 4 1
A populateDefaults() 0 12 1
A dataObjectOptions() 0 4 1
A emailFieldOptions() 0 4 1
A dateFieldOptions() 0 4 1
B getFieldsFromDataObject() 0 24 8
A hasValidDataObject() 0 4 3
A hasValidDataObjectFields() 0 15 4
A getTitle() 0 6 3
A hasValidFields() 0 13 6
A validate() 0 14 5
A onBeforeWrite() 0 11 3
A onAfterWrite() 0 11 3
A getReplacerObject() 0 6 2
A getMailOutObject() 0 12 3
A SampleFieldDataForRecords() 0 14 3
A CMSEditLink() 0 6 1
C CurrentRecords() 0 57 15
A whereStatementForDays() 0 23 4
D getCMSFields() 0 155 12

How to fix   Complexity   

Complex Class

Complex classes like EmailReminder_NotificationSchedule often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use EmailReminder_NotificationSchedule, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
class EmailReminder_NotificationSchedule extends DataObject
4
{
5
6
    /**
7
     * @var int
8
     */
9
    private static $grace_days = 10;
10
11
    /**
12
     * @var string
13
     */
14
    private static $default_data_object = 'Member';
15
16
    /**
17
     * @var string
18
     */
19
    private static $default_date_field = '';
20
21
    /**
22
     * @var string
23
     */
24
    private static $default_email_field = '';
25
26
    /**
27
     * @var string
28
     */
29
    private static $replaceable_record_fields = array('FirstName', 'Surname', 'Email');
30
31
    /**
32
     * @var string
33
     */
34
    private static $include_method = 'EmailReminderInclude';
35
36
    /**
37
     * @var string
38
     */
39
    private static $exclude_method = 'EmailReminderExclude';
40
41
    /**
42
     * @var string
43
     */
44
    private static $mail_out_class = 'EmailReminder_DailyMailOut';
45
46
    /**
47
     * @var string
48
     */
49
    private static $disabled_checkbox_label = 'Disable';
50
51
    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...
52
    public function i18n_singular_name()
53
    {
54
        return self::$singular_name;
55
    }
56
57
    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...
58
    public function i18n_plural_name()
59
    {
60
        return self::$plural_name;
61
    }
62
63
    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...
64
        'DataObject' => 'Varchar(100)',
65
        'EmailField' => 'Varchar(100)',
66
        'DateField' => 'Varchar(100)',
67
        'Days' => 'Int',
68
        'RepeatDays' => 'Int',
69
        'BeforeAfter' => "Enum('before,after,immediately','before')",
70
        'EmailFrom' => 'Varchar(100)',
71
        'EmailSubject' => 'Varchar(100)',
72
        'Content' => 'HTMLText',
73
        'Disable' => 'Boolean',
74
        'SendTestTo' => 'Text'
75
    );
76
77
78
    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...
79
        'EmailsSent' => 'EmailReminder_EmailRecord'
80
    );
81
82
    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...
83
        'EmailSubject',
84
        'BeforeAfter',
85
        'Days'
86
    );
87
88
    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...
89
        'DataObject' => 'Class/Table',
90
        'Days' => 'Days Before/After Date',
91
        'RepeatDays' => 'Repeat cycle days',
92
        'BeforeAfter' => 'When to send'
93
    );
94
95
    public function populateDefaults()
96
    {
97
        parent::populateDefaults();
98
        $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...
99
        $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...
100
        $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...
101
        $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...
102
        $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...
103
        $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...
104
        $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...
105
        $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...
106
    }
107
108
    public function getCMSFields()
109
    {
110
        $fields = parent::getCMSFields();
111
112
        $emailsSentField = $fields->dataFieldByName('EmailsSent');
113
        $fields->removeFieldFromTab('Root', 'EmailsSent');
114
115
        $disableLabel = $this->Config()->get('disabled_checkbox_label');
116
        $fields->addFieldToTab(
117
            'Root.Main',
118
            CheckboxField::create('Disable', $disableLabel)->setDescription("If checked this email will not be sent during the daily mail out, however it can still be sent programatically")
119
        );
120
        $fields->addFieldToTab(
121
            'Root.Main',
122
            $dataObjecField = DropdownField::create(
123
                'DataObject',
124
                'Table/Class Name',
125
                $this->dataObjectOptions()
126
            )
127
            ->setRightTitle('Type a valid table/class name')
128
        );
129
        if ($this->Config()->get('default_data_object')) {
130
            $fields->replaceField('DataObject', $dataObjecField->performReadonlyTransformation());
131
        }
132
133
134
135
        $fields->addFieldToTab(
136
            'Root.Main',
137
            $emailFieldField = DropdownField::create(
138
                'EmailField',
139
                'Email Field',
140
                $this->emailFieldOptions()
141
            )
142
            ->setRightTitle('Select the field that will contain a valid email address')
143
            ->setEmptyString('[ Please select ]')
144
        );
145
        if ($this->Config()->get('default_email_field')) {
146
            $fields->replaceField('EmailField', $emailFieldField->performReadonlyTransformation());
147
        }
148
149
        $fields->addFieldToTab(
150
            'Root.Main',
151
            $dateFieldField = DropdownField::create(
152
                'DateField',
153
                'Date Field',
154
                $this->dateFieldOptions()
155
            )
156
            ->setRightTitle('Select a valid Date field to calculate when reminders should be sent')
157
            ->setEmptyString('[ Please select ]')
158
        );
159
        if ($this->Config()->get('default_date_field')) {
160
            $fields->replaceField('DateField', $dateFieldField->performReadonlyTransformation());
161
        }
162
163
        $fields->removeFieldsFromTab(
164
            'Root.Main',
165
            array('Days', 'BeforeAfter', 'RepeatDays')
166
        );
167
        $fields->addFieldsToTab(
168
            'Root.Main',
169
            array(
170
                DropdownField::create('BeforeAfter', 'Before / After Expiration', array('before' => 'before', 'after' => 'after', 'immediately' => 'immediately'))
171
                    ->setRightTitle('Are the days listed above before or after the actual expiration date.'),
172
                NumericField::create('Days', 'Days')
173
                    ->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.'),
174
                NumericField::create('RepeatDays', 'Repeat Cycle Days')
175
                    ->setRightTitle(
176
                        '
177
                        Number of days after which the same reminder can be sent to the same email address.
178
                        <br />We allow an e-mail to be sent to one specific email address for one specific reminder only once.
179
                        <br />In this field you can indicate for how long we will apply this rule.'
180
                )
181
            )
182
        );
183
184
        if ($this->BeforeAfter === 'immediately') {
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...
185
            $fields->removeFieldsFromTab(
186
                'Root.Main',
187
                array('Days', 'RepeatDays')
188
            );
189
        }
190
191
        $fields->addFieldsToTab(
192
            'Root.EmailContent',
193
            array(
194
                TextField::create('EmailFrom', 'Email From Address')
195
                    ->setRightTitle('The email from address, eg: "My Company &lt;[email protected]&gt;"'),
196
                $subjectField = TextField::create('EmailSubject', 'Email Subject Line')
197
                    ->setRightTitle('The subject of the email'),
198
                $contentField = HTMLEditorField::create('Content', 'Email Content')
199
                    ->SetRows(20)
200
            )
201
        );
202
        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...
203
            $html = $obj->replaceHelpList($asHTML = true);
204
            $otherFieldsThatCanBeUsed = $this->getFieldsFromDataObject(array('*'));
205
            $replaceableFields = $this->Config()->get('replaceable_record_fields');
206
            if (count($otherFieldsThatCanBeUsed)) {
207
                $html .= '<h3>You can also use the record fields (not replaced in tests):</h3><ul>';
208
                foreach ($otherFieldsThatCanBeUsed as $key => $value) {
209
                    if (in_array($key, $replaceableFields)) {
210
                        $html .= '<li><strong>$'.$key.'</strong> <span>'.$value.'</span></li>';
211
                    }
212
                }
213
            }
214
            $html .= '</ul>';
215
            $subjectField->setRightTitle('for replacement options, please see below ...');
216
            $contentField->setRightTitle($html);
217
        }
218
        $fields->addFieldsToTab(
219
            'Root.Sent',
220
            array(
221
                TextareaField::create('SendTestTo', 'Send test email to ...')
222
                    ->setRightTitle(
223
                        '
224
                        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
225
                        '
226
                    )
227
                    ->SetRows(3)
228
            )
229
        );
230
        if ($emailsSentField) {
231
            $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...
232
            $config->removeComponentsByType('GridFieldAddExistingAutocompleter');
233
            $fields->addFieldToTab(
234
                'Root.Sent',
235
                $emailsSentField
236
            );
237
        }
238
        $records = $this->CurrentRecords();
239
        if ($records && !$this->Disable) {
0 ignored issues
show
Bug introduced by
The property Disable does not seem to exist. Did you mean disabled_checkbox_label?

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

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

Loading history...
240
            $fields->addFieldsToTab(
241
                'Root.Review',
242
                array(
243
                    GridField::create(
244
                        'CurrentRecords',
245
                        'Today we are sending to ...',
246
                        $records
247
                    ),
248
                    LiteralField::create(
249
                        'SampleSelectStatement',
250
                        '<h3>Here is a sample statement used to select records:</h3>
251
                        <pre>'.$this->whereStatementForDays().'</pre>'
252
                    ),
253
                    LiteralField::create(
254
                        'SampleFieldDataForRecords',
255
                        '<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...
256
                        <li>'.implode('</li><li>', $this->SampleFieldDataForRecords()).'</li>'
257
                    )
258
                )
259
            );
260
        }
261
        return $fields;
262
    }
263
264
    /**
265
     * @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...
266
     */
267
    protected function dataObjectOptions()
268
    {
269
        return ClassInfo::subclassesFor("DataObject");
270
    }
271
272
    /**
273
     * @return array
274
     */
275
    protected function emailFieldOptions()
276
    {
277
        return $this->getFieldsFromDataObject(array('Varchar', 'Email'));
278
    }
279
280
    /**
281
     * @return array
282
     */
283
    protected function dateFieldOptions()
284
    {
285
        return $this->getFieldsFromDataObject(array('Date'));
286
    }
287
288
289
    /**
290
     * list of database fields available
291
     * @param  array $fieldTypeMatchArray - strpos filter
292
     * @return array
293
     */
294
    protected function getFieldsFromDataObject($fieldTypeMatchArray = array())
295
    {
296
        $array = array();
297
        if ($this->hasValidDataObject()) {
298
            $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...
299
            if ($object) {
300
                $allOptions = $object->stat('db');
301
                $fieldLabels = $object->fieldLabels();
302
                foreach ($allOptions as $fieldName => $fieldType) {
303
                    foreach ($fieldTypeMatchArray as $matchString) {
304
                        if ((strpos($fieldType, $matchString) !== false) || $matchString == '*') {
305
                            if (isset($fieldLabels[$fieldName])) {
306
                                $label = $fieldLabels[$fieldName];
307
                            } else {
308
                                $label = $fieldName;
309
                            }
310
                            $array[$fieldName] = $label;
311
                        }
312
                    }
313
                }
314
            }
315
        }
316
        return $array;
317
    }
318
319
320
    /**
321
     * Test if valid classname has been set
322
     * @param null
323
     * @return Boolean
324
     */
325
    public function hasValidDataObject()
326
    {
327
        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...
328
    }
329
330
    /**
331
     * Test if valid fields have been set
332
     * @param null
333
     * @return Boolean
334
     */
335
    public function hasValidDataObjectFields()
336
    {
337
        if (!$this->hasValidDataObject()) {
338
            return false;
339
        }
340
        $emailFieldOptions = $this->emailFieldOptions();
341
        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...
342
            return false;
343
        }
344
        $dateFieldOptions = $this->dateFieldOptions();
345
        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...
346
            return false;
347
        }
348
        return true;
349
    }
350
351
    /**
352
     * @return string
353
     */
354
    public function getTitle()
355
    {
356
        $niceTitle = '[' . $this->EmailSubject . '] // send ';
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...
357
        $niceTitle .= ($this->BeforeAfter === 'immediately') ?  $this->BeforeAfter : $this->Days . ' days '.$this->BeforeAfter.' Expiration Date';
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...
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...
358
        return ($this->hasValidDataObjectFields()) ? $niceTitle : 'uncompleted';
359
    }
360
361
    /**
362
     * @return boolean
363
     */
364
    public function hasValidFields()
365
    {
366
        if (!$this->hasValidDataObject()) {
367
            return false;
368
        }
369
        if (!$this->hasValidDataObjectFields()) {
370
            return false;
371
        }
372
        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...
373
            return true;
374
        }
375
        return false;
376
    }
377
378
    /**
379
     * @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...
380
     */
381
    public function validate()
382
    {
383
        $valid = parent::validate();
384
        if ($this->exists()) {
385
            if (! $this->hasValidDataObject()) {
386
                $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...
387
            } elseif (! $this->hasValidDataObjectFields()) {
388
                $valid->error('Please select valid fields for both Email & Date');
389
            } elseif (! $this->hasValidFields()) {
390
                $valid->error('Please fill in all fields.  Make sure not to forget the email details (from who, subject, content)');
391
            }
392
        }
393
        return $valid;
394
    }
395
396
    public function onBeforeWrite()
397
    {
398
        parent::onBeforeWrite();
399
        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...
400
            $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...
401
        }
402
403
        if ($this->BeforeAfter === 'immediately') {
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...
404
            $this->Days = 0;
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...
405
        }
406
    }
407
408
    public function onAfterWrite()
409
    {
410
        parent::onAfterWrite();
411
        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...
412
            if ($mailOutObject = $this->getMailOutObject()) {
413
                $mailOutObject->setTestOnly(true);
414
                $mailOutObject->setVerbose(true);
415
                $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...
416
            }
417
        }
418
    }
419
420
    /**
421
     *
422
     * @return null | EmailReminder_ReplacerClassInterface
423
     */
424
    public function getReplacerObject()
425
    {
426
        if ($mailOutObject = $this->getMailOutObject()) {
427
            return $mailOutObject->getReplacerObject();
428
        }
429
    }
430
431
    /**
432
     *
433
     * @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...
434
     */
435
    public function getMailOutObject()
436
    {
437
        $mailOutClass = $this->Config()->get('mail_out_class');
438
        if (class_exists($mailOutClass)) {
439
            $obj = Injector::inst()->get($mailOutClass);
440
            if ($obj instanceof BuildTask) {
441
                return $obj;
442
            } else {
443
                user_error($mailOutClass.' needs to be an instance of a Scheduled Task');
444
            }
445
        }
446
    }
447
448
    /**
449
     * @param int $limit
450
     * @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...
451
     */
452
    public function SampleFieldDataForRecords($limit = 200)
453
    {
454
        if ($this->hasValidFields()) {
455
            $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...
456
            $objects = $className::get()->sort('RAND()')
457
                ->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...
458
                ->limit($limit);
459
            if ($objects->count()) {
460
                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...
461
            } else {
462
                return array();
463
            }
464
        }
465
    }
466
467
    public function CMSEditLink()
468
    {
469
        $controller = singleton("EmailReminder_ModelAdmin");
470
471
        return $controller->Link().$this->ClassName."/EditForm/field/".$this->ClassName."/item/".$this->ID."/edit";
472
    }
473
474
475
    /**
476
     * @return DataList | null
477
     */
478
    public function CurrentRecords()
479
    {
480
        if ($this->hasValidFields()) {
481
            $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...
482
483
            // Use StartsWith to match Date and DateTime fields
484
            $records = $className::get()->where($this->whereStatementForDays());
485
            //sample record
486
            $firstRecord = $records->first();
487
            if ($firstRecord && $firstRecord->exists()) {
488
                //methods
489
                $includeMethod = $this->Config()->get('include_method');
490
                $excludeMethod = $this->Config()->get('exclude_method');
491
492
                //included method?
493
                $hasIncludeMethod = false;
494
                if ($firstRecord->hasMethod($includeMethod)) {
495
                    $includedRecords = [0 => 0];
496
                    $hasIncludeMethod = true;
497
                }
498
499
                //excluded method?
500
                $hasExcludeMethod = false;
501
                if ($firstRecord->hasMethod($excludeMethod)) {
502
                    $excludedRecords = [0 => 0];
503
                    $hasExcludeMethod = true;
504
                }
505
506
                //see who is in and out
507
                if ($hasIncludeMethod || $hasExcludeMethod) {
508
                    foreach ($records as $record) {
509
                        if ($hasIncludeMethod) {
510
                            $in = $record->$includeMethod($this, $records);
511
                            if ($in == true) {
512
                                $includedRecords[$record->ID] = $record->ID;
0 ignored issues
show
Bug introduced by
The variable $includedRecords does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
513
                            }
514
                        }
515
                        if ($hasExcludeMethod) {
516
                            $out = $record->$excludeMethod($this, $records);
517
                            if ($out == true) {
518
                                $excludedRecords[$record->ID] = $record->ID;
0 ignored issues
show
Bug introduced by
The variable $excludedRecords does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
519
                            }
520
                        }
521
                    }
522
                }
523
524
                //apply inclusions and exclusions
525
                if ($hasIncludeMethod) {
526
                    $records = $className::get()->filter(['ID' => $includedRecords]);
527
                }
528
                if ($hasExcludeMethod) {
529
                    $records = $records->exclude(['ID' => $excludedRecords]);
530
                }
531
            }
532
            return $records;
533
        }
534
    }
535
536
    /**
537
     * BeforeAfter = 'after'
538
     * Days = 3
539
     * GraceDays = 2
540
     *  -> minDays = -5 days start of day
541
     *  -> maxDays = -3 days end of day
542
     *
543
     * @return string
544
     */
545
    protected function whereStatementForDays()
546
    {
547
        if ($this->hasValidFields()) {
548
            $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...
549
            $graceDays = Config::inst()->get('EmailReminder_NotificationSchedule', 'grace_days');
550
551
            if ($sign == '+') {
552
                $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...
553
                $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...
554
                $minDate = date('Y-m-d', strtotime($minDays)).' 00:00:00';
555
                $maxDate = date('Y-m-d', strtotime($maxDays)).' 23:59:59';
556
            } else {
557
                $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...
558
                $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...
559
                //we purposely change these days around here ...
560
                $minDate = date('Y-m-d', strtotime($maxDays)).' 00:00:00';
561
                $maxDate = date('Y-m-d', strtotime($minDays)).' 23:59:59';
562
            }
563
564
            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...
565
        }
566
        return '1 == 2';
567
    }
568
}
569