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
Pull Request — master (#344)
by
unknown
01:55
created

src/Actions/UnpublishItemWorkflowAction.php (8 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\AdvancedWorkflow\Actions;
4
5
use SilverStripe\Forms\FieldGroup;
6
use SilverStripe\Forms\LabelField;
7
use SilverStripe\Forms\NumericField;
8
use SilverStripe\ORM\DataObject;
9
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowAction;
10
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowInstance;
11
use Symbiote\AdvancedWorkflow\Extensions\WorkflowEmbargoExpiryExtension;
12
use Symbiote\AdvancedWorkflow\Jobs\WorkflowPublishTargetJob;
13
use Symbiote\QueuedJob\Services\AbstractQueuedJob;
14
use Symbiote\QueuedJob\Services\QueuedJobService;
15
16
/**
17
 * Unpublishes an item
18
 *
19
 * @author     [email protected]
20
 * @license    BSD License (http://silverstripe.org/bsd-license/)
21
 * @package    advancedworkflow
22
 * @subpackage actions
23
 */
24
class UnpublishItemWorkflowAction extends WorkflowAction
25
{
26
    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...
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...
27
        'UnpublishDelay' => 'Int'
28
    );
29
30
    private static $icon = 'symbiote/silverstripe-advancedworkflow:images/unpublish.png';
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...
The property $icon 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...
31
32
    private static $table_name = 'UnpublishItemWorkflowAction';
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...
The property $table_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...
33
34
    public function execute(WorkflowInstance $workflow)
35
    {
36
        if (!$target = $workflow->getTarget()) {
37
            return true;
38
        }
39
40
        if (class_exists(AbstractQueuedJob::class) && $this->UnpublishDelay) {
0 ignored issues
show
The property UnpublishDelay does not exist on object<Symbiote\Advanced...lishItemWorkflowAction>. 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...
41
            $job   = new WorkflowPublishTargetJob($target, "unpublish");
42
            $days  = $this->UnpublishDelay;
0 ignored issues
show
The property UnpublishDelay does not exist on object<Symbiote\Advanced...lishItemWorkflowAction>. 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...
43
            $after = date('Y-m-d H:i:s', strtotime("+$days days"));
44
            singleton(QueuedJobService::class)->queueJob($job, $after);
45
        } elseif ($target->hasExtension(WorkflowEmbargoExpiryExtension::class)) {
46
            // setting future date stuff if needbe
47
48
            // set these values regardless
49
            $target->DesiredUnPublishDate = '';
50
            $target->DesiredPublishDate = '';
51
            $target->write();
52
53
            if ($target->hasMethod('doUnpublish')) {
54
                $target->doUnpublish();
55
            }
56
        } else {
57
            if ($target->hasMethod('doUnpublish')) {
58
                $target->doUnpublish();
59
            }
60
        }
61
62
        return true;
63
    }
64
65
    public function getCMSFields()
66
    {
67
        $fields = parent::getCMSFields();
68
69
        if (class_exists(AbstractQueuedJob::class)) {
70
            $before = _t('UnpublishItemWorkflowAction.DELAYUNPUBDAYSBEFORE', 'Delay unpublishing by ');
71
            $after  = _t('UnpublishItemWorkflowAction.DELAYUNPUBDAYSAFTER', ' days');
72
73
            $fields->addFieldToTab('Root.Main', new FieldGroup(
74
                _t('UnpublishItemWorkflowAction.UNPUBLICATIONDELAY', 'Delay Un-publishing'),
75
                new LabelField('UnpublishDelayBefore', $before),
76
                new NumericField('UnpublishDelay', ''),
77
                new LabelField('UnpublishDelayAfter', $after)
78
            ));
79
        }
80
81
        return $fields;
82
    }
83
84
    /**
85
     * @param  DataObject $target
86
     * @return bool
87
     */
88
    public function canPublishTarget(DataObject $target)
89
    {
90
        return false;
91
    }
92
}
93