Completed
Push — master ( ce164c...4c286e )
by Nicolaas
03:42
created

OrderProcessQueue::isReadyToGo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * This class provides a bunch of Meta Objects
4
 * that do not interact with the object at hand, but rather with the datalist as a whole.
5
 *
6
 */
7
8
class OrderProcessQueue extends DataObject
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
{
10
    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...
11
        'DeferTimeInSeconds' => 'Int',
12
        'InProcess' => 'Boolean'
13
    );
14
15
    private static $has_one = array(
0 ignored issues
show
Unused Code introduced by
The property $has_one 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...
16
        'Order' => 'Order',
17
        'OrderStep' => 'OrderStep'
18
    );
19
20
    private static $indexes = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $indexes is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
21
        'OrderID' => array(
22
            'type' => 'unique',
23
            'value' => '"OrderID"'
24
        ),
25
        'Created' => true,
26
        'DeferTimeInSeconds' => true
27
    );
28
29
    private static $casting = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $casting is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
30
        'ToBeProcessedAt' => 'SS_Datetime'
31
    );
32
33
    private static $default_sort = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $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...
34
        'Created' => 'DESC'
35
    );
36
37
    /**
38
     * standard SS variable.
39
     *
40
     * @var array
41
     */
42
    private static $summary_fields = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $summary_fields is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
43
        'Order.Title' => 'Order',
44
        'Order.Status.Title' => 'Current Step',
45
        'ToBeProcessedAt.Nice' => 'To be processed at',
46
        'ToBeProcessedAt.Ago' => 'That is ...',
47
        'InProcess.Nice' => 'Currently Running'
48
    );
49
50
    /**
51
     * standard SS variable.
52
     *
53
     * @var array
54
     */
55
    private static $searchable_fields = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $searchable_fields is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
56
        'OrderID' => array(
57
            'field' => 'NumericField',
58
            'title' => 'Order Number',
59
        )
60
    );
61
62
63
    /**
64
     * Standard SS method.
65
     *
66
     * @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...
67
     *
68
     * @return bool
69
     */
70
    public function canCreate($member = null)
71
    {
72
        return false;
73
    }
74
75
    /**
76
     * Standard SS method.
77
     *
78
     * @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...
79
     *
80
     * @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...
81
     */
82
    public function canView($member = null)
83
    {
84
        if (! $member) {
85
            $member = Member::currentUser();
86
        }
87
        $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...
88
        if ($extended !== null) {
89
            return $extended;
90
        }
91
        if (Permission::checkMember($member, Config::inst()->get('EcommerceRole', 'admin_permission_code'))) {
92
            return true;
93
        }
94
        //is the member is a shop assistant they can always view it
95
        if (EcommerceRole::current_member_is_shop_assistant($member)) {
96
            return true;
97
        }
98
99
        return parent::canView($member);
0 ignored issues
show
Bug introduced by
It seems like $member defined by \Member::currentUser() on line 85 can also be of type object<DataObject>; however, DataObject::canView() 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...
100
    }
101
102
    /**
103
     * Standard SS method.
104
     *
105
     * @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...
106
     *
107
     * @return bool
108
     */
109
    public function canEdit($member = null)
110
    {
111
        return false;
112
    }
113
114
    /**
115
     * Standard SS method
116
     * Queues can be deleted if needed.
117
     *
118
     * @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...
119
     *
120
     * @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...
121
     */
122
    public function canDelete($member = null)
123
    {
124
        return parent::canDelete($member);
125
    }
126
127
    /**
128
     * standard SS variable.
129
     *
130
     * @var string
131
     */
132
    private static $singular_name = 'Order To Be Processed';
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...
133
    public function i18n_singular_name()
134
    {
135
        return _t('OrderProcessQueue.SINGULAR_NAME', 'Order In Queue');
136
    }
137
138
    /**
139
     * standard SS variable.
140
     *
141
     * @var string
142
     */
143
    private static $plural_name = 'Orders to be Processed';
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...
144
    public function i18n_plural_name()
145
    {
146
        return _t('OrderProcessQueue.PLURAL_NAME', 'Orders In Queue');
147
    }
148
149
150
    /**
151
     * META METHOD: Add an order to the job list.
152
     * If the order already exists, it will update the seconds and the creation  time.
153
     *
154
     * @param Order $order
155
     * @param Int   $deferInSeconds
0 ignored issues
show
Bug introduced by
There is no parameter named $deferInSeconds. 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...
156
     */
157
    public function AddOrderToQueue($order, $deferTimeInSeconds)
