Completed
Push — master ( 521ac8...a48538 )
by Nicolaas
03:37
created

OrderStep::HideFromEveryone()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * @description: see OrderStep.md
5
 *
6
 *
7
 * @authors: Nicolaas [at] Sunny Side Up .co.nz
8
 * @package: ecommerce
9
 * @sub-package: model
10
 * @inspiration: Silverstripe Ltd, Jeremy
11
 **/
12
class OrderStep extends DataObject implements EditableEcommerceObject
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...
13
{
14
15
16
    /**
17
     * standard SS variable.
18
     *
19
     * @return array
20
     */
21
    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...
22
        'Name' => 'Varchar(50)',
23
        'Code' => 'Varchar(50)',
24
        'Description' => 'Text',
25
        'EmailSubject' => 'Varchar(200)',
26
        'CustomerMessage' => 'HTMLText',
27
        //customer privileges
28
        'CustomerCanEdit' => 'Boolean',
29
        'CustomerCanCancel' => 'Boolean',
30
        'CustomerCanPay' => 'Boolean',
31
        //What to show the customer...
32
        'ShowAsUncompletedOrder' => 'Boolean',
33
        'ShowAsInProcessOrder' => 'Boolean',
34
        'ShowAsCompletedOrder' => 'Boolean',
35
        'HideStepFromCustomer' => 'Boolean',
36
        //sorting index
37
        'Sort' => 'Int',
38
        'DeferTimeInSeconds' => 'Int',
39
        'DeferFromSubmitTime' => 'Boolean'
40
    );
41
42
43
44
    /**
45
     * standard SS variable.
46
     *
47
     * @return array
48
     */
49
    private static $indexes = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $indexes 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...
50
        'Code' => true,
51
        'Sort' => true,
52
    );
53
54
    /**
55
     * standard SS variable.
56
     *
57
     * @return array
58
     */
59
    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...
60
        'Orders' => 'Order',
61
        'OrderEmailRecords' => 'OrderEmailRecord',
62
    );
63
64
    /**
65
     * standard SS variable.
66
     *
67
     * @return array
68
     */
69
    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...
70
        'Sort' => 'Sorting Index',
71
        'CustomerCanEdit' => 'Customer can edit order',
72
        'CustomerCanPay' => 'Customer can pay order',
73
        'CustomerCanCancel' => 'Customer can cancel order',
74
    );
75
76
    /**
77
     * standard SS variable.
78
     *
79
     * @return array
80
     */
81
    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...
82
        'NameAndDescription' => 'Step',
83
        'ShowAsSummary' => 'Phase',
84
    );
85
86
    /**
87
     * standard SS variable.
88
     *
89
     * @return array
90
     */
91
    private static $casting = 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 $casting 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...
92
        'Title' => 'Varchar',
93
        'CustomerCanEditNice' => 'Varchar',
94
        'CustomerCanPayNice' => 'Varchar',
95
        'CustomerCanCancelNice' => 'Varchar',
96
        'ShowAsUncompletedOrderNice' => 'Varchar',
97
        'ShowAsInProcessOrderNice' => 'Varchar',
98
        'ShowAsCompletedOrderNice' => 'Varchar',
99
        'HideStepFromCustomerNice' => 'Varchar',
100
        'HasCustomerMessageNice' => 'Varchar',
101
        'ShowAsSummary' => 'HTMLText',
102
        'NameAndDescription' => 'HTMLText'
103
    );
104
105
    /**
106
     * standard SS variable.
107
     *
108
     * @return array
109
     */
110
    private static $searchable_fields = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $searchable_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...
111
        'Name' => array(
112
            'title' => 'Name',
113
            'filter' => 'PartialMatchFilter',
114
        ),
115
        'Code' => array(
116
            'title' => 'Code',
117
            'filter' => 'PartialMatchFilter',
118
        ),
119
    );
120
121
122
    /**
123
     * casted variable.
124
     *
125
     * @return string
126
     */
127
    public function Title()
128
    {
129
        return $this->getTitle();
130
    }
131
    public function getTitle()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
132
    {
133
        return $this->Name;
0 ignored issues
show
Documentation introduced by
The property Name does not exist on object<OrderStep>. 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...
134
    }
135
136
    /**
137
     * casted variable.
138
     *
139
     * @return string
140
     */
141
    public function CustomerCanEditNice()
142
    {
143
        return $this->getCustomerCanEditNice();
144
    }
145
    public function getCustomerCanEditNice()
146
    {
147
        if ($this->CustomerCanEdit) {
0 ignored issues
show
Documentation introduced by
The property CustomerCanEdit does not exist on object<OrderStep>. 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...
148
            return _t('OrderStep.YES', 'Yes');
149
        }
150
151
        return _t('OrderStep.NO', 'No');
152
    }
153
154
    /**
155
     * casted variable.
156
     *
157
     * @return string
158
     */
159
    public function CustomerCanPayNice()
160
    {
161
        return $this->getCustomerCanPayNice();
162
    }
163
    public function getCustomerCanPayNice()
164
    {
165
        if ($this->CustomerCanPay) {
0 ignored issues
show
Documentation introduced by
The property CustomerCanPay does not exist on object<OrderStep>. 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...
166
            return _t('OrderStep.YES', 'Yes');
167
        }
168
169
        return _t('OrderStep.NO', 'No');
170
    }
171
172
    /**
173
     * casted variable.
174
     *
175
     * @return string
176
     */
177
    public function CustomerCanCancelNice()
178
    {
179
        return $this->getCustomerCanCancelNice();
180
    }
181
    public function getCustomerCanCancelNice()
182
    {
183
        if ($this->CustomerCanCancel) {
0 ignored issues
show
Documentation introduced by
The property CustomerCanCancel does not exist on object<OrderStep>. 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...
184
            return _t('OrderStep.YES', 'Yes');
185
        }
186
187
        return _t('OrderStep.NO', 'No');
188
    }
189
190
    public function ShowAsUncompletedOrderNice()
191
    {
192
        return $this->getShowAsUncompletedOrderNice();
193
    }
194
    public function getShowAsUncompletedOrderNice()
195
    {
196
        if ($this->ShowAsUncompletedOrder) {
0 ignored issues
show
Documentation introduced by
The property ShowAsUncompletedOrder does not exist on object<OrderStep>. 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...
197
            return _t('OrderStep.YES', 'Yes');
198
        }
199
200
        return _t('OrderStep.NO', 'No');
201
    }
202
203
    /**
204
     * casted variable.
205
     *
206
     * @return string
207
     */
208
    public function ShowAsInProcessOrderNice()
