Issues (2002)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

code/model/process/OrderProcessQueue.php (30 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
9
{
10
    private static $db = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
11
        'DeferTimeInSeconds' => 'Int',
12
        'InProcess' => 'Boolean',
13
        'ProcessAttempts' => 'Int'
14
    );
15
16
    private static $has_one = 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...
17
        'Order' => 'Order',
18
        'OrderStep' => 'OrderStep'
19
    );
20
21
    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...
22
        'DeferTimeInSeconds' => true,
23
        'ProcessAttempts' => true
24
    );
25
26
    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...
27
        'ToBeProcessedAt' => 'SS_Datetime',
28
        'HasBeenInQueueSince' => 'SS_Datetime'
29
    );
30
31
    private static $default_sort = [
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...
32
        'ID' => 'DESC'
33
    ];
34
35
    /**
36
     * standard SS variable.
37
     *
38
     * @var array
39
     */
40
    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...
41
        'Order.Title' => 'Order',
42
        'Order.Status.Title' => 'Current Step',
43
        'ProcessAttempts' => 'Attempts',
44
        'ToBeProcessedAt.Nice' => 'To be processed at',
45
        'ToBeProcessedAt.Ago' => 'That is ...',
46
        'HasBeenInQueueForSince.Nice' => 'Added to queue ...',
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...
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
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
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
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
$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
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
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
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
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
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
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 if it does not exist already.
152
     *
153
     * @param Order $order
154
     * @param Int   $deferInSeconds
0 ignored issues
show
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...
155
     */
156
    public function AddOrderToQueue($order, $deferTimeInSeconds)
157
    {
158
        if (!$order || ! $order->ID) {
159
            user_error('No real order provided.');
160
        }
161
        $filter = array(
162
            'OrderID' => $order->ID,
163
            'OrderStepID' => $order->StatusID
0 ignored issues
show
The property StatusID does not exist on object<Order>. 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...
164
        );
165
        $existingEntry = DataObject::get_one(
166
            'OrderProcessQueue',
167
            $filter,
168
            $cacheDataObjectGetOne = false
169
        );
170
        $filter['DeferTimeInSeconds'] = $deferTimeInSeconds;
171
        if (! $existingEntry) {
172
            $existingEntry = OrderProcessQueue::create($filter);
173
        } else {
174
            foreach ($filter as $field => $value) {
175
                $existingEntry->$field = $value;
176
            }
177
        }
178
        $existingEntry->write();
179
180
        return $existingEntry;
181
    }
182
183
    /**
184
     * META METHOD
185
     * processes the order ...
186
     * returns TRUE if SUCCESSFUL and a message if unsuccessful ...
187
     *
188
     *
189
     * @param  Order $order optional
0 ignored issues
show
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...
190
     * @return boolean | string
0 ignored issues
show
Should the return type not be boolean|string?

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...
191
     */
192
    public function process($order = null)
193
    {
194
        //find variables
195
        if (! $order) {
196
            $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...
197
            $myQueueObject = $this;
198
        } else {
199
            $myQueueObject = $this->getQueueObject($order);
200
        }
201
        //delete if order is gone ...
202
        if ($order) {
203
            //if order has moved already ... delete
204
            if (
205
                $order->IsCancelled() ||
206
                $order->IsArchived()
207
            ) {
208
                $myQueueObject->delete();
209
                $message = 'Order is archived already and/or cancelled.';
210
            } elseif (
211
                $this->OrderStepID > 0
0 ignored issues
show
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...
212
                && (int)$order->StatusID !== (int)$myQueueObject->OrderStepID
213
            ) {
214
                $message = 'Order has already moved on.';
215
                $myQueueObject->delete();
216
            } else {
217
                if ($myQueueObject) {
218
                    if ($myQueueObject->isReadyToGo()) {
219
                        $oldOrderStatusID = $order->StatusID;
220
                        $myQueueObject->InProcess = true;
221
                        $myQueueObject->ProcessAttempts = $myQueueObject->ProcessAttempts + 1;
222
                        $myQueueObject->write();
223
                        $order->tryToFinaliseOrder(
224
                            $tryAgain = false,
225
                            $fromOrderQueue = true
226
                        );
227
                        $newOrderStatusID = $order->StatusID;
228
                        if ($oldOrderStatusID != $newOrderStatusID) {
229
                            $myQueueObject->delete();
230
                            return true;
231
                        } else {
232
                            $message = 'Attempt to move order was not successful.';
233
                            $myQueueObject->InProcess = false;
234
                            $myQueueObject->write();
235
                        }
236
                    } else {
237
                        $message = 'Minimum order queue time has not been passed.';
238
                    }
239
                } else {
240
                    $message = 'Could not find queue object.';
241
                }
242
            }
243
        } else {
244
            $message = 'Can not find order.';
245
            $myQueueObject->delete();
246
        }
247
248
        return $message;
249
    }