158
    {
159
        $filter = array('OrderID' => $order->ID);
160
        $existingEntry = OrderProcessQueue::get()->filter($filter)->first();
161
        $filter['Created'] = SS_Datetime::now()->Rfc2822();
162
        $filter['DeferTimeInSeconds'] = $deferTimeInSeconds;
163
        if (! $existingEntry) {
164
            $existingEntry = OrderProcessQueue::create($filter);
165
            $existingEntry->OrderStepID = $order->StatusID;
0 ignored issues
show
Documentation introduced by
The property OrderStepID does not exist on object<OrderProcessQueue>. 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 StatusID does not exist on object<Order>. 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...
166
        } else {
167
            foreach ($filter as $field => $value) {
168
                $existingEntry->$field = $value;
169
            }
170
        }
171
        $existingEntry->write();
172
173
        return $existingEntry;
174
    }
175
176
    /**
177
     * META METHOD
178
     * processes the order ...
179
     * returns TRUE if SUCCESSFUL and FALSE if it did not run for any reason ...
180
     *
181
     *
182
     * @param  Order $order optional
0 ignored issues
show
Documentation introduced by
Should the type for parameter $order not be Order|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...
183
     * @return boolean
184
     */
185
    public function process($order = null)
186
    {
187
        //find variables
188
        if( ! $order) {
189
            $order = $this->Order();
0 ignored issues
show
Documentation Bug introduced by
The method Order does not exist on object<OrderProcessQueue>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
190
            $myQueueObject = $this;
191
        } else {
192
            $myQueueObject = $this->getQueueObject($order);
193
        }
194
        //delete if order is gone ...
195
        if(! $order) {
196
            $myQueueObject->delete();
197
        }
198
        //if order has moved already ... delete
199
        if(
200
            $this->OrderStepID > 0
0 ignored issues
show
Documentation introduced by
The property OrderStepID does not exist on object<OrderProcessQueue>. 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...
201
            && (int)$order->StatusID !== (int)$this->OrderStepID
0 ignored issues
show
Documentation introduced by
The property OrderStepID does not exist on object<OrderProcessQueue>. 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...
202
        ) {
203
            $myQueueObject->delete();
204
        }
205
        if($order && $myQueueObject) {
206
            if ($myQueueObject->isReadyToGo()) {
207
                $oldOrderStatusID = $order->StatusID;
208
                $myQueueObject->InProcess = true;
209
                $myQueueObject->write();
210
                $order->tryToFinaliseOrder(
211
                    $tryAgain = false,
212
                    $fromOrderQueue = true
213
                );
214
                $newOrderStatusID = $order->StatusID;
215
                if($oldOrderStatusID != $newOrderStatusID) {
216
                    $myQueueObject->delete();
217
                    return true;
218
                } else {
219
                    $myQueueObject->InProcess = false;
220
                    $myQueueObject->write();
221
                }
222
            }
223
        }
224
225
        return false;
226
    }
227
228
    /**
229
     * META METHOD: returns the queue object if it exists
230
     *
231
     * @param  Order $order
232
     *
233
     * @return null |   OrderProcessQueue
0 ignored issues
show
Documentation introduced by
Should the return type not be DataObject|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...
234
     */
235
    public function getQueueObject($order)
236
    {
237
        $filter = array('OrderID' => $order->ID);
238
239
        return OrderProcessQueue::get()->filter($filter)->first();
240
    }
241
242
    /**
243
     * META METHOD: Once you are done, you can remove the item like this ...
244
     *
245
     * @param  Order $order
246
     */
247
    public function removeOrderFromQueue($order)
248
    {
249
        $queueEntries = OrderProcessQueue::get()->filter(array('OrderID' => $order->ID));
250
        foreach($queueEntries as $queueEntry) {
251
            $queueEntry->delete();
252
        }
253
    }
254
255
    /**
256
     * META METHOD: returns a list of orders to be processed
257
     * @param int $id force this Order to be processed
258
     * @param int $limit total number of orders that can be retrieved at any one time
259
     *
260
     * @return DataList (of orders)
261
     */
262
    public function OrdersToBeProcessed($id = 0, $limit = 9999)
263
    {
264
265
        //we sort the order randomly so that we get a nice mixture
266
        //not always the same ones holding up the process
267
        $sql = '
268
            SELECT "OrderID"
269
            FROM "OrderProcessQueue"
270
            WHERE
271
                "InProcess" = 0
272
                AND
273
                (UNIX_TIMESTAMP("Created") + "DeferTimeInSeconds") < '.time().'
274
            ORDER BY RAND() DESC
275
            LIMIT '.$limit.';
276
        ';
277
        $rows = DB::query($sql);
278
        $orderIDs = array($id => $id);
279
        foreach ($rows as $row) {
280
            $orderIDs[$row['OrderID']] = $row['OrderID'];
281
        }
282
283
        return Order::get()
284
            ->filter(array('ID' => $orderIDs))
285
            ->sort('RAND()');
286
    }
