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.

SetPropertyWorkflowAction   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 40
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 14 3
A getCMSFields() 0 15 1
1
<?php
2
3
namespace Symbiote\AdvancedWorkflow\Actions;
4
5
use SilverStripe\Forms\TextField;
6
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowAction;
7
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowInstance;
8
9
/**
10
 *
11
 *
12
 * @author Marcus Nyeholt <[email protected]>
13
 */
14
class SetPropertyWorkflowAction extends WorkflowAction
15
{
16
    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...
17
        'Property' => 'Varchar',
18
        'Value'    => 'Text',
19
    );
20
21
    private static $table_name = 'SetPropertyWorkflowAction';
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
23
    public function execute(WorkflowInstance $workflow)
24
    {
25
        if (!$target = $workflow->getTarget()) {
26
            return true;
27
        }
28
29
        if ($target->hasField($this->Property)) {
0 ignored issues
show
Documentation introduced by
The property Property does not exist on object<Symbiote\Advanced...PropertyWorkflowAction>. 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...
30
            $target->setField($this->Property, $this->Value);
0 ignored issues
show
Documentation introduced by
The property Property does not exist on object<Symbiote\Advanced...PropertyWorkflowAction>. 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 Value does not exist on object<Symbiote\Advanced...PropertyWorkflowAction>. 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...
31
        }
32
33
        $target->write();
34
35
        return true;
36
    }
37
38
    public function getCMSFields()
39
    {
40
        $fields = parent::getCMSFields();
41
42
        $fields->addFieldsToTab('Root.Main', array(
43
            TextField::create('Property', _t('SetPropertyWorkflowAction.PROPERTY', 'Property'))
44
                ->setRightTitle(_t(
45
                    'SetPropertyWorkflowAction.PROPERTYTITLE',
46
                    'Property to set; if this exists as a setter method, will be called passing the value'
47
                )),
48
            TextField::create('Value', 'Value')
49
        ));
50
51
        return $fields;
52
    }
53
}
54