250
251
    /**
252
     * META METHOD: returns the queue object if it exists
253
     *
254
     * @param  Order $order
255
     *
256
     * @return null |   OrderProcessQueue
0 ignored issues
show
Should the return type not be DataObject?

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...
257
     */
258
    public function getQueueObject($order)
259
    {
260
        $filter = array('OrderID' => $order->ID);
261
262
        return DataObject::get_one('OrderProcessQueue', $filter);
263
    }
264
265
    /**
266
     * META METHOD: Once you are done, you can remove the item like this ...
267
     *
268
     * @param  Order $order
269
     */
270
    public function removeOrderFromQueue($order)
271
    {
272
        $queueEntries = OrderProcessQueue::get()->filter(array('OrderID' => $order->ID));
273
        foreach ($queueEntries as $queueEntry) {
274
            $queueEntry->delete();
275
        }
276
    }
277
278
    /**
279
     * META METHOD: returns a list of orders to be processed
280
     * @param int $id force this Order to be processed
281
     * @param int $limit total number of orders that can be retrieved at any one time
282
     *
283
     * @return DataList (of orders)
284
     */
285
    public function OrdersToBeProcessed($id = 0, $limit = 9999)
286
    {
287
288
        //we sort the order randomly so that we get a nice mixture
289
        //not always the same ones holding up the process
290
        $sql = '
291
            SELECT "OrderID"
292
            FROM "OrderProcessQueue"
293
            WHERE
294
                "InProcess" = 0
295
                AND
296
                (UNIX_TIMESTAMP("Created") + "DeferTimeInSeconds") < UNIX_TIMESTAMP()
297
            ORDER BY '.$this->sortPhrase().'
298
            LIMIT '.$limit.';
299
        ';
300
        $rows = DB::query($sql);
301
        $orderIDs = array($id => $id);
302
        foreach ($rows as $row) {
303
            $orderIDs[$row['OrderID']] = $row['OrderID'];
304
        }
305
306
        return Order::get()
307
            ->filter(array('ID' => $orderIDs))
308
            ->sort($this->sortPhraseForOrderIDs($orderIDs));
309
    }
310
311
    /**
312
     * META METHOD: all orders with a queue object
313
     * @param int $id force this Order to be processed
0 ignored issues
show
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...
314
     * @param int $limit total number of orders that can be retrieved at any one time
315
     *
316
     * @return DataList (of orders)
317
     */
318
    public function AllOrdersInQueue($limit = 9999)
319
    {
320
        $orderIDs = OrderProcessQueue::get()->column('OrderID');
321
322
        return Order::get()
323
            ->filter(array('ID' => $orderIDs))
324
            ->sort($this->sortPhraseForOrderIDs($orderIDs))
325
            ->limit($limit);
326
    }
327
328
    /**
329
     * META METHOD: returns a list of orders NOT YET to be processed
330
     * @param int $limit total number of orders that can be retrieved at any one time
331
     *
332
     * @return DataList (of orders)
333
     */
334
    public function OrdersInQueueThatAreNotReady($limit = 9999)
335
    {
336
337
        //we sort the order randomly so that we get a nice mixture
338
        //not always the same ones holding up the process
339
        $sql = '
340
            SELECT "OrderID"
341
            FROM "OrderProcessQueue"
342
            WHERE
343
                (UNIX_TIMESTAMP("Created") + "DeferTimeInSeconds") >= UNIX_TIMESTAMP()
344
            ORDER BY '.$this->sortPhrase().'
345
            LIMIT '.$limit.';
346
        ';
347
        $rows = DB::query($sql);
348
        $orderIDs = array(0 => 0);
349
        foreach ($rows as $row) {
350
            $orderIDs[$row['OrderID']] = $row['OrderID'];
351
        }
352
353
        return Order::get()
354
            ->filter(array('ID' => $orderIDs))
355
            ->sort($this->sortPhraseForOrderIDs($orderIDs));
356
    }
