Completed
Push — master ( 613b2e...a2195f )
by Nicolaas
03:28
created

OrderStep   F

Complexity

Total Complexity 171

Size/Duplication

Total Lines 1312
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 24

Importance

Changes 0
Metric Value
dl 0
loc 1312
rs 0.5665
c 0
b 0
f 0
wmc 171
lcom 2
cbo 24

71 Methods

Rating   Name   Duplication   Size   Complexity  
A calculateddefertimeinseconds() 0 4 1
A Title() 0 4 1
A getTitle() 0 4 1
A CustomerCanEditNice() 0 4 1
A getCustomerCanEditNice() 0 8 2
A CustomerCanPayNice() 0 4 1
A getCustomerCanPayNice() 0 8 2
A CustomerCanCancelNice() 0 4 1
A getCustomerCanCancelNice() 0 8 2
A ShowAsUncompletedOrderNice() 0 4 1
A getShowAsUncompletedOrderNice() 0 8 2
A ShowAsInProcessOrderNice() 0 4 1
A getShowAsInProcessOrderNice() 0 8 2
A ShowAsCompletedOrderNice() 0 4 1
A getShowAsCompletedOrderNice() 0 8 2
A HideFromEveryone() 0 4 1
A HideStepFromCustomerNice() 0 4 1
A getHideStepFromCustomerNice() 0 8 2
A i18n_singular_name() 0 4 1
A i18n_plural_name() 0 4 1
A admin_manageable_steps() 0 5 1
A bad_order_step_ids() 0 12 2
A get_status_id_from_code() 0 11 2
A get_codes_for_order_steps_to_include() 0 13 4
B get_not_created_codes_for_order_steps_to_include() 0 14 5
A getMyCode() 0 9 2
A populateDefaults() 0 5 1
C getCMSFields() 0 83 9
A CMSEditLink() 0 8 1
A AlternativeDisplayPage() 0 4 1
A addOrderStepFields() 0 4 1
A validate() 0 18 2
A initStep() 0 6 1
A doStep() 0 6 1
A nextStep() 0 11 2
B hasPassed() 0 18 5
A hasPassedOrIsEqualTo() 0 4 1
A hasNotPassed() 0 4 1
A isBefore() 0 4 2
A isDefaultStatusOption() 0 4 1
A getEmailClassName() 0 4 1
C sendEmailForStep() 0 46 11
A setEmailClassName() 0 4 1
A testEmailLink() 0 14 4
B hasBeenSent() 0 24 5
A hasCustomerMessage() 0 4 1
A canBeDefered() 0 4 1
A HasCustomerMessageNice() 0 4 1
A getHasCustomerMessageNice() 0 4 2
A ShowAsSummary() 0 4 1
F getShowAsSummary() 0 33 10
A humanReadeableDeferTimeInSeconds() 0 17 3
A NameAndDescription() 0 4 1
A getNameAndDescription() 0 6 1
A getRelevantLogEntryClassName() 0 4 1
A setRelevantLogEntryClassName() 0 4 1
A RelevantLogEntry() 0 6 2
A RelevantLogEntries() 0 6 2
A canCreate() 0 4 1
A canView() 0 15 4
A canOverrideCanViewForOrder() 0 9 3
A canEdit() 0 15 4
C canDelete() 0 30 7
C onBeforeWrite() 0 29 7
B onBeforeDelete() 0 21 6
A onAfterDelete() 0 5 1
A NextOrderStep() 0 6 1
A PreviousOrderStep() 0 6 1
C requireDefaultRecords() 0 53 13
A EcomConfig() 0 4 1
A myDescription() 0 4 1

How to fix   Complexity   

Complex Class

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

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

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

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
    public function calculateddefertimeinseconds()
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...
15
    {
16
        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...
17
    }
18
19
    /**
20
     * standard SS variable.
21
     *
22
     * @return array
23
     */
24
    private static $db = array(
0 ignored issues
show
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...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
25
        'Name' => 'Varchar(50)',
26
        'Code' => 'Varchar(50)',
27
        'Description' => 'Text',
28
        'EmailSubject' => 'Varchar(200)',
29
        'CustomerMessage' => 'HTMLText',
30
        //customer privileges
31
        'CustomerCanEdit' => 'Boolean',
32
        'CustomerCanCancel' => 'Boolean',
33
        'CustomerCanPay' => 'Boolean',
34
        //What to show the customer...
35
        'ShowAsUncompletedOrder' => 'Boolean',
36
        'ShowAsInProcessOrder' => 'Boolean',
37
        'ShowAsCompletedOrder' => 'Boolean',
38
        'HideStepFromCustomer' => 'Boolean',
39
        //sorting index
40
        'Sort' => 'Int',
41
        'DeferTimeInSeconds' => 'Int',
42
        'DeferFromSubmitTime' => 'Boolean'
43
    );
44
45
46
47
    /**
48
     * standard SS variable.
49
     *
50
     * @return array
51
     */
52
    private static $indexes = array(
0 ignored issues
show
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...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
53
        'Code' => true,
54
        'Sort' => true,
55
    );
56
57
    /**
58
     * standard SS variable.
59
     *
60
     * @return array
61
     */
62
    private static $has_many = array(
0 ignored issues
show
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...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
63
        'Orders' => 'Order',
64
        'OrderEmailRecords' => 'OrderEmailRecord',
65
    );
66
67
    /**
68
     * standard SS variable.
69
     *
70
     * @return array
71
     */