209
    {
210
        return $this->getShowAsInProcessOrderNice();
211
    }
212
    public function getShowAsInProcessOrderNice()
213
    {
214
        if ($this->ShowAsInProcessOrder) {
0 ignored issues
show
Documentation introduced by
The property ShowAsInProcessOrder does not exist on object<OrderStep>. 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...
215
            return _t('OrderStep.YES', 'Yes');
216
        }
217
218
        return _t('OrderStep.NO', 'No');
219
    }
220
221
    /**
222
     * casted variable.
223
     *
224
     * @return string
225
     */
226
    public function ShowAsCompletedOrderNice()
227
    {
228
        return $this->getShowAsCompletedOrderNice();
229
    }
230
    public function getShowAsCompletedOrderNice()
231
    {
232
        if ($this->ShowAsCompletedOrder) {
0 ignored issues
show
Documentation introduced by
The property ShowAsCompletedOrder does not exist on object<OrderStep>. 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...
233
            return _t('OrderStep.YES', 'Yes');
234
        }
235
236
        return _t('OrderStep.NO', 'No');
237
    }
238
239
    /**
240
     * do not show in steps at all.
241
     * @return boolean
242
     */
243
    public function HideFromEveryone()
244
    {
245
        return false;
246
    }
247
248
    /**
249
     * casted variable.
250
     *
251
     * @return string
252
     */
253
    public function HideStepFromCustomerNice()
254
    {
255
        return $this->getHideStepFromCustomerNice();
256
    }
257
258
    public function getHideStepFromCustomerNice()
259
    {
260
        if ($this->HideStepFromCustomer) {
0 ignored issues
show
Documentation introduced by
The property HideStepFromCustomer does not exist on object<OrderStep>. 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...
261
            return _t('OrderStep.YES', 'Yes');
262
        }
263
264
        return _t('OrderStep.NO', 'No');
265
    }
266
267
    /**
268
     * standard SS variable.
269
     *
270
     * @return string
271
     */
272
    private static $singular_name = 'Order Step';
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 $singular_name 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...
273
    public function i18n_singular_name()
274
    {
275
        return _t('OrderStep.ORDERSTEP', 'Order Step');
276
    }
277
278
    /**
279
     * standard SS variable.
280
     *
281
     * @return string
282
     */
283
    private static $plural_name = 'Order Steps';
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 $plural_name 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...
284
    public function i18n_plural_name()
285
    {
286
        return _t('OrderStep.ORDERSTEPS', 'Order Steps');
287
    }
288
289
    /**
290
     * Standard SS variable.
291
     *
292
     * @var string
293
     */
294
    private static $description = 'A step that any order goes through.';
0 ignored issues
show
Unused Code introduced by
The property $description 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...
295
296
    /**
297
     * SUPER IMPORTANT TO KEEP ORDER!
298
     * standard SS variable.
299
     *
300
     * @return string
301
     */
302
    private static $default_sort = '"Sort" ASC';
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 $default_sort 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...
303
304
    /**
305
     * returns all the order steps
306
     * that the admin should / can edit....
307
     *
308
     * @return DataList
309
     */
310
    public static function admin_manageable_steps()
311
    {
312
        $lastStep = OrderStep::get()->Last();
313
        return OrderStep::get()->filter(array('CustomerCanEdit' => 0))->exclude(array('ID' => $lastStep->ID));
314
    }
315
316
    /**
317
     * return StatusIDs (orderstep IDs) from orders that are bad....
318
     * (basically StatusID values that do not exist)
319
     *
320
     * @return array
321
     */
322
    public static function bad_order_step_ids()
323
    {
324
        $badorderStatus = Order::get()
325
            ->leftJoin('OrderStep', '"OrderStep"."ID" = "Order"."StatusID"')
326
            ->where('"OrderStep"."ID" IS NULL AND "StatusID" > 0')
327
            ->column('StatusID');
328
        if (is_array($badorderStatus)) {
329
            return array_unique(array_values($badorderStatus));
330
        } else {
331
            return array(-1);
332
        }
333
    }
334
335
    /**
336
     * turns code into ID.
337
     *
338
     * @param string $code
339
     * @param int
340
     */
341
    public static function get_status_id_from_code($code)
342
    {
343
        $otherStatus = OrderStep::get()
344
            ->filter(array('Code' => $code))
345
            ->First();
346
        if ($otherStatus) {
347
            return $otherStatus->ID;
348
        }
349
350
        return 0;
351
    }
352
353
    /**
354
     *@return array
355
     **/
356
    public static function get_codes_for_order_steps_to_include()
357
    {
358
        $newArray = array();
359
        $array = EcommerceConfig::get('OrderStep', 'order_steps_to_include');
360
        if (is_array($array) && count($array)) {
361
            foreach ($array as $className) {
362
                $code = singleton($className)->getMyCode();
363
                $newArray[$className] = strtoupper($code);
364
            }
365
        }
366
367
        return $newArray;
368
    }
369
370
    /**
371
     * returns a list of ordersteps that have not been created yet.
372
     *
373
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|double|string|boolean|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...
374
     **/
375
    public static function get_not_created_codes_for_order_steps_to_include()
376
    {
377
        $array = EcommerceConfig::get('OrderStep', 'order_steps_to_include');
378
        if (is_array($array) && count($array)) {
379
            foreach ($array as $className) {
380
                $obj = $className::get()->First();
381
                if ($obj) {
382
                    unset($array[$className]);
383
                }
384
            }
385
        }
386
387
        return $array;
388
    }
389
390
    /**
391
     *@return string
392
     **/
393
    public function getMyCode()
394
    {
395
        $array = Config::inst()->get($this->ClassName, 'defaults', Config::UNINHERITED);
396
        if (!isset($array['Code'])) {
397
            user_error($this->class.' does not have a default code specified');
398
        }
399
400
        return $array['Code'];
401
    }
402
403
    /**
404
     * IMPORTANT:: MUST HAVE Code must be defined!!!
405
     * standard SS variable.
406
     *
407
     * @return array
408
     */
409
    private static $defaults = 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 $defaults 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...
410
        'CustomerCanEdit' => 0,
411
        'CustomerCanCancel' => 0,
412
        'CustomerCanPay' => 1,
413
        'ShowAsUncompletedOrder' => 0,
414
        'ShowAsInProcessOrder' => 0,
415
        'ShowAsCompletedOrder' => 0,
416
        'Code' => 'ORDERSTEP',
417
    );
418
419
    /**
420
     * standard SS method.
421
     */
422
    public function populateDefaults()
423
    {
424
        parent::populateDefaults();
425
        $this->Description = $this->myDescription();
0 ignored issues
show
Bug introduced by
The property Description does not seem to exist. Did you mean description?

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...
426
    }
