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.

AssignUsersToWorkflowAction::getAssignedMembers()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.552
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Symbiote\AdvancedWorkflow\Actions;
4
5
use SilverStripe\Forms\CheckboxField;
6
use SilverStripe\Forms\CheckboxSetField;
7
use SilverStripe\Forms\HeaderField;
8
use SilverStripe\Forms\TreeMultiselectField;
9
use SilverStripe\ORM\ArrayList;
10
use SilverStripe\ORM\DB;
11
use SilverStripe\Security\Group;
12
use SilverStripe\Security\Member;
13
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowAction;
14
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowInstance;
15
16
/**
17
 * A workflow action that allows additional users or groups to be assigned to
18
 * the workflow part-way through the workflow path.
19
 *
20
 * @license    BSD License (http://silverstripe.org/bsd-license/)
21
 * @package    advancedworkflow
22
 * @subpackage actions
23
 */
24
class AssignUsersToWorkflowAction 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...
27
        'AssignInitiator'       => 'Boolean',
28
    );
29
30
    private static $many_many = 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...
31
        'Users'  => Member::class,
32
        'Groups' => Group::class,
33
    );
34
35
    private static $icon = 'symbiote/silverstripe-advancedworkflow:images/assign.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...
36
37
    private static $table_name = 'AssignUsersToWorkflowAction';
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...
38
39
    public function execute(WorkflowInstance $workflow)
40
    {
41
        $workflow->Users()->removeAll();
0 ignored issues
show
Documentation Bug introduced by
The method Users does not exist on object<Symbiote\Advanced...jects\WorkflowInstance>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
42
        //Due to http://open.silverstripe.org/ticket/8258, there are errors occuring if Group has been extended
43
        //We use a direct delete query here before ticket 8258 fixed
44
        //$workflow->Groups()->removeAll();
45
        $workflowID = $workflow->ID;
46
        $query = <<<SQL
47
		DELETE FROM "WorkflowInstance_Groups" WHERE ("WorkflowInstance_Groups"."WorkflowInstanceID" = '$workflowID');
48
SQL;
49
        DB::query($query);
50
        $workflow->Users()->addMany($this->Users());
0 ignored issues
show
Documentation Bug introduced by
The method Users does not exist on object<Symbiote\Advanced...jects\WorkflowInstance>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
Documentation Bug introduced by
The method Users does not exist on object<Symbiote\Advanced...nUsersToWorkflowAction>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
51
        $workflow->Groups()->addMany($this->Groups());
0 ignored issues
show
Documentation Bug introduced by
The method Groups does not exist on object<Symbiote\Advanced...jects\WorkflowInstance>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
Documentation Bug introduced by
The method Groups does not exist on object<Symbiote\Advanced...nUsersToWorkflowAction>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
52
        if ($this->AssignInitiator) {
0 ignored issues
show
Documentation introduced by
The property AssignInitiator does not exist on object<Symbiote\Advanced...nUsersToWorkflowAction>. 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...
53
            $workflow->Users()->add($workflow->Initiator());
0 ignored issues
show
Documentation Bug introduced by
The method Users does not exist on object<Symbiote\Advanced...jects\WorkflowInstance>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
54
        }
55
        return true;
56
    }
57
58
    public function getCMSFields()
59
    {
60
        $fields = parent::getCMSFields();
61
62
        $cmsUsers = Member::mapInCMSGroups();
63
64
        $fields->addFieldsToTab('Root.Main', array(
65
            new HeaderField('AssignUsers', $this->fieldLabel('AssignUsers')),
66
            new CheckboxField('AssignInitiator', $this->fieldLabel('AssignInitiator')),
67
            $users = CheckboxSetField::create('Users', $this->fieldLabel('Users'), $cmsUsers),
68
            new TreeMultiselectField('Groups', $this->fieldLabel('Groups'), Group::class)
69
        ));
70
71
        // limit to the users which actually can access the CMS
72
        $users->setSource(Member::mapInCMSGroups());
73
74
        return $fields;
75
    }
76
77
    public function fieldLabels($relations = true)
78
    {
79
        return array_merge(parent::fieldLabels($relations), array(
80
            'AssignUsers'       => _t('AssignUsersToWorkflowAction.ASSIGNUSERS', 'Assign Users'),
81
            'Users'             => _t('AssignUsersToWorkflowAction.USERS', 'Users'),
82
            'Groups'            => _t('AssignUsersToWorkflowAction.GROUPS', 'Groups'),
83
            'AssignInitiator'   => _t('AssignUsersToWorkflowAction.INITIATOR', 'Assign Initiator'),
84
        ));
85
    }
86
87
    /**
88
     * Returns a set of all Members that are assigned to this WorkflowAction subclass, either directly or via a group.
89
     *
90
     * @return ArrayList
91
     */
92
    public function getAssignedMembers()
93
    {
94
        $members = $this->Users();
0 ignored issues
show
Documentation Bug introduced by
The method Users does not exist on object<Symbiote\Advanced...nUsersToWorkflowAction>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
95
        $groups  = $this->Groups();
0 ignored issues
show
Documentation Bug introduced by
The method Groups does not exist on object<Symbiote\Advanced...nUsersToWorkflowAction>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
96
97
        // Can't merge instances of DataList so convert to something where we can
98
        $_members = ArrayList::create();
99
        $members->each(function ($item) use ($_members) {
100
            $_members->push($item);
101
        });
102
103
        $_groups = ArrayList::create();
104
        $groups->each(function ($item) use ($_groups) {
105
            $_groups->push($item);
106
        });
107
108
        foreach ($_groups as $group) {
109
            $_members->merge($group->Members());
110
        }
111
112
        $_members->removeDuplicates();
113
        return $_members;
114
    }
115
}
116