72
    private static $field_labels = array(
0 ignored issues
show
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...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
73
        'Sort' => 'Sorting Index',
74
        'CustomerCanEdit' => 'Customer can edit order',
75
        'CustomerCanPay' => 'Customer can pay order',
76
        'CustomerCanCancel' => 'Customer can cancel order',
77
    );
78
79
    /**
80
     * standard SS variable.
81
     *
82
     * @return array
83
     */
84
    private static $summary_fields = array(
0 ignored issues
show
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...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
85
        'NameAndDescription' => 'Step',
86
        'ShowAsSummary' => 'Phase',
87
    );
88
89
    /**
90
     * standard SS variable.
91
     *
92
     * @return array
93
     */
94
    private static $casting = array(
0 ignored issues
show
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...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
95
        'Title' => 'Varchar',
96
        'CustomerCanEditNice' => 'Varchar',
97
        'CustomerCanPayNice' => 'Varchar',
98
        'CustomerCanCancelNice' => 'Varchar',
99
        'ShowAsUncompletedOrderNice' => 'Varchar',
100
        'ShowAsInProcessOrderNice' => 'Varchar',
101
        'ShowAsCompletedOrderNice' => 'Varchar',
102
        'HideStepFromCustomerNice' => 'Varchar',
103
        'HasCustomerMessageNice' => 'Varchar',
104
        'ShowAsSummary' => 'HTMLText',
105
        'NameAndDescription' => 'HTMLText'
106
    );
107
108
    /**
109
     * standard SS variable.
110
     *
111
     * @return array
112
     */
113
    private static $searchable_fields = array(
0 ignored issues
show
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...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
114
        'Name' => array(
115
            'title' => 'Name',
116
            'filter' => 'PartialMatchFilter',
117
        ),
118
        'Code' => array(
119
            'title' => 'Code',
120
            'filter' => 'PartialMatchFilter',
121
        ),
122
    );
123
124
125
    /**
126
     * casted variable.
127
     *
128
     * @return string
129
     */
130
    public function Title()
131
    {
132
        return $this->getTitle();
133
    }
134
    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...
135
    {
136
        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...
137
    }
138
139
    /**
140
     * casted variable.
141
     *
142
     * @return string
143
     */
144
    public function CustomerCanEditNice()
145
    {
146
        return $this->getCustomerCanEditNice();
147
    }
148
    public function getCustomerCanEditNice()
149
    {
150
        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...
151
            return _t('OrderStep.YES', 'Yes');
152
        }
153
154
        return _t('OrderStep.NO', 'No');
155
    }
156
157
    /**
158
     * casted variable.
159
     *
160
     * @return string
161
     */
162
    public function CustomerCanPayNice()
163
    {
164
        return $this->getCustomerCanPayNice();
165
    }
166
    public function getCustomerCanPayNice()
167
    {
168
        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...
169
            return _t('OrderStep.YES', 'Yes');
170
        }
171
172
        return _t('OrderStep.NO', 'No');
173
    }
174
175
    /**
176
     * casted variable.
177
     *
178
     * @return string
179
     */
180
    public function CustomerCanCancelNice()
181
    {
182
        return $this->getCustomerCanCancelNice();
183
    }
184
    public function getCustomerCanCancelNice()
185
    {
186
        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...
187
            return _t('OrderStep.YES', 'Yes');
188
        }
189
190
        return _t('OrderStep.NO', 'No');
191
    }
192
193
    public function ShowAsUncompletedOrderNice()
194
    {
195
        return $this->getShowAsUncompletedOrderNice();
196
    }
197
    public function getShowAsUncompletedOrderNice()
198
    {
199
        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...
200
            return _t('OrderStep.YES', 'Yes');
201
        }
202
203
        return _t('OrderStep.NO', 'No');
204
    }
205
206
    /**
207
     * casted variable.
208
     *
209
     * @return string
210
     */
211
    public function ShowAsInProcessOrderNice()
212
    {
213
        return $this->getShowAsInProcessOrderNice();
214
    }
215
    public function getShowAsInProcessOrderNice()
216
    {
217
        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...
218
            return _t('OrderStep.YES', 'Yes');
219
        }
220
221
        return _t('OrderStep.NO', 'No');
222
    }
223
224
    /**
225
     * casted variable.
226
     *
227
     * @return string
228
     */
229
    public function ShowAsCompletedOrderNice()
230
    {
231
        return $this->getShowAsCompletedOrderNice();
232
    }
233
    public function getShowAsCompletedOrderNice()
234
    {
235
        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...
236
            return _t('OrderStep.YES', 'Yes');
237
        }
238
239
        return _t('OrderStep.NO', 'No');
240
    }
241
242
    /**
243
     * do not show in steps at all.
244
     * @return boolean
245
     */
246
    public function HideFromEveryone()
247
    {
248
        return false;
249
    }
250
251
    /**
252
     * casted variable.
253
     *
254
     * @return string
255
     */
256
    public function HideStepFromCustomerNice()
257
    {
258
        return $this->getHideStepFromCustomerNice();
259
    }
260
261
    public function getHideStepFromCustomerNice()
262
    {
263
        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...
264
            return _t('OrderStep.YES', 'Yes');
265
        }
266
267
        return _t('OrderStep.NO', 'No');
268
    }
269
270
    /**
271
     * standard SS variable.
272
     *
273
     * @return string
274
     */
275
    private static $singular_name = 'Order Step';
0 ignored issues
show
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...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
276
    public function i18n_singular_name()
277
    {
278
        return _t('OrderStep.ORDERSTEP', 'Order Step');
279
    }
280
281
    /**
282
     * standard SS variable.
283
     *
284
     * @return string
285
     */