427
428
    /**
429
     *@return FieldList
430
     **/
431
    public function getCMSFields()
432
    {
433
        $fields = parent::getCMSFields();
434
        //replacing
435
        if ($this->canBeDefered()) {
436
            if ($this->DeferTimeInSeconds) {
0 ignored issues
show
Documentation introduced by
The property DeferTimeInSeconds does not exist on object<OrderStep>. 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...
437
                $fields->addFieldToTab(
438
                    'Root.Queue',
439
                    HeaderField::create(
440
                        'WhenWillThisRun',
441
                        $this->humanReadeableDeferTimeInSeconds()
442
                    )
443
                );
444
            }
445
            $fields->addFieldToTab(
446
                'Root.Queue',
447
                $deferTimeInSecondsField = TextField::create(
448
                    'DeferTimeInSeconds',
449
                    _t('OrderStep.DeferTimeInSeconds', 'Seconds in queue')
450
                )
451
                ->setRightTitle(
452
                    _t(
453
                        'OrderStep.TIME_EXPLANATION',
454
                        '86,400 seconds is one day ...
455
                        <br />To make it easier, you can also enter things like <em>1 week</em>, <em>3 hours</em>, or <em>7 minutes</em>.
456
                        <br />Non-second entries will automatically be converted to seconds.'
457
                    )
458
                )
459
            );
460
            if ($this->DeferTimeInSeconds) {
0 ignored issues
show
Documentation introduced by
The property DeferTimeInSeconds does not exist on object<OrderStep>. 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
                $fields->addFieldToTab(
462
                    'Root.Queue',
463
                    $deferTimeInSecondsField = CheckboxField::create(
464
                        'DeferFromSubmitTime',
465
                        _t('OrderStep.DeferFromSubmitTime', 'Calculated from submit time?')
466
                    )
467
                    ->setDescription(
468
                        _t(
469
                            'OrderStep.DeferFromSubmitTime_HELP',
470
                            'The time in the queue can be calculated from the moment the current orderstep starts or from the moment the order was submitted (in this case, check the box above) '
471
                            )
472
                        )
473
                );
474
            }
475
        }
476
        if ($this->hasCustomerMessage()) {
477
            $rightTitle = _t(
478
                'OrderStep.EXPLAIN_ORDER_NUMBER_IN_SUBJECT',
479
                'You can use [OrderNumber] as a tag that will be replaced with the actual Order Number.'
480
            );
481
            $fields->addFieldToTab(
482
                'Root.CustomerMessage',
483
                TextField::create('EmailSubject', _t('OrderStep.EMAILSUBJECT', 'Email Subject'))
484
                    ->setRightTitle($rightTitle)
485
            );
486
            if ($testEmailLink = $this->testEmailLink()) {
487
                $fields->addFieldToTab('Root.CustomerMessage', new LiteralField('testEmailLink', '<h3><a href="'.$testEmailLink.'" data-popup="true" target="_blank">'._t('OrderStep.VIEW_EMAIL_EXAMPLE', 'View email example in browser').'</a></h3>'));
488
            }
489
490
            $fields->addFieldToTab('Root.CustomerMessage', $htmlEditorField = new HTMLEditorField('CustomerMessage', _t('OrderStep.CUSTOMERMESSAGE', 'Customer Message (if any)')));
491
        } else {
492
            $fields->removeFieldFromTab('Root', 'OrderEmailRecords');
493
            $fields->removeFieldFromTab('Root.Main', 'EmailSubject');
494
            $fields->removeFieldFromTab('Root.Main', 'CustomerMessage');
495
        }
496
        //adding
497
        if (!$this->exists() || !$this->isDefaultStatusOption()) {
498
            $fields->removeFieldFromTab('Root.Main', 'Code');
499
            $fields->addFieldToTab('Root.Main', new DropdownField('ClassName', _t('OrderStep.TYPE', 'Type'), self::get_not_created_codes_for_order_steps_to_include()), 'Name');
500
        }
501
        if ($this->isDefaultStatusOption()) {
502
            $fields->replaceField('Code', $fields->dataFieldByName('Code')->performReadonlyTransformation());
503
        }
504
        //headers
505
        $fields->addFieldToTab('Root.Main', new HeaderField('WARNING1', _t('OrderStep.CAREFUL', 'CAREFUL! please edit details below with care'), 2), 'Description');
506
        $fields->addFieldToTab('Root.Main', new HeaderField('WARNING2', _t('OrderStep.CUSTOMERCANCHANGE', 'What can be changed during this step?'), 3), 'CustomerCanEdit');
507
        $fields->addFieldToTab('Root.Main', new HeaderField('WARNING5', _t('OrderStep.ORDERGROUPS', 'Order groups for customer?'), 3), 'ShowAsUncompletedOrder');
508
        $fields->addFieldToTab('Root.Main', new HeaderField('HideStepFromCustomerHeader', _t('OrderStep.HIDE_STEP_FROM_CUSTOMER_HEADER', 'Customer Interaction'), 3), 'HideStepFromCustomer');
509
        //final cleanup
510
        $fields->removeFieldFromTab('Root.Main', 'Sort');
511
        $fields->addFieldToTab('Root.Main', new TextareaField('Description', _t('OrderStep.DESCRIPTION', 'Explanation for internal use only')), 'WARNING1');
512
513
        return $fields;
514
    }
515
516
    /**
517
     * link to edit the record.
518
     *
519
     * @param string | Null $action - e.g. edit
520
     *
521
     * @return string
522
     */
523
    public function CMSEditLink($action = null)
524
    {
525
        return Controller::join_links(
526
            Director::baseURL(),
527
            '/admin/shop/'.$this->ClassName.'/EditForm/field/'.$this->ClassName.'/item/'.$this->ID.'/',
528
            $action
529
        );
530
    }
531
532
    /**
533
     * tells the order to display itself with an alternative display page.
534
     * in that way, orders can be displayed differently for certain steps
535
     * for example, in a print step, the order can be displayed in a
536
     * PRINT ONLY format.
537
     *
538
     * When the method return null, the order is displayed using the standard display page
539
     *
540
     * @see Order::DisplayPage
541
     *
542
     * @return null|object (Page)
543
     **/
544
    public function AlternativeDisplayPage()
545
    {
546
        return;
547
    }
548
549
    /**
550
     * Allows the opportunity for the Order Step to add any fields to Order::getCMSFields
551
     * Usually this is added before ActionNextStepManually.
552
     *
553
     * @param FieldList $fields
554
     * @param Order     $order
555
     *
556
     * @return FieldList
557
     **/
