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.

ScheduledExecutionJob   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 5
dl 0
loc 76
rs 10
c 0
b 0
f 0

5 Methods

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