286
    private static $plural_name = 'Order Steps';
0 ignored issues
show
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...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
287
    public function i18n_plural_name()
288
    {
289
        return _t('OrderStep.ORDERSTEPS', 'Order Steps');
290
    }
291
292
    /**
293
     * Standard SS variable.
294
     *
295
     * @var string
296
     */
297
    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...
298
299
    /**
300
     * SUPER IMPORTANT TO KEEP ORDER!
301
     * standard SS variable.
302
     *
303
     * @return string
304
     */
305
    private static $default_sort = '"Sort" ASC';
0 ignored issues
show
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...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
306
307
    /**
308
     * returns all the order steps
309
     * that the admin should / can edit....
310
     *
311
     * @return DataList
312
     */
313
    public static function admin_manageable_steps()
314
    {
315
        $lastStep = OrderStep::get()->Last();
316
        return OrderStep::get()->filter(array('CustomerCanEdit' => 0))->exclude(array('ID' => $lastStep->ID));
317
    }
318
319
    /**
320
     * return StatusIDs (orderstep IDs) from orders that are bad....
321
     * (basically StatusID values that do not exist)
322
     *
323
     * @return array
324
     */
325
    public static function bad_order_step_ids()
326
    {
327
        $badorderStatus = Order::get()
328
            ->leftJoin('OrderStep', '"OrderStep"."ID" = "Order"."StatusID"')
329
            ->where('"OrderStep"."ID" IS NULL AND "StatusID" > 0')
330
            ->column('StatusID');
331
        if (is_array($badorderStatus)) {
332
            return array_unique(array_values($badorderStatus));
333
        } else {
334
            return array(-1);
335
        }
336
    }
337
338
    /**
339
     * turns code into ID.
340
     *
341
     * @param string $code
342
     * @param int
343
     */
344
    public static function get_status_id_from_code($code)
345
    {
346
        $otherStatus = OrderStep::get()
347
            ->filter(array('Code' => $code))
348
            ->First();
349
        if ($otherStatus) {
350
            return $otherStatus->ID;
351
        }
352
353
        return 0;
354
    }
355
356
    /**
357
     *@return array
358
     **/
359
    public static function get_codes_for_order_steps_to_include()
360
    {
361
        $newArray = array();
362
        $array = EcommerceConfig::get('OrderStep', 'order_steps_to_include');
363
        if (is_array($array) && count($array)) {
364
            foreach ($array as $className) {
365
                $code = singleton($className)->getMyCode();
366
                $newArray[$className] = strtoupper($code);
367
            }
368
        }
369
370
        return $newArray;
371
    }
372
373
    /**
374
     * returns a list of ordersteps that have not been created yet.
375
     *
376
     * @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...
377
     **/
378
    public static function get_not_created_codes_for_order_steps_to_include()
379
    {
380
        $array = EcommerceConfig::get('OrderStep', 'order_steps_to_include');
381
        if (is_array($array) && count($array)) {
382
            foreach ($array as $className) {
383
                $obj = $className::get()->First();
384
                if ($obj) {
385
                    unset($array[$className]);
386
                }
387
            }
388
        }
389
390
        return $array;
391
    }
392
393
    /**
394
     *@return string
395
     **/
396
    public function getMyCode()
397
    {
398
        $array = Config::inst()->get($this->ClassName, 'defaults', Config::UNINHERITED);
399
        if (!isset($array['Code'])) {
400
            user_error($this->class.' does not have a default code specified');
401
        }
402
403
        return $array['Code'];
404
    }
405
406
    /**
407
     * IMPORTANT:: MUST HAVE Code must be defined!!!
408
     * standard SS variable.
409
     *
410
     * @return array
411
     */
412
    private static $defaults = array(
0 ignored issues
show
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...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
413
        'CustomerCanEdit' => 0,
414
        'CustomerCanCancel' => 0,
415
        'CustomerCanPay' => 1,
416
        'ShowAsUncompletedOrder' => 0,
417
        'ShowAsInProcessOrder' => 0,
418
        'ShowAsCompletedOrder' => 0,
419
        'Code' => 'ORDERSTEP',
420
    );
421
422
    /**
423
     * standard SS method.
424
     */
425
    public function populateDefaults()
426
    {
427
        parent::populateDefaults();
428
        $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...
429
    }
430
431
    /**
432
     *@return FieldList
433
     **/
434
    public function getCMSFields()
435
    {
436
        $fields = parent::getCMSFields();
437
        //replacing
438
        if ($this->canBeDefered()) {
439
            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...
440
                $fields->addFieldToTab(
441
                    'Root.Queue',
442
                    HeaderField::create(
443
                        'WhenWillThisRun',
444
                        $this->humanReadeableDeferTimeInSeconds()
445
                    )
446
                );
447
            }
448
            $fields->addFieldToTab(
449
                'Root.Queue',
450
                $deferTimeInSecondsField = TextField::create(
451
                    'DeferTimeInSeconds',
452
                    _t('OrderStep.DeferTimeInSeconds', 'Seconds in queue')
453
                )
454
                ->setRightTitle(
455
                    _t(
456
                        'OrderStep.TIME_EXPLANATION',
457
                        '86,400 seconds is one day ...
458
                        <br />To make it easier, you can also enter things like <em>1 week</em>, <em>3 hours</em>, or <em>7 minutes</em>.
459
                        <br />Non-second entries will automatically be converted to seconds.'
460
                    )
461
                )
462
            );
463
            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...
464
                $fields->addFieldToTab(
465
                    'Root.Queue',
466
                    $deferTimeInSecondsField = CheckboxField::create(
467
                        'DeferFromSubmitTime',
468
                        _t('OrderStep.DeferFromSubmitTime', 'Calculated from submit time?')
469
                    )
470
                    ->setDescription(
471
                        _t(
472
                            'OrderStep.DeferFromSubmitTime_HELP',
473
                            'The time in the queue can be calculated from the moment the current ordersteps starts or from the moment the order was submitted (in this case, check the box above) '
474
                            )
475
                        )
476
                );
477
            }