558
    public function addOrderStepFields(FieldList $fields, Order $order)
559
    {
560
        return $fields;
561
    }
562
563
    /**
564
     *@return ValidationResult
565
     **/
566
    public function validate()
567
    {
568
        $result = parent::validate();
569
        $anotherOrderStepWithSameNameOrCode = OrderStep::get()
570
            ->filter(
571
                array(
572
                    'Name' => $this->Name,
0 ignored issues
show
Documentation introduced by
The property Name does not exist on object<OrderStep>. 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...
573
                    'Code' => strtoupper($this->Code),
0 ignored issues
show
Documentation introduced by
The property Code does not exist on object<OrderStep>. 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...
574
                )
575
            )
576
            ->exclude(array('ID' => intval($this->ID)))
577
            ->First();
578
        if ($anotherOrderStepWithSameNameOrCode) {
579
            $result->error(_t('OrderStep.ORDERSTEPALREADYEXISTS', 'An order status with this name already exists. Please change the name and try again.'));
580
        }
581
582
        return $result;
583
    }
584
585
/**************************************************
586
* moving between statusses...
587
**************************************************/
588
    /**
589
     *initStep:
590
     * makes sure the step is ready to run.... (e.g. check if the order is ready to be emailed as receipt).
591
     * should be able to run this function many times to check if the step is ready.
592
     *
593
     * @see Order::doNextStatus
594
     *
595
     * @param Order object
596
     *
597
     * @return bool - true if the current step is ready to be run...
598
     **/
599
    public function initStep(Order $order)
600
    {
601
        user_error('Please implement the initStep method in a subclass ('.get_class().') of OrderStep', E_USER_WARNING);
602
603
        return true;
604
    }
605
606
    /**
607
     *doStep:
608
     * should only be able to run this function once
609
     * (init stops you from running it twice - in theory....)
610
     * runs the actual step.
611
     *
612
     * @see Order::doNextStatus
613
     *
614
     * @param Order object
615
     *
616
     * @return bool - true if run correctly.
617
     **/
618
    public function doStep(Order $order)
619
    {
620
        user_error('Please implement the initStep method in a subclass ('.get_class().') of OrderStep', E_USER_WARNING);
621
622
        return true;
623
    }
624
625
    /**
626
     * nextStep:
627
     * returns the next step (after it checks if everything is in place for the next step to run...).
628
     *
629
     * @see Order::doNextStatus
630
     *
631
     * @param Order $order
632
     *
633
     * @return OrderStep | Null (next step OrderStep object)
0 ignored issues
show
Documentation introduced by
Should the return type not be OrderStep|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...
634
     **/
635
    public function nextStep(Order $order)
636
    {
637
        $nextOrderStepObject = OrderStep::get()
638
            ->filter(array('Sort:GreaterThan' => $this->Sort))
0 ignored issues
show
Documentation introduced by
The property Sort does not exist on object<OrderStep>. 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...
639
            ->First();
640
        if ($nextOrderStepObject) {
641
            return $nextOrderStepObject;
642
        }
643
644
        return;
645
    }
646
647
/**************************************************
648
* Boolean checks
649
**************************************************/
650
651
    /**
652
     * Checks if a step has passed (been completed) in comparison to the current step.
653
     *
654
     * @param string $code:       the name of the step to check
0 ignored issues
show
Bug introduced by
There is no parameter named $code:. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
655
     * @param bool   $orIsEqualTo if set to true, this method will return TRUE if the step being checked is the current one
656
     *
657
     * @return bool
658
     **/
659
    public function hasPassed($code, $orIsEqualTo = false)
660
    {
661
        $otherStatus = OrderStep::get()
662
            ->filter(array('Code' => $code))
663
            ->First();
664
        if ($otherStatus) {
665
            if ($otherStatus->Sort < $this->Sort) {
0 ignored issues
show
Documentation introduced by
The property Sort does not exist on object<OrderStep>. 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...
666
                return true;
667
            }
668
            if ($orIsEqualTo && $otherStatus->Code == $this->Code) {
0 ignored issues
show
Documentation introduced by
The property Code does not exist on object<OrderStep>. 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...
669
                return true;
670
            }
671
        } else {
672
            user_error("could not find $code in OrderStep", E_USER_NOTICE);
673
        }
674
675
        return false;
676
    }
677
678
    /**
679
     * @param string $code
680
     *
681
     * @return bool
682
     **/
683
    public function hasPassedOrIsEqualTo($code)
684
    {
685
        return $this->hasPassed($code, true);
686
    }
687
688
    /**
689
     * @param string $code
690
     *
691
     * @return bool
692
     **/
693
    public function hasNotPassed($code)
694
    {
695
        return (bool) !$this->hasPassed($code, true);
696
    }
697
698
    /**
699
     * Opposite of hasPassed.
700
     *
701
     * @param string $code
702
     *
703
     * @return bool
704
     **/
705
    public function isBefore($code)
706
    {
707
        return (bool) $this->hasPassed($code, false) ? false : true;
708
    }
709
710
    /**
711
     *@return bool
712
     **/
713
    protected function isDefaultStatusOption()
714
    {
715
        return in_array($this->Code, self::get_codes_for_order_steps_to_include());
0 ignored issues
show
Documentation introduced by
The property Code does not exist on object<OrderStep>. 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...
716
    }
717
718
/**************************************************
719
* Email
720
**************************************************/
721
722
    /**
723
     * @var string
724
     */
725
    protected $emailClassName = '';
726
727
    /**
728
     * returns the email class used for emailing the
729
     * customer during a specific step (IF ANY!).
730
     *
731
     * @return string
732
     */
733
    public function getEmailClassName()
734
    {
735
        return $this->emailClassName;
736
    }
737
738
    /**
739
     * return true if done already or mailed successfully now.
740
     *
741
     * @param order         $order
742
     * @param string        $subject
743
     * @param string        $message
744
     * @param bool          $resend
745
     * @param bool | string $adminOnlyOrToEmail you can set to false = send to customer, true: send to admin, or email = send to email
746
     * @param string        $emailClassName
747
     *
748
     * @return boolean;
0 ignored issues
show
Documentation introduced by
The doc-type boolean; could not be parsed: Expected "|" or "end of type", but got ";" at position 7. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
749
     */
