GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 95a104...d03d4c )
by Guy
27s
created

src/Jobs/ScheduledExecutionJob.php (1 issue)

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
namespace Symbiote\QueuedJobs\Jobs;
4
5
use SilverStripe\ORM\DataObject;
6
use Symbiote\QueuedJobs\Services\AbstractQueuedJob;
7
use Symbiote\QueuedJobs\Services\QueuedJobService;
8
9
/**
10
 * A job that gets executed on a particular schedule. When it runs,
11
 * it will call the onScheduledExecution method on the owning
12
 * dataobject.
13
 *
14
 * @author [email protected]
15
 * @license BSD License http://silverstripe.org/bsd-license/
16
 */
17
class ScheduledExecutionJob extends AbstractQueuedJob
18
{
19
    /**
20
     * @param DataObject $dataObject
21
     * @param int $timesExecuted
22
     */
23
    public function __construct($dataObject = null, $timesExecuted = 0)
24
    {
25
        if ($dataObject) {
26
            $this->objectID = $dataObject->ID;
27
            $this->objectType = $dataObject->ClassName;
28
29
            // captured so we have a unique hash generated for this job
30
            $this->timesExecuted = $timesExecuted;
31
            $this->totalSteps = 1;
32
        }
33
    }
34
35
    /**
36
     * @return DataObject
37
     */
38
    public function getDataObject()
39
    {
40
        return DataObject::get_by_id($this->objectType, $this->objectID);
41
    }
42
43
    /**
44
     * @return string
45
     */
46
    public function getTitle()
47
    {
48
        return _t(
49
            __CLASS__ . '.Title',
50
            'Scheduled execution for {title}',
51
            array('title' => $this->getDataObject()->getTitle())
52
        );
53
    }
54
55
56
    public function setup()
57
    {
58
    }
59
60
    public function process()
61
    {
62
        $object = $this->getDataObject();
63
        if ($object) {
64
            $object->onScheduledExecution();
65
66
            // figure out what our rescheduled date should be
67
            $timeStr = $object->ExecuteFree;
68
            if ($object->ExecuteEvery) {
69
                $executeInterval = $object->ExecuteInterval;
70
                if (!$executeInterval || !is_numeric($executeInterval)) {
71
                    $executeInterval = 1;
72
                }
73
                $timeStr = '+' . $executeInterval . ' ' . $object->ExecuteEvery;
74
            }
75
76
            $next = strtotime($timeStr);
77
            if ($next > time()) {
78
                // in the future
79
                $nextGen = date('Y-m-d H:i:s', $next);
80
                $nextId = singleton(QueuedJobService::class)->queueJob(
81
                    new ScheduledExecutionJob($object, $this->timesExecuted + 1),
0 ignored issues
show
The property timesExecuted does not exist on object<Symbiote\QueuedJo...\ScheduledExecutionJob>. 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...
82
                    $nextGen
83
                );
84
                $object->ScheduledJobID = $nextId;
85
                $object->write();
86
            }
87
        }
88
89
        $this->currentStep++;
90
        $this->isComplete = true;
91
    }
92
}
93