478
        }
479
        if ($this->hasCustomerMessage()) {
480
            $rightTitle = _t(
481
                'OrderStep.EXPLAIN_ORDER_NUMBER_IN_SUBJECT',
482
                'You can use [OrderNumber] as a tag that will be replaced with the actual Order Number.'
483
            );
484
            $fields->addFieldToTab(
485
                'Root.CustomerMessage',
486
                TextField::create('EmailSubject', _t('OrderStep.EMAILSUBJECT', 'Email Subject'))
487
                    ->setRightTitle($rightTitle)
488
            );
489
            $fields->addFieldToTab('Root.CustomerMessage', $htmlEditorField = new HTMLEditorField('CustomerMessage', _t('OrderStep.CUSTOMERMESSAGE', 'Customer Message (if any)')));
490
            if ($testEmailLink = $this->testEmailLink()) {
491
                $fields->addFieldToTab('Root.CustomerMessage', new LiteralField('testEmailLink', '<p><a href="'.$testEmailLink.'" data-popup="true">'._t('OrderStep.VIEW_EMAIL_EXAMPLE', 'View email example in browser').'</a></p>'));
492
            }
493
        } else {
494
            $fields->removeFieldFromTab('Root', 'OrderEmailRecords');
495
            $fields->removeFieldFromTab('Root.Main', 'EmailSubject');
496
            $fields->removeFieldFromTab('Root.Main', 'CustomerMessage');
497
        }
498
        //adding
499
        if (!$this->exists() || !$this->isDefaultStatusOption()) {
500
            $fields->removeFieldFromTab('Root.Main', 'Code');
501
            $fields->addFieldToTab('Root.Main', new DropdownField('ClassName', _t('OrderStep.TYPE', 'Type'), self::get_not_created_codes_for_order_steps_to_include()), 'Name');
502
        }
503
        if ($this->isDefaultStatusOption()) {
504
            $fields->replaceField('Code', $fields->dataFieldByName('Code')->performReadonlyTransformation());
505
        }
506
        //headers
507
        $fields->addFieldToTab('Root.Main', new HeaderField('WARNING1', _t('OrderStep.CAREFUL', 'CAREFUL! please edit details below with care'), 2), 'Description');
508
        $fields->addFieldToTab('Root.Main', new HeaderField('WARNING2', _t('OrderStep.CUSTOMERCANCHANGE', 'What can be changed during this step?'), 3), 'CustomerCanEdit');
509
        $fields->addFieldToTab('Root.Main', new HeaderField('WARNING5', _t('OrderStep.ORDERGROUPS', 'Order groups for customer?'), 3), 'ShowAsUncompletedOrder');
510
        $fields->addFieldToTab('Root.Main', new HeaderField('HideStepFromCustomerHeader', _t('OrderStep.HIDE_STEP_FROM_CUSTOMER_HEADER', 'Customer Interaction'), 3), 'HideStepFromCustomer');
511
        //final cleanup
512
        $fields->removeFieldFromTab('Root.Main', 'Sort');
513
        $fields->addFieldToTab('Root.Main', new TextareaField('Description', _t('OrderStep.DESCRIPTION', 'Explanation for internal use only')), 'WARNING1');
514
515
        return $fields;
516
    }
517
518
    /**
519
     * link to edit the record.
520
     *
521
     * @param string | Null $action - e.g. edit
522
     *
523
     * @return string
524
     */
525
    public function CMSEditLink($action = null)
526
    {
527
        return Controller::join_links(
528
            Director::baseURL(),
529
            '/admin/shop/'.$this->ClassName.'/EditForm/field/'.$this->ClassName.'/item/'.$this->ID.'/',
530
            $action
531
        );
532
    }
533
534
    /**
535
     * tells the order to display itself with an alternative display page.
536
     * in that way, orders can be displayed differently for certain steps
537
     * for example, in a print step, the order can be displayed in a
538
     * PRINT ONLY format.
539
     *
540
     * When the method return null, the order is displayed using the standard display page
541
     *
542
     * @see Order::DisplayPage
543
     *
544
     * @return null|object (Page)
545
     **/
546
    public function AlternativeDisplayPage()
547
    {
548
        return;
549
    }
550
551
    /**
552
     * Allows the opportunity for the Order Step to add any fields to Order::getCMSFields
553
     * Usually this is added before ActionNextStepManually.
554
     *
555
     * @param FieldList $fields
556
     * @param Order     $order
557
     *
558
     * @return FieldList
559
     **/
560
    public function addOrderStepFields(FieldList $fields, Order $order)
561
    {
562
        return $fields;
563
    }
564
565
    /**
566
     *@return ValidationResult
567
     **/
568
    public function validate()
569
    {
570
        $result = parent::validate();
571
        $anotherOrderStepWithSameNameOrCode = OrderStep::get()
572
            ->filter(
573
                array(
574
                    '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...
575
                    '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...
576
                )
577
            )
578
            ->exclude(array('ID' => intval($this->ID)))
579
            ->First();
580
        if ($anotherOrderStepWithSameNameOrCode) {
581
            $result->error(_t('OrderStep.ORDERSTEPALREADYEXISTS', 'An order status with this name already exists. Please change the name and try again.'));
582
        }
583
584
        return $result;
585
    }