750
    protected function sendEmailForStep(
751
        $order,
752
        $subject,
753
        $message = '',
754
        $resend = false,
755
        $adminOnlyOrToEmail = false,
756
        $emailClassName = ''
757
    ) {
758
        if (!$this->hasBeenSent($order) || $resend) {
759
            if (!$subject) {
760
                $subject = $this->EmailSubject;
0 ignored issues
show
Documentation introduced by
The property EmailSubject does not exist on object<OrderStep>. 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...
761
            }
762
            if (!$emailClassName) {
763
                $emailClassName = $this->getEmailClassName();
764
            }
765
            $adminOnlyOrToEmailIsEmail = $adminOnlyOrToEmail && filter_var($adminOnlyOrToEmail, FILTER_VALIDATE_EMAIL);
766
            if ($this->hasCustomerMessage() || $adminOnlyOrToEmailIsEmail) {
767
                return $order->sendEmail(
768
                    $subject,
769
                    $message,
770
                    $resend,
771
                    $adminOnlyOrToEmail,
772
                    $emailClassName
773
                );
774
            } else {
775
                if (!$emailClassName) {
776
                    $emailClassName = 'Order_ErrorEmail';
777
                }
778
                //looks like we are sending an error, but we are just using this for notification
779
                $message = _t('OrderStep.THISMESSAGENOTSENTTOCUSTOMER', 'NOTE: This message was not sent to the customer.').'<br /><br /><br /><br />'.$message;
780
                $outcome = $order->sendAdminNotification(
781
                    $subject,
782
                    $message,
783
                    $resend,
784
                    $emailClassName
785
                );
786
            }
787
            if ($outcome || Director::isDev()) {
0 ignored issues
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return $outcome || \Director::isDev();.
Loading history...
788
                return true;
789
            }
790
791
            return false;
792
        }
793
794
        return true;
795
    }
796
797
    /**
798
     * sets the email class used for emailing the
799
     * customer during a specific step (IF ANY!).
800
     *
801
     * @param string
802
     */
803
    public function setEmailClassName($s)
804
    {
805
        $this->emailClassName = $s;
806
    }
807
808
    /**
809
     * returns a link that can be used to test
810
     * the email being sent during this step
811
     * this method returns NULL if no email
812
     * is being sent OR if there is no suitable Order
813
     * to test with...
814
     *
815
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be string|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...
816
     */
817
    protected function testEmailLink()
818
    {
819
        if ($this->getEmailClassName()) {
820
            $orders = Order::get()
821
                ->where('"OrderStep"."Sort" >= '.$this->Sort)
0 ignored issues
show
Documentation introduced by
The property Sort does not exist on object<OrderStep>. 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...
822
                ->sort('IF("OrderStep"."Sort" > '.$this->Sort.', 0, 1) ASC, "OrderStep"."Sort" ASC, RAND() ASC')
0 ignored issues
show
Documentation introduced by
The property Sort does not exist on object<OrderStep>. 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...
823
                ->innerJoin('OrderStep', '"OrderStep"."ID" = "Order"."StatusID"');
824
            if ($orders->count()) {
825
                if ($order = $orders->First()) {
826
                    return OrderConfirmationPage::get_email_link($order->ID, $this->getEmailClassName(), $actuallySendEmail = false, $alternativeOrderStepID = $this->ID);
827
                }
828
            }
829
        }
830
    }
831
832
    /**
833
     * Has an email been sent to the customer for this
834
     * order step.
835
     *"-10 days".
836
     *
837
     * @param Order $order
838
     * @param bool  $checkDateOfOrder
839
     *
840
     * @return bool
841
     **/
842
    public function hasBeenSent(Order $order, $checkDateOfOrder = true)
843
    {
844
        //if it has been more than a XXX days since the order was last edited (submitted) then we do not send emails as
845
        //this would be embarrasing.
846
        if ($checkDateOfOrder) {
847
            if ($log = $order->SubmissionLog()) {
848
                $lastEditedValue = $log->LastEdited;
849
            } else {
850
                $lastEditedValue = $order->LastEdited;
851
            }
852
            if ((strtotime($lastEditedValue) < strtotime('-'.EcommerceConfig::get('OrderStep', 'number_of_days_to_send_update_email').' days'))) {
853
                return true;
854
            }
855
        }
856
        $count = OrderEmailRecord::get()
857
            ->Filter(array(
858
                'OrderID' => $order->ID,
859
                'OrderStepID' => $this->ID,
860
                'Result' => 1,
861
            ))
862
            ->count();
863
864
        return $count ? true : false;
865
    }
866
867
    /**
868
     * For some ordersteps this returns true...
869
     *
870
     * @return bool
871
     **/
872
    protected function hasCustomerMessage()
873
    {
874
        return false;
875
    }
876
877
878
    /**
879
     * Formatted answer for "hasCustomerMessage".
880
     *
881
     * @return string
882
     */
883
    public function HasCustomerMessageNice()
884
    {
885
        return $this->getHasCustomerMessageNice();
886
    }
887
    public function getHasCustomerMessageNice()
888
    {
889
        return $this->hasCustomerMessage() ?  _t('OrderStep.YES', 'Yes') :  _t('OrderStep.NO', 'No');
890
    }
891
892
    /**
893
     * Formatted answer for "hasCustomerMessage".
894
     *
895
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be DBField?

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...
896
     */
897
    public function ShowAsSummary()
898
    {
899
        return $this->getShowAsSummary();
900
    }
901
902
    /**
903
     *
904
     *
905
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be DBField?

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...
906
     */
907
    public function getShowAsSummary()
908
    {
909
        $v = '<strong>';
910
        if ($this->ShowAsUncompletedOrder) {
0 ignored issues
show
Documentation introduced by
The property ShowAsUncompletedOrder does not exist on object<OrderStep>. 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...
911
            $v .= _t('OrderStep.UNCOMPLETED', 'Uncompleted');
912
        } elseif ($this->ShowAsInProcessOrder) {
0 ignored issues
show
Documentation introduced by
The property ShowAsInProcessOrder does not exist on object<OrderStep>. 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...
913
            $v .= _t('OrderStep.INPROCESS', 'In process');
914
        } elseif ($this->ShowAsCompletedOrder) {
0 ignored issues
show
Documentation introduced by
The property ShowAsCompletedOrder does not exist on object<OrderStep>. 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...
915
            $v .= _t('OrderStep.COMPLETED', 'Completed');
916
        }
917
        $v .= '</strong>';
918
        $canArray = array();
919
        if ($this->CustomerCanEdit) {
0 ignored issues
show
Documentation introduced by
The property CustomerCanEdit does not exist on object<OrderStep>. 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...
920
            $canArray[] = _t('OrderStep.EDITABLE', 'edit');
921
        }
922
        if ($this->CustomerCanPay) {
0 ignored issues
show
Documentation introduced by
The property CustomerCanPay does not exist on object<OrderStep>. 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...
923
            $canArray[] = _t('OrderStep.PAY', 'pay');
924
        }
925
        if ($this->CustomerCanCancel) {
0 ignored issues
show
Documentation introduced by
The property CustomerCanCancel does not exist on object<OrderStep>. 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...
926
            $canArray[] = _t('OrderStep.CANCEL', 'cancel');
927
        }
928
        if (count($canArray)) {
929
            $v .=  '<br />'._t('OrderStep.CUSTOMER_CAN', 'Customer Can').': '.implode(', ', $canArray).'';
930
        }
931
        if ($this->hasCustomerMessage()) {
932
            $v .= '<br />'._t('OrderStep.CUSTOMER_MESSAGES', 'Includes message to customer');
933
        }
934
        if ($this->DeferTimeInSeconds) {
0 ignored issues
show
Documentation introduced by
The property DeferTimeInSeconds does not exist on object<OrderStep>. 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...
935
            $v .= '<br />'.$this->humanReadeableDeferTimeInSeconds();
936
        }
937
938
        return DBField::create_field('HTMLText', $v);
939
    }