287
288
    /**
289
     * META METHOD: all orders with a queue object
290
     * @param int $id force this Order to be processed
0 ignored issues
show
Bug introduced by
There is no parameter named $id. 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...
291
     * @param int $limit total number of orders that can be retrieved at any one time
292
     *
293
     * @return DataList (of orders)
294
     */
295
    public function AllOrdersInQueue($limit = 9999)
296
    {
297
298
        return Order::get()
299
            ->filter(array('ID' => OrderProcessQueue::get()->column('OrderID')))
300
            ->sort('RAND()')
301
            ->limit($limit);
302
    }
303
304
    /**
305
     * META METHOD: returns a list of orders NOT YET to be processed
306
     * @param int $limit total number of orders that can be retrieved at any one time
307
     *
308
     * @return DataList (of orders)
309
     */
310
    public function OrdersInQueueThatAreNotReady($limit = 9999)
311
    {
312
313
        //we sort the order randomly so that we get a nice mixture
314
        //not always the same ones holding up the process
315
        $sql = '
316
            SELECT "OrderID"
317
            FROM "OrderProcessQueue"
318
            WHERE
319
                (UNIX_TIMESTAMP("Created") + "DeferTimeInSeconds") >= '.time().'
320
            ORDER BY RAND() DESC
321
            LIMIT '.$limit.';
322
        ';
323
        $rows = DB::query($sql);
324
        $orderIDs = array(0 => 0);
325
        foreach ($rows as $row) {
326
            $orderIDs[$row['OrderID']] = $row['OrderID'];
327
        }
328
329
        return Order::get()
330
            ->filter(array('ID' => $orderIDs))
331
            ->sort('RAND()');
332
    }
333
334
    /**
335
     * non-database method of working out if an Order is ready to go.
336
     *
337
     * @return bool
338
     */
339
    public function isReadyToGo()
340
    {
341
        return (strtotime($this->Created) + $this->DeferTimeInSeconds) < time();
0 ignored issues
show
Documentation introduced by
The property DeferTimeInSeconds does not exist on object<OrderProcessQueue>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
342
    }
343
344
    /**
345
     *
346
     * casted variable
347
     * @return SS_DateTime
348
     */
349
    public function ToBeProcessedAt()
350
    {
351
        return $this->getToBeProcessedAt();
352
    }
353
354
    /**
355
     *
356
     * casted variable
357
     * @return SS_DateTime
358
     */
359
    public function getToBeProcessedAt()
360
    {
361
        return DBField::create_field('SS_Datetime', (strtotime($this->Created) + $this->DeferTimeInSeconds));
0 ignored issues
show
Documentation introduced by
The property DeferTimeInSeconds does not exist on object<OrderProcessQueue>. 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...
362
    }
363
364
365
    /**
366
     * CMS Fields
367
     * @return FieldList
368
     */
369
    public function getCMSFields()
370
    {
371
        $fields = parent::getCMSFields();
372
        if($this->exists()) {
373
            $fields->addFieldToTab(
374
                'Root.Main',
375
                ReadonlyField::create(
376
                    'ToBeProcessedAtCompilations',
377
                    _t('OrderProcessQueue.TO_BE_PROCESSED', 'To Be Processed'),
378
                    $this->ToBeProcessedAt->Nice() . ' - ' . $this->getToBeProcessedAt()->Ago()
0 ignored issues
show
Documentation introduced by
The property ToBeProcessedAt does not exist on object<OrderProcessQueue>. 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...
379
                ),
380
                'InProcess'
381
            );
382
            $fields->addFieldToTab(
383
                'Root.Main',
384
                LiteralField::create(
385
                    'processQueueNow',
386
                    '<h2>
387
                        <a href="/dev/tasks/EcommerceTaskProcessOrderQueue/?id='.$this->OrderID.'" target="_blank">'.
0 ignored issues
show
Documentation introduced by
The property OrderID does not exist on object<OrderProcessQueue>. 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...
388
                            _t('OrderProcessQueue.PROCESS', 'Process now').
389
                        '</a>
390
                    </h2>'
391
                )
392
            );
393
            $fields->replaceField(
394
                'OrderID',
395
                CMSEditLinkField::create(
396
                    'OrderID',
397
                    'Order',
398
                    $this->Order()
0 ignored issues
show
Documentation Bug introduced by
The method Order does not exist on object<OrderProcessQueue>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
399
                )
400
            );
401
        }
402
        return $fields;
403
    }
404
405
    public function requireDefaultRecords()
406
    {
407
        parent::requireDefaultRecords();
408
        $errors = OrderProcessQueue::get()->filter(array('OrderID' => 0));
409
        foreach($errors as $error) {
410
            DB::alteration_message(' DELETING ROGUE OrderProcessQueue', 'deleted');
411
            $error->delete();
412
        }
413
    }
414
415
}
416