586
587
/**************************************************
588
* moving between statusses...
589
**************************************************/
590
    /**
591
     *initStep:
592
     * makes sure the step is ready to run.... (e.g. check if the order is ready to be emailed as receipt).
593
     * should be able to run this function many times to check if the step is ready.
594
     *
595
     * @see Order::doNextStatus
596
     *
597
     * @param Order object
598
     *
599
     * @return bool - true if the current step is ready to be run...
600
     **/
601
    public function initStep(Order $order)
602
    {
603
        user_error('Please implement the initStep method in a subclass ('.get_class().') of OrderStep', E_USER_WARNING);
604
605
        return true;
606
    }
607
608
    /**
609
     *doStep:
610
     * should only be able to run this function once
611
     * (init stops you from running it twice - in theory....)
612
     * runs the actual step.
613
     *
614
     * @see Order::doNextStatus
615
     *
616
     * @param Order object
617
     *
618
     * @return bool - true if run correctly.
619
     **/
620
    public function doStep(Order $order)
621
    {
622
        user_error('Please implement the initStep method in a subclass ('.get_class().') of OrderStep', E_USER_WARNING);
623
624
        return true;
625
    }
626
627
    /**
628
     * nextStep:
629
     * returns the next step (after it checks if everything is in place for the next step to run...).
630
     *
631
     * @see Order::doNextStatus
632
     *
633
     * @param Order $order
634
     *
635
     * @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...
636
     **/
637
    public function nextStep(Order $order)
638
    {
639
        $nextOrderStepObject = OrderStep::get()
640
            ->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...
641
            ->First();
642
        if ($nextOrderStepObject) {
643
            return $nextOrderStepObject;
644
        }
645
646
        return;
647
    }
648
649
/**************************************************
650
* Boolean checks
651
**************************************************/
652
653
    /**
654
     * Checks if a step has passed (been completed) in comparison to the current step.
655
     *
656
     * @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...
657
     * @param bool   $orIsEqualTo if set to true, this method will return TRUE if the step being checked is the current one
658
     *
659
     * @return bool
660
     **/
661
    public function hasPassed($code, $orIsEqualTo = false)
662
    {
663
        $otherStatus = OrderStep::get()
664
            ->filter(array('Code' => $code))
665
            ->First();
666
        if ($otherStatus) {
667
            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...
668
                return true;
669
            }
670
            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...
671
                return true;
672
            }
673
        } else {
674
            user_error("could not find $code in OrderStep", E_USER_NOTICE);
675
        }
676
677
        return false;
678
    }
679
680
    /**
681
     * @param string $code
682
     *
683
     * @return bool
684
     **/
685
    public function hasPassedOrIsEqualTo($code)
686
    {
687
        return $this->hasPassed($code, true);
688
    }
689
690
    /**
691
     * @param string $code
692
     *
693
     * @return bool
694
     **/
695
    public function hasNotPassed($code)
696
    {
697
        return (bool) !$this->hasPassed($code, true);
698
    }
699
700
    /**
701
     * Opposite of hasPassed.
702
     *
703
     * @param string $code
704
     *
705
     * @return bool
706
     **/
707
    public function isBefore($code)
708
    {
709
        return (bool) $this->hasPassed($code, false) ? false : true;
710
    }
711
712
    /**
713
     *@return bool
714
     **/
715
    protected function isDefaultStatusOption()
716
    {
717
        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...
718
    }
719
720
/**************************************************
721
* Email
722
**************************************************/
723
724
    /**
725
     * @var string
726
     */
727
    protected $emailClassName = '';
728
729
    /**
730
     * returns the email class used for emailing the
731
     * customer during a specific step (IF ANY!).
732
     *
733
     * @return string
734
     */
735
    public function getEmailClassName()
736
    {
737
        return $this->emailClassName;
738
    }
739
740
    /**
741
     * return true if done already or mailed successfully now.
742
     *
743
     * @param order         $order
744
     * @param string        $subject
745
     * @param string        $message
746
     * @param bool          $resend
747
     * @param bool | string $adminOnlyOrToEmail you can set to false = send to customer, true: send to admin, or email = send to email
748
     * @param string        $emailClassName
749
     *
750
     * @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...
751
     */
752
    protected function sendEmailForStep(
753
        $order,
754
        $subject,
755
        $message = '',
756
        $resend = false,
757
        $adminOnlyOrToEmail = false,
758
        $emailClassName = ''
759
    ) {
760
        if (!$this->hasBeenSent($order) || $resend) {
761
            if (!$subject) {
762
                $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...
763
            }
764
            if (!$emailClassName) {
765
                $emailClassName = $this->getEmailClassName();
766
            }
767
            $adminOnlyOrToEmailIsEmail = $adminOnlyOrToEmail && filter_var($adminOnlyOrToEmail, FILTER_VALIDATE_EMAIL);
768
            if ($this->hasCustomerMessage() || $adminOnlyOrToEmailIsEmail) {
769
                return $order->sendEmail(
770
                    $subject,
771
                    $message,
772
                    $resend,
773
                    $adminOnlyOrToEmail,
774
                    $emailClassName
775
                );
776
            } else {
777
                if (!$emailClassName) {
778
                    $emailClassName = 'Order_ErrorEmail';
779
                }
780
                //looks like we are sending an error, but we are just using this for notification
781
                $message = _t('OrderStep.THISMESSAGENOTSENTTOCUSTOMER', 'NOTE: This message was not sent to the customer.').'<br /><br /><br /><br />'.$message;
782
                $outcome = $order->sendAdminNotification(
783
                    $subject,
784
                    $message,
785
                    $resend,
786
                    $emailClassName
787
                );
788
            }
789
            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...
790
                return true;
791
            }
792
793
            return false;
794
        }