940
941
    /**
942
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be string|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...
943
     */
944
    protected function humanReadeableDeferTimeInSeconds()
945
    {
946
        if ($this->canBeDefered()) {
947
            $field = DBField::create_field('SS_DateTime', strtotime('+ '.$this->DeferTimeInSeconds.' seconds'));
0 ignored issues
show
Documentation introduced by
The property DeferTimeInSeconds does not exist on object<OrderStep>. 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...
948
            $descr0 = _t('OrderStep.THE', 'The').' '.'<span style="color: #338DC1">'.$this->getTitle().'</span>';
949
            $descr1 = _t('OrderStep.DELAY_VALUE', 'Order Step, for any order, will run');
950
            $descr2 = $field->ago();
951
            $descr3 = $this->DeferFromSubmitTime ?
0 ignored issues
show
Documentation introduced by
The property DeferFromSubmitTime does not exist on object<OrderStep>. 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...
952
                    _t('OrderStep.FROM_ORDER_SUBMIT_TIME', 'from the order being submitted') :
953
                    _t('OrderStep.FROM_START_OF_ORDSTEP', 'from the order arriving on this step');
954
            return $descr0. ' ' . $descr1.' <span style="color: #338DC1">'.$descr2.'</span> '.$descr3.'.';
955
        }
956
        // $dtF = new \DateTime('@0');
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
957
        // $dtT = new \DateTime("@".$this->DeferTimeInSeconds);
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
958
        //
959
        // return $dtF->diff($dtT)->format('%a days, %h hours, %i minutes and %s seconds');
0 ignored issues
show
Unused Code Comprehensibility introduced by
74% 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...
960
    }
961
962
    /**
963
     * Formatted answer for "hasCustomerMessage".
964
     *
965
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be DBField?

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...
966
     */
967
    public function NameAndDescription()
968
    {
969
        return $this->getNameAndDescription();
970
    }
971
972
    public function getNameAndDescription()
973
    {
974
        $v = '<strong>'.$this->Name.'</strong><br /><em>'.$this->Description.'</em>';
0 ignored issues
show
Documentation introduced by
The property Name does not exist on object<OrderStep>. 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...
Bug introduced by
The property Description does not seem to exist. Did you mean description?

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...
975
976
        return DBField::create_field('HTMLText', $v);
977
    }
978
979
    /**
980
     * This allows you to set the time to something other than the standard DeferTimeInSeconds
981
     * value based on the order provided.
982
     *
983
     * @param Order
984
     *
985
     * @return int
986
     */
987
    public function CalculatedDeferTimeInSeconds($order)
0 ignored issues
show
Unused Code introduced by
The parameter $order is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
988
    {
989
        return $this->DeferTimeInSeconds;
0 ignored issues
show
Documentation introduced by
The property DeferTimeInSeconds does not exist on object<OrderStep>. 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...
990
    }
991
992
    /**
993
     * can this order step be delayed?
994
     * in general, if there is a customer message
995
     * we should be able to delay it
996
     *
997
     * This method can be overridden in any orderstep
998
     * @return bool
999
     **/
1000
    protected function canBeDefered()
1001
    {
1002
        return $this->hasCustomerMessage();
1003
    }
1004
1005
1006
/**************************************************
1007
* Order Status Logs
1008
**************************************************/
1009
1010
    /**
1011
     * The OrderStatusLog that is relevant to the particular step.
1012
     *
1013
     * @var string
1014
     */
1015
    protected $relevantLogEntryClassName = '';
1016
1017
    /**
1018
     * @return string
1019
     */
1020
    public function getRelevantLogEntryClassName()
1021
    {
1022
        return $this->relevantLogEntryClassName;
1023
    }
1024
1025
    /**
1026
     * @param string
1027
     */
1028
    public function setRelevantLogEntryClassName($s)
1029
    {
1030
        $this->relevantLogEntryClassName = $s;
1031
    }
1032
1033
    /**
1034
     * returns the OrderStatusLog that is relevant to this step.
1035
     *
1036
     * @param Order $order
1037
     *
1038
     * @return OrderStatusLog | null
1039
     */
1040
    public function RelevantLogEntry(Order $order)
1041
    {
1042
        if ($className = $this->getRelevantLogEntryClassName()) {
0 ignored issues
show
Unused Code introduced by
$className 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...
1043
            return $this->RelevantLogEntries($order)->Last();
1044
        }
1045
    }
1046
1047
    /**
1048
     * returns the OrderStatusLogs that are relevant to this step.
1049
     *
1050
     * @param Order $order
1051
     *
1052
     * @return DataObjectSet | null
1053
     */
1054
    public function RelevantLogEntries(Order $order)
1055
    {
1056
        if ($className = $this->getRelevantLogEntryClassName()) {
1057
            return $className::get()->filter(array('OrderID' => $order->ID));
1058
        }
1059
    }
1060
1061
/**************************************************
1062
* Silverstripe Standard Data Object Methods
1063
**************************************************/
1064
1065
    /**
1066
     * Standard SS method
1067
     * These are only created programmatically.
1068
     *
1069
     * @param Member $member
0 ignored issues
show
Documentation introduced by
Should the type for parameter $member not be Member|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
1070
     *
1071
     * @return bool
1072
     */
1073
    public function canCreate($member = null)
1074
    {
1075
        return false;
1076
    }
1077
1078
    /**
1079
     * Standard SS method.
1080
     *
1081
     * @param Member $member
0 ignored issues
show
Documentation introduced by
Should the type for parameter $member not be Member|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
1082
     *
1083
     * @return bool
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|string|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...
1084
     */