357
358
    /**
359
     * non-database method of working out if an Order is ready to go.
360
     *
361
     * @return bool
362
     */
363
    public function isReadyToGo()
364
    {
365
        return (strtotime($this->Created) + $this->DeferTimeInSeconds) < time();
0 ignored issues
show
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...
366
    }
367
368
    /**
369
     *
370
     * casted variable
371
     * @return SS_DateTime
372
     */
373
    public function ToBeProcessedAt()
374
    {
375
        return $this->getToBeProcessedAt();
376
    }
377
378
    /**
379
     *
380
     * casted variable
381
     * @return SS_DateTime
382
     */
383
    public function getToBeProcessedAt()
384
    {
385
        return DBField::create_field('SS_Datetime', (strtotime($this->Created) + $this->DeferTimeInSeconds));
0 ignored issues
show
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...
386
    }
387
388
389
    /**
390
     *
391
     * casted variable
392
     * @return SS_DateTime
393
     */
394
    public function HasBeenInQueueForSince()
395
    {
396
        return $this->getHasBeenInQueueForSince();
397
    }
398
399
    /**
400
     *
401
     * casted variable
402
     * @return SS_DateTime
403
     */
404
    public function getHasBeenInQueueForSince()
405
    {
406
        return DBField::create_field('SS_Datetime', (strtotime($this->Created)));
407
    }
408
409
410
    /**
411
     * CMS Fields
412
     * @return FieldList
413
     */
414
    public function getCMSFields()
415
    {
416
        $fields = parent::getCMSFields();
417
        if ($this->exists()) {
418
            $fields->addFieldToTab(
419
                'Root.Main',
420
                ReadonlyField::create(
421
                    'HasBeenInQueueForSinceCompilations',
422
                    _t('OrderProcessQueue.SINCE', 'In the queue since'),
423
                    $this->getHasBeenInQueueForSince()->Nice() . ' - ' . $this->getHasBeenInQueueForSince()->Ago()
424
                ),
425
                'DeferTimeInSeconds'
426
            );
427
            $fields->addFieldToTab(
428
                'Root.Main',
429
                ReadonlyField::create(
430
                    'ToBeProcessedAtCompilations',
431
                    _t('OrderProcessQueue.TO_BE_PROCESSED', 'To Be Processed'),
432
                    $this->getToBeProcessedAt()->Nice() . ' - ' . $this->getToBeProcessedAt()->Ago()
433
                ),
434
                'InProcess'
435
            );
436
            $fields->addFieldToTab(
437
                'Root.Main',
438
                LiteralField::create(
439
                    'processQueueNow',
440
                    '<h2>
441
                        <a href="/dev/tasks/EcommerceTaskProcessOrderQueue/?id='.$this->OrderID.'" target="_blank">'.
0 ignored issues
show
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...
442
                            _t('OrderProcessQueue.PROCESS', 'Process now').
443
                        '</a>
444
                    </h2>'
445
                )
446
            );
447
            $fields->replaceField(
448
                'OrderID',
449
                CMSEditLinkField::create(
450
                    'OrderID',
451
                    'Order',
452
                    $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...
453
                )
454
            );
455
        }
456
        return $fields;
457
    }
458
459
    public function requireDefaultRecords()
460
    {
461
        parent::requireDefaultRecords();
462
        $errors = OrderProcessQueue::get()->filter(array('OrderID' => 0));
463
        foreach ($errors as $error) {
464
            DB::alteration_message(' DELETING ROGUE OrderProcessQueue', 'deleted');
465
            $error->delete();
466
        }
467
    }
468
469
    protected function sortPhrase()
470
    {
471
        return '
472
            "ProcessAttempts" ASC,
473
            (UNIX_TIMESTAMP("Created") + "DeferTimeInSeconds") ASC
474
        ';
475
    }
476
477
    /**
478
     * sort phrase for orders, based in order IDs...
479
     * @param  array $orderIds
0 ignored issues
show
There is no parameter named $orderIds. Did you maybe mean $orderIDs?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

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

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

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

Loading history...
480
     * @return string
481
     */
482
    protected function sortPhraseForOrderIDs($orderIDs)
483
    {
484
        return 'FIELD("Order"."ID", '.implode(",", $orderIDs).')';
485
    }
486
}
487