795
796
        return true;
797
    }
798
799
    /**
800
     * sets the email class used for emailing the
801
     * customer during a specific step (IF ANY!).
802
     *
803
     * @param string
804
     */
805
    public function setEmailClassName($s)
806
    {
807
        $this->emailClassName = $s;
808
    }
809
810
    /**
811
     * returns a link that can be used to test
812
     * the email being sent during this step
813
     * this method returns NULL if no email
814
     * is being sent OR if there is no suitable Order
815
     * to test with...
816
     *
817
     * @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...
818
     */
819
    protected function testEmailLink()
820
    {
821
        if ($this->getEmailClassName()) {
822
            $orders = Order::get()
823
                ->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...
824
                ->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...
825
                ->innerJoin('OrderStep', '"OrderStep"."ID" = "Order"."StatusID"');
826
            if ($orders->count()) {
827
                if ($order = $orders->First()) {
828
                    return OrderConfirmationPage::get_email_link($order->ID, $this->getEmailClassName(), $actuallySendEmail = false, $alternativeOrderStepID = $this->ID);
829
                }
830
            }
831
        }
832
    }
833
834
    /**
835
     * Has an email been sent to the customer for this
836
     * order step.
837
     *"-10 days".
838
     *
839
     * @param Order $order
840
     * @param bool  $checkDateOfOrder
841
     *
842
     * @return bool
843
     **/
844
    public function hasBeenSent(Order $order, $checkDateOfOrder = true)
845
    {
846
        //if it has been more than a XXX days since the order was last edited (submitted) then we do not send emails as
847
        //this would be embarrasing.
848
        if ($checkDateOfOrder) {
849
            if ($log = $order->SubmissionLog()) {
850
                $lastEditedValue = $log->LastEdited;
851
            } else {
852
                $lastEditedValue = $order->LastEdited;
853
            }
854
            if ((strtotime($lastEditedValue) < strtotime('-'.EcommerceConfig::get('OrderStep', 'number_of_days_to_send_update_email').' days'))) {
855
                return true;
856
            }
857
        }
858
        $count = OrderEmailRecord::get()
859
            ->Filter(array(
860
                'OrderID' => $order->ID,
861
                'OrderStepID' => $this->ID,
862
                'Result' => 1,
863
            ))
864
            ->count();
865
866
        return $count ? true : false;
867
    }
868
869
    /**
870
     * For some ordersteps this returns true...
871
     *
872
     * @return bool
873
     **/
874
    protected function hasCustomerMessage()
875
    {
876
        return false;
877
    }
878
879
    /**
880
     * can this order step be delayed?
881
     * @return bool
882
     **/
883
    protected function canBeDefered()
884
    {
885
        return $this->hasCustomerMessage();
886
    }
887
888
    /**
889
     * Formatted answer for "hasCustomerMessage".
890
     *
891
     * @return string
892
     */
893
    public function HasCustomerMessageNice()
894
    {
895
        return $this->getHasCustomerMessageNice();
896
    }
897
    public function getHasCustomerMessageNice()
898
    {
899
        return $this->hasCustomerMessage() ?  _t('OrderStep.YES', 'Yes') :  _t('OrderStep.NO', 'No');
900
    }
901
902
    /**
903
     * Formatted answer for "hasCustomerMessage".
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 ShowAsSummary()
908
    {
909
        return $this->getShowAsSummary();
910
    }
911
912
    /**
913
     *
914
     *
915
     * @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...
916
     */
917
    public function getShowAsSummary()
918
    {
919
        $v = '<strong>';
920
        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...
921
            $v .= _t('OrderStep.UNCOMPLETED', 'Uncompleted');
922
        } 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...
923
            $v .= _t('OrderStep.INPROCESS', 'In process');
924
        } 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...
925
            $v .= _t('OrderStep.COMPLETED', 'Completed');
926
        }
927
        $v .= '</strong>';
928
        $canArray = array();
929
        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...
930
            $canArray[] = _t('OrderStep.EDITABLE', 'edit');
931
        }
932
        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...
933
            $canArray[] = _t('OrderStep.PAY', 'pay');
934
        }
935
        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...
936
            $canArray[] = _t('OrderStep.CANCEL', 'cancel');
937
        }
938
        if (count($canArray)) {
939
            $v .=  '<br />'._t('OrderStep.CUSTOMER_CAN', 'Customer Can').': '.implode(', ', $canArray).'';
940
        }
941
        if ($this->hasCustomerMessage()) {
942
            $v .= '<br />'._t('OrderStep.CUSTOMER_MESSAGES', 'Includes message to customer');
943
        }
944
        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...
945
            $v .= '<br />'.$this->humanReadeableDeferTimeInSeconds();
946
        }
947
948
        return DBField::create_field('HTMLText', $v);
949
    }
950
951
    /**
952
     * @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...
953
     */
954
    protected function humanReadeableDeferTimeInSeconds()