1085
    public function canView($member = null)
1086
    {
1087
        if (! $member) {
1088
            $member = Member::currentUser();
1089
        }
1090
        $extended = $this->extendedCan(__FUNCTION__, $member);
0 ignored issues
show
Documentation introduced by
$member is of type object<DataObject>|null, but the function expects a object<Member>|integer.

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...
1091
        if ($extended !== null) {
1092
            return $extended;
1093
        }
1094
        if (Permission::checkMember($member, Config::inst()->get('EcommerceRole', 'admin_permission_code'))) {
1095
            return true;
1096
        }
1097
1098
        return parent::canEdit($member);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (canEdit() instead of canView()). Are you sure this is correct? If so, you might want to change this to $this->canEdit().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
Bug introduced by
It seems like $member defined by \Member::currentUser() on line 1088 can also be of type object<DataObject>; however, DataObject::canEdit() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
1099
    }
1100
1101
    /**
1102
     * the default for this is TRUE, but for completed order steps
1103
     *
1104
     * we do not allow this.
1105
     *
1106
     * @param  Order $order
1107
     * @param  Member $member optional
0 ignored issues
show
Documentation introduced by
Should the type for parameter $member not be Member|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
1108
     * @return bool
1109
     */
1110
    public function canOverrideCanViewForOrder($order, $member = null)
0 ignored issues
show
Unused Code introduced by
The parameter $order is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $member is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1111
    {
1112
        //return true if the order can have customer input
1113
        // orders recently saved can also be views
1114
        return
1115
            $this->CustomerCanEdit ||
0 ignored issues
show
Documentation introduced by
The property CustomerCanEdit does not exist on object<OrderStep>. 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...
1116
            $this->CustomerCanCancel ||
0 ignored issues
show
Documentation introduced by
The property CustomerCanCancel does not exist on object<OrderStep>. 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...
1117
            $this->CustomerCanPay;
0 ignored issues
show
Documentation introduced by
The property CustomerCanPay does not exist on object<OrderStep>. 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...
1118
    }
1119
1120
    /**
1121
     * standard SS method.
1122
     *
1123
     * @param Member | NULL
1124
     *
1125
     * @return bool
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|string|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...
1126
     */
1127
    public function canEdit($member = null)
1128
    {
1129
        if (! $member) {
1130
            $member = Member::currentUser();
1131
        }
1132
        $extended = $this->extendedCan(__FUNCTION__, $member);
1133
        if ($extended !== null) {
1134
            return $extended;
1135
        }
1136
        if (Permission::checkMember($member, Config::inst()->get('EcommerceRole', 'admin_permission_code'))) {
1137
            return true;
1138
        }
1139
1140
        return parent::canEdit($member);
1141
    }
1142
1143
    /**
1144
     * Standard SS method.
1145
     *
1146
     * @param Member $member
0 ignored issues
show
Documentation introduced by
Should the type for parameter $member not be Member|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
1147
     *
1148
     * @return bool
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|string|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...
1149
     */
1150
    public function canDelete($member = null)
1151
    {
1152
        //cant delete last status if there are orders with this status
1153
        $nextOrderStepObject = $this->NextOrderStep();
1154
        if ($nextOrderStepObject) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
1155
            //do nothing
1156
        } else {
1157
            $orderCount = Order::get()
1158
                ->filter(array('StatusID' => intval($this->ID) - 0))
1159
                ->count();
1160
            if ($orderCount) {
1161
                return false;
1162
            }
1163
        }
1164
        if ($this->isDefaultStatusOption()) {
1165
            return false;
1166
        }
1167
        if (! $member) {
1168
            $member = Member::currentUser();
1169
        }
1170
        $extended = $this->extendedCan(__FUNCTION__, $member);
0 ignored issues
show
Documentation introduced by
$member is of type object<DataObject>|null, but the function expects a object<Member>|integer.

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...
1171
        if ($extended !== null) {
1172
            return $extended;
1173
        }
1174
        if (Permission::checkMember($member, Config::inst()->get('EcommerceRole', 'admin_permission_code'))) {
1175
            return true;
1176
        }
1177
1178
        return parent::canEdit($member);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (canEdit() instead of canDelete()). Are you sure this is correct? If so, you might want to change this to $this->canEdit().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
Bug introduced by
It seems like $member defined by \Member::currentUser() on line 1168 can also be of type object<DataObject>; however, DataObject::canEdit() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
1179
    }
1180
1181
    /**
1182
     * standard SS method.
1183
     */
1184
    public function onBeforeWrite()
1185
    {
1186
        parent::onBeforeWrite();
1187
        //make sure only one of three conditions applies ...
1188
        if ($this->ShowAsUncompletedOrder) {
0 ignored issues
show
Documentation introduced by
The property ShowAsUncompletedOrder does not exist on object<OrderStep>. 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...
1189
            $this->ShowAsInProcessOrder = false;
0 ignored issues
show
Documentation introduced by
The property ShowAsInProcessOrder does not exist on object<OrderStep>. 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...
1190
            $this->ShowAsCompletedOrder = false;
0 ignored issues
show
Documentation introduced by
The property ShowAsCompletedOrder does not exist on object<OrderStep>. 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...
1191
        } elseif ($this->ShowAsInProcessOrder) {
0 ignored issues
show
Documentation introduced by
The property ShowAsInProcessOrder does not exist on object<OrderStep>. 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...
1192
            $this->ShowAsUncompletedOrder = false;
0 ignored issues
show
Documentation introduced by
The property ShowAsUncompletedOrder does not exist on object<OrderStep>. 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...
1193
            $this->ShowAsCompletedOrder = false;
0 ignored issues
show
Documentation introduced by
The property ShowAsCompletedOrder does not exist on object<OrderStep>. 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...
1194
        } elseif ($this->ShowAsCompletedOrder) {
0 ignored issues
show
Documentation introduced by
The property ShowAsCompletedOrder does not exist on object<OrderStep>. 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...
1195
            $this->ShowAsUncompletedOrder = false;
0 ignored issues
show
Documentation introduced by
The property ShowAsUncompletedOrder does not exist on object<OrderStep>. 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...
1196
            $this->ShowAsInProcessOrder = false;
0 ignored issues
show
Documentation introduced by
The property ShowAsInProcessOrder does not exist on object<OrderStep>. 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...
1197
        }
1198
        if (! $this->canBeDefered()) {
1199
            $this->DeferTimeInSeconds = 0;
0 ignored issues
show
Documentation introduced by
The property DeferTimeInSeconds does not exist on object<OrderStep>. 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...
1200
            $this->DeferFromSubmitTime = 0;
0 ignored issues
show
Documentation introduced by
The property DeferFromSubmitTime does not exist on object<OrderStep>. 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...
1201
        } else {
1202
            if (is_numeric($this->DeferTimeInSeconds)) {
0 ignored issues
show
Documentation introduced by
The property DeferTimeInSeconds does not exist on object<OrderStep>. 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...
1203
                $this->DeferTimeInSeconds = intval($this->DeferTimeInSeconds);
0 ignored issues
show
Documentation introduced by
The property DeferTimeInSeconds does not exist on object<OrderStep>. 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 DeferTimeInSeconds does not exist on object<OrderStep>. 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...
1204
            } else {
1205
                $this->DeferTimeInSeconds = strtotime('+'.$this->DeferTimeInSeconds);
0 ignored issues
show
Documentation introduced by
The property DeferTimeInSeconds does not exist on object<OrderStep>. 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 DeferTimeInSeconds does not exist on object<OrderStep>. 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...
1206
                if ($this->DeferTimeInSeconds > 0) {
0 ignored issues
show
Documentation introduced by
The property DeferTimeInSeconds does not exist on object<OrderStep>. 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...
1207
                    $this->DeferTimeInSeconds = $this->DeferTimeInSeconds - time();
0 ignored issues
show
Documentation introduced by
The property DeferTimeInSeconds does not exist on object<OrderStep>. 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 DeferTimeInSeconds does not exist on object<OrderStep>. 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...
1208
                }
1209
            }
1210
        }
1211
        $this->Code = strtoupper($this->Code);
0 ignored issues
show
Documentation introduced by
The property Code does not exist on object<OrderStep>. 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 Code does not exist on object<OrderStep>. 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...
1212
    }
