Completed
Push — master ( c5ed18...ed0fce )
by Nathan
07:36
created

src/Jobs/DeleteObjectJob.php (4 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
namespace Symbiote\QueuedJobs\Jobs;
4
5
use SilverStripe\ORM\DataObject;
6
use Symbiote\QueuedJobs\Services\AbstractQueuedJob;
7
use Symbiote\QueuedJobs\Services\QueuedJob;
8
9
/**
10
 * A job used to delete a data object. Typically used for deletes that need to happen on
11
 * a schedule, or where the delete may have some onflow affect that takes a while to
12
 * finish the deletion.
13
 *
14
 * @author [email protected]
15
 * @license BSD License http://silverstripe.org/bsd-license/
16
 */
17
class DeleteObjectJob extends AbstractQueuedJob
18
{
19
    /**
20
     * @param DataObject $node
21
     */
22
    public function __construct($node = null)
23
    {
24
        if ($node) {
25
            $this->TargetClass = get_class($node);
0 ignored issues
show
The property TargetClass does not exist on object<Symbiote\QueuedJobs\Jobs\DeleteObjectJob>. 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...
26
            $this->TargetID = $node->ID;
0 ignored issues
show
The property TargetID does not exist on object<Symbiote\QueuedJobs\Jobs\DeleteObjectJob>. 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...
27
            $this->currentStep = 0;
28
            $this->totalSteps = 1;
29
        }
30
    }
31
32
    /**
33
     * @param string (default: Object)
34
     * @return DataObject
35
     */
36
    protected function getObject($name = 'SilverStripe\\Core\\Object')
37
    {
38
        return DataObject::get_by_id($this->TargetClass, $this->TargetID);
0 ignored issues
show
The property TargetClass does not exist on object<Symbiote\QueuedJobs\Jobs\DeleteObjectJob>. 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...
The property TargetID does not exist on object<Symbiote\QueuedJobs\Jobs\DeleteObjectJob>. 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...
39
    }
40
41
    /**
42
     * @return string
43
     */
44
    public function getJobType()
45
    {
46
        return QueuedJob::IMMEDIATE;
47
    }
48
49
    /**
50
     * @return string
51
     */
52
    public function getTitle()
53
    {
54
        $obj = $this->getObject();
55
        if ($obj) {
56
            return _t('DeleteObjectJob.DELETE_OBJ2', 'Delete {title}', array('title' => $obj->Title));
57
        } else {
58
            return _t('DeleteObjectJob.DELETE_JOB', 'Delete node');
59
        }
60
    }
61
62
    public function process()
63
    {
64
        $obj = $this->getObject();
65
        $obj->delete();
66
        $this->currentStep = 1;
67
        $this->isComplete = true;
68
    }
69
}
70