955
    {
956
        if ($this->canBeDefered()) {
957
            $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...
958
            $descr0 = _t('OrderStep.THE', 'The').' '.'<span style="color: #338DC1">'.$this->getTitle().'</span>';
959
            $descr1 = _t('OrderStep.DELAY_VALUE', 'Order Step, for any order, will run');
960
            $descr2 = $field->ago();
961
            $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...
962
                    _t('OrderStep.FROM_ORDER_SUBMIT_TIME', 'from the order being submitted') :
963
                    _t('OrderStep.FROM_START_OF_ORDSTEP', 'from the order arriving on this step');
964
            return $descr0. ' ' . $descr1.' <span style="color: #338DC1">'.$descr2.'</span> '.$descr3.'.';
965
        }
966
        // $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...
967
        // $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...
968
        //
969
        // 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...
970
    }
971
972
    /**
973
     * Formatted answer for "hasCustomerMessage".
974
     *
975
     * @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...
976
     */
977
    public function NameAndDescription()
978
    {
979
        return $this->getNameAndDescription();
980
    }
981
982
    public function getNameAndDescription()
983
    {
984
        $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...
985
986
        return DBField::create_field('HTMLText', $v);
987
    }
988
989
/**************************************************
990
* Order Status Logs
991
**************************************************/
992
993
    /**
994
     * The OrderStatusLog that is relevant to the particular step.
995
     *
996
     * @var string
997
     */
998
    protected $relevantLogEntryClassName = '';
999
1000
    /**
1001
     * @return string
1002
     */
1003
    public function getRelevantLogEntryClassName()
1004
    {
1005
        return $this->relevantLogEntryClassName;
1006
    }
1007
1008
    /**
1009
     * @param string
1010
     */
1011
    public function setRelevantLogEntryClassName($s)
1012
    {
1013
        $this->relevantLogEntryClassName = $s;
1014
    }
1015
1016
    /**
1017
     * returns the OrderStatusLog that is relevant to this step.
1018
     *
1019
     * @param Order $order
1020
     *
1021
     * @return OrderStatusLog | null
1022
     */
1023
    public function RelevantLogEntry(Order $order)
1024
    {
1025
        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...
1026
            return $this->RelevantLogEntries($order)->Last();
1027
        }
1028
    }
1029
1030
    /**
1031
     * returns the OrderStatusLogs that are relevant to this step.
1032
     *
1033
     * @param Order $order
1034
     *
1035
     * @return DataObjectSet | null
1036
     */
1037
    public function RelevantLogEntries(Order $order)
1038
    {
1039
        if ($className = $this->getRelevantLogEntryClassName()) {
1040
            return $className::get()->filter(array('OrderID' => $order->ID));
1041
        }
1042
    }
1043
1044
/**************************************************
1045
* Silverstripe Standard Data Object Methods
1046
**************************************************/
1047
1048
    /**
1049
     * Standard SS method
1050
     * These are only created programmatically.
1051
     *
1052
     * @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...
1053
     *
1054
     * @return bool
1055
     */
1056
    public function canCreate($member = null)
1057
    {
1058
        return false;
1059
    }
1060
1061
    /**
1062
     * Standard SS method.
1063
     *
1064
     * @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...
1065
     *
1066
     * @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...
1067
     */
1068
    public function canView($member = null)
1069
    {
1070
        if (! $member) {
1071
            $member = Member::currentUser();
1072
        }
1073
        $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...
1074
        if ($extended !== null) {
1075
            return $extended;
1076
        }
1077
        if (Permission::checkMember($member, Config::inst()->get('EcommerceRole', 'admin_permission_code'))) {
1078
            return true;
1079
        }
1080
1081
        return parent::canEdit($member);
0 ignored issues
show
Bug introduced by
It seems like $member defined by \Member::currentUser() on line 1071 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...
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...
1082
    }
1083
1084
    /**
1085
     * the default for this is TRUE, but for completed order steps
1086
     *
1087
     * we do not allow this.
1088
     *
1089
     * @param  Order $order
1090
     * @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...
1091
     * @return bool
1092
     */
1093
    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...
1094
    {
1095
        //return true if the order can have customer input
1096
        // orders recently saved can also be views
1097
        return
1098
            $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...
1099
            $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...
1100
            $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...
1101
    }
1102
1103
    /**
1104
     * standard SS method.
1105
     *
1106
     * @param Member | NULL
1107
     *
1108
     * @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...
1109
     */
1110
    public function canEdit($member = null)
1111
    {
1112
        if (! $member) {
1113
            $member = Member::currentUser();
1114
        }
1115
        $extended = $this->extendedCan(__FUNCTION__, $member);
1116
        if ($extended !== null) {
1117
            return $extended;
1118
        }
1119
        if (Permission::checkMember($member, Config::inst()->get('EcommerceRole', 'admin_permission_code'))) {
1120
            return true;
1121
        }
1122
1123
        return parent::canEdit($member);
1124
    }
1125
1126
    /**
1127
     * Standard SS method.
1128
     *
1129
     * @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...
1130
     *
1131
     * @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...
1132
     */
1133
    public function canDelete($member = null)
1134
    {
1135
        //cant delete last status if there are orders with this status
1136
        $nextOrderStepObject = $this->NextOrderStep();
1137
        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...
1138
            //do nothing
1139
        } else {
1140
            $orderCount = Order::get()
1141
                ->filter(array('StatusID' => intval($this->ID) - 0))
1142
                ->count();
1143
            if ($orderCount) {
1144
                return false;
1145
            }
1146
        }
1147
        if ($this->isDefaultStatusOption()) {
1148
            return false;
1149
        }
1150
        if (! $member) {
1151
            $member = Member::currentUser();
1152
        }
1153
        $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...
1154
        if ($extended !== null) {
1155
            return $extended;
1156
        }