1213
1214
    /**
1215
     * move linked orders to the next status
1216
     * standard SS method.
1217
     */
1218
    public function onBeforeDelete()
1219
    {
1220
        parent::onBeforeDelete();
1221
        $previousOrderStepObject = null;
1222
        $nextOrderStepObject = $this->NextOrderStep();
1223
        //backup
1224
        if ($nextOrderStepObject) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
1225
            //do nothing
1226
        } else {
1227
            $previousOrderStepObject = $this->PreviousOrderStep();
1228
        }
1229
        if ($previousOrderStepObject) {
1230
            $ordersWithThisStatus = Order::get()->filter(array('StatusID' => $this->ID));
1231
            if ($ordersWithThisStatus && $ordersWithThisStatus->count()) {
1232
                foreach ($ordersWithThisStatus as $orderWithThisStatus) {
1233
                    $orderWithThisStatus->StatusID = $previousOrderStepObject->ID;
1234
                    $orderWithThisStatus->write();
1235
                }
1236
            }
1237
        }
1238
    }
1239
1240
    /**
1241
     * standard SS method.
1242
     */
1243
    public function onAfterDelete()
1244
    {
1245
        parent::onAfterDelete();
1246
        $this->requireDefaultRecords();
1247
    }
1248
1249
    protected function NextOrderStep()
1250
    {
1251
        return OrderStep::get()
1252
            ->filter(array('Sort:GreaterThan' => $this->Sort))
0 ignored issues
show
Documentation introduced by
The property Sort does not exist on object<OrderStep>. 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...
1253
            ->First();
1254
    }
1255
1256
    protected function PreviousOrderStep()
1257
    {
1258
        return OrderStep::get()
1259
            ->filter(array('Sort:LessThan' => $this->Sort))
0 ignored issues
show
Documentation introduced by
The property Sort does not exist on object<OrderStep>. 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...
1260
            ->First();
1261
    }
1262
1263
    /**
1264
     * standard SS method
1265
     * USED TO BE: Unpaid,Query,Paid,Processing,Sent,Complete,AdminCancelled,MemberCancelled,Cart.
1266
     */
1267
    public function requireDefaultRecords()
1268
    {
1269
        parent::requireDefaultRecords();
1270
        $orderStepsToInclude = EcommerceConfig::get('OrderStep', 'order_steps_to_include');
1271
        $codesToInclude = self::get_codes_for_order_steps_to_include();
1272
        $indexNumber = 0;
1273
        if ($orderStepsToInclude && count($orderStepsToInclude)) {
1274
            if ($codesToInclude && count($codesToInclude)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $codesToInclude of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
1275
                foreach ($codesToInclude as $className => $code) {
1276
                    $code = strtoupper($code);
1277
                    $filter = array('ClassName' => $className);
1278
                    $indexNumber += 10;
1279
                    $itemCount = OrderStep::get()->filter($filter)->Count();
1280
                    if ($itemCount) {
1281
                        $obj = OrderStep::get()->filter($filter)->First();
1282
                        if ($obj->Code != $code) {
1283
                            $obj->Code = $code;
1284
                            $obj->write();
1285
                        }
1286
                        $parentObj = singleton('OrderStep');
1287
                        if ($obj->Description == $parentObj->myDescription()) {
1288
                            $obj->Description = $obj->myDescription();
1289
                            $obj->write();
1290
                        }
1291
                    } else {
1292
                        $obj = $className::create();
1293
                        $obj->Code = $code;
1294
                        $obj->Description = $obj->myDescription();
1295
                        $obj->write();
1296
                        DB::alteration_message("Created \"$code\" as $className.", 'created');
1297
                    }
1298
                    $obj = OrderStep::get()
1299
                        ->filter(array('Code' => strtoupper($code)))
1300
                        ->First();
1301
                    if ($obj) {
1302
                        if ($obj->Sort != $indexNumber) {
1303
                            $obj->Sort = $indexNumber;
1304
                            $obj->write();
1305
                        }
1306
                    } else {
1307
                        user_error("There was an error in creating the $code OrderStep");
1308
                    }
1309
                }
1310
            }
1311
        }
1312
        $steps = OrderStep::get();
1313
        foreach ($steps as $step) {
1314
            if (!$step->Description) {
1315
                $step->Description = $step->myDescription();
1316
                $step->write();
1317
            }
1318
        }
1319
    }
1320
1321
    /**
1322
     * returns the standard EcommerceDBConfig for use within OrderSteps.
1323
     *
1324
     * @return EcommerceDBConfig
1325
     */
1326
    protected function EcomConfig()
1327
    {
1328
        return EcommerceDBConfig::current_ecommerce_db_config();
1329
    }
1330
1331
    /**
1332
     * Explains the current order step.
1333
     *
1334
     * @return string
1335
     */
1336
    protected function myDescription()
1337
    {
1338
        return _t('OrderStep.DESCRIPTION', 'No description has been provided for this step.');
1339
    }
1340
}
1341