1157
        if (Permission::checkMember($member, Config::inst()->get('EcommerceRole', 'admin_permission_code'))) {
1158
            return true;
1159
        }
1160
1161
        return parent::canEdit($member);
0 ignored issues
show
Bug introduced by
It seems like $member defined by \Member::currentUser() on line 1151 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...
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...
1162
    }
1163
1164
    /**
1165
     * standard SS method.
1166
     */
1167
    public function onBeforeWrite()
1168
    {
1169
        parent::onBeforeWrite();
1170
        //make sure only one of three conditions applies ...
1171
        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...
1172
            $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...
1173
            $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...
1174
        } 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...
1175
            $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...
1176
            $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...
1177
        } 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...
1178
            $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...
1179
            $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...
1180
        }
1181
        if (! $this->canBeDefered()) {
1182
            $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...
1183
            $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...
1184
        } else {
1185
            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...
1186
                $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...
1187
            } else {
1188
                $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...
1189
                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...
1190
                    $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...
1191
                }
1192
            }
1193
        }
1194
        $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...
1195
    }
1196
1197
    /**
1198
     * move linked orders to the next status
1199
     * standard SS method.
1200
     */
1201
    public function onBeforeDelete()
1202
    {
1203
        parent::onBeforeDelete();
1204
        $previousOrderStepObject = null;
1205
        $nextOrderStepObject = $this->NextOrderStep();
1206
        //backup
1207
        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...
1208
            //do nothing
1209
        } else {
1210
            $previousOrderStepObject = $this->PreviousOrderStep();
1211
        }
1212
        if ($previousOrderStepObject) {
1213
            $ordersWithThisStatus = Order::get()->filter(array('StatusID' => $this->ID));
1214
            if ($ordersWithThisStatus && $ordersWithThisStatus->count()) {
1215
                foreach ($ordersWithThisStatus as $orderWithThisStatus) {
1216
                    $orderWithThisStatus->StatusID = $previousOrderStepObject->ID;
1217
                    $orderWithThisStatus->write();
1218
                }
1219
            }
1220
        }
1221
    }
1222
1223
    /**
1224
     * standard SS method.
1225
     */
1226
    public function onAfterDelete()
1227
    {
1228
        parent::onAfterDelete();
1229
        $this->requireDefaultRecords();
1230
    }
1231
1232
    protected function NextOrderStep()
1233
    {
1234
        return OrderStep::get()
1235
            ->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...
1236
            ->First();
1237
    }
1238
1239
    protected function PreviousOrderStep()
1240
    {
1241
        return OrderStep::get()
1242
            ->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...
1243
            ->First();
1244
    }
1245
1246
    /**
1247
     * standard SS method
1248
     * USED TO BE: Unpaid,Query,Paid,Processing,Sent,Complete,AdminCancelled,MemberCancelled,Cart.
1249
     */
1250
    public function requireDefaultRecords()
1251
    {
1252
        parent::requireDefaultRecords();
1253
        $orderStepsToInclude = EcommerceConfig::get('OrderStep', 'order_steps_to_include');
1254
        $codesToInclude = self::get_codes_for_order_steps_to_include();
1255
        $indexNumber = 0;
1256
        if ($orderStepsToInclude && count($orderStepsToInclude)) {
1257
            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...
1258
                foreach ($codesToInclude as $className => $code) {
1259
                    $code = strtoupper($code);
1260
                    $filter = array('ClassName' => $className);
1261
                    $indexNumber += 10;
1262
                    $itemCount = OrderStep::get()->filter($filter)->Count();
1263
                    if ($itemCount) {
1264
                        $obj = OrderStep::get()->filter($filter)->First();
1265
                        if ($obj->Code != $code) {
1266
                            $obj->Code = $code;
1267
                            $obj->write();
1268
                        }
1269
                        $parentObj = singleton('OrderStep');
1270
                        if ($obj->Description == $parentObj->myDescription()) {
1271
                            $obj->Description = $obj->myDescription();
1272
                            $obj->write();
1273
                        }
1274
                    } else {
1275
                        $obj = $className::create();
1276
                        $obj->Code = $code;
1277
                        $obj->Description = $obj->myDescription();
1278
                        $obj->write();
1279
                        DB::alteration_message("Created \"$code\" as $className.", 'created');
1280
                    }
1281
                    $obj = OrderStep::get()
1282
                        ->filter(array('Code' => strtoupper($code)))
1283
                        ->First();
1284
                    if ($obj) {
1285
                        if ($obj->Sort != $indexNumber) {
1286
                            $obj->Sort = $indexNumber;
1287
                            $obj->write();
1288
                        }
1289
                    } else {
1290
                        user_error("There was an error in creating the $code OrderStep");
1291
                    }
1292
                }
1293
            }
1294
        }
1295
        $steps = OrderStep::get();
1296
        foreach ($steps as $step) {
1297
            if (!$step->Description) {
1298
                $step->Description = $step->myDescription();
1299
                $step->write();
1300
            }
1301
        }
1302
    }
1303
1304
    /**
1305
     * returns the standard EcommerceDBConfig for use within OrderSteps.
1306
     *
1307
     * @return EcommerceDBConfig
1308
     */
1309
    protected function EcomConfig()
1310
    {
1311
        return EcommerceDBConfig::current_ecommerce_db_config();
1312
    }
1313
1314
    /**
1315
     * Explains the current order step.
1316
     *
1317
     * @return string
1318
     */
1319
    protected function myDescription()
1320
    {
1321
        return _t('OrderStep.DESCRIPTION', 'No description has been provided for this step.');
1322
    }
1323
}
1324