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.

WorkflowFieldTransitionController   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 68
Duplicated Lines 22.06 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 7
dl 15
loc 68
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A handleAdd() 0 18 4
A handleItem() 15 15 4
A RootField() 0 4 1
A Link() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Symbiote\AdvancedWorkflow\FormFields;
4
5
use SilverStripe\Control\Controller;
6
use SilverStripe\Control\RequestHandler;
7
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowAction;
8
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowTransition;
9
10
/**
11
 * Handles requests for creating or editing transitions.
12
 *
13
 * @package silverstripe-advancedworkflow
14
 */
15
class WorkflowFieldTransitionController extends RequestHandler
16
{
17
    private static $url_handlers = 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...
18
        'new/$ParentID!' => 'handleAdd',
19
        'item/$ID!'      => 'handleItem'
20
    );
21
22
    private static $allowed_actions = 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...
23
        'handleAdd',
24
        'handleItem'
25
    );
26
27
    protected $parent;
28
    protected $name;
29
30
    public function __construct($parent, $name)
31
    {
32
        $this->parent = $parent;
33
        $this->name   = $name;
34
35
        parent::__construct();
36
    }
37
38
    public function handleAdd()
39
    {
40
        $parent = $this->request->param('ParentID');
41
        $action = WorkflowAction::get()->byID($this->request->param('ParentID'));
42
43
        if (!$action || $action->WorkflowDefID != $this->RootField()->Definition()->ID) {
44
            $this->httpError(404);
45
        }
46
47
        if (!singleton(WorkflowTransition::class)->canCreate()) {
48
            $this->httpError(403);
49
        }
50
51
        $transition = new WorkflowTransition();
52
        $transition->ActionID = $action->ID;
0 ignored issues
show
Documentation introduced by
The property ActionID does not exist on object<Symbiote\Advanced...cts\WorkflowTransition>. 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...
53
54
        return new WorkflowFieldItemController($this, "new/$parent", $transition);
55
    }
56
57 View Code Duplication
    public function handleItem()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
    {
59
        $id    = $this->request->param('ID');
60
        $trans = WorkflowTransition::get()->byID($id);
61
62
        if (!$trans || $trans->Action()->WorkflowDefID != $this->RootField()->Definition()->ID) {
0 ignored issues
show
Bug introduced by
The method Action() does not exist on SilverStripe\ORM\DataObject. Did you maybe mean getCMSActions()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
63
            $this->httpError(404);
64
        }
65
66
        if (!$trans->canEdit()) {
67
            $this->httpError(403);
68
        }
69
70
        return new WorkflowFieldItemController($this, "item/$id", $trans);
71
    }
72
73
    public function RootField()
74
    {
75
        return $this->parent;
76
    }
77
78
    public function Link($action = null)
79
    {
80
        return Controller::join_links($this->parent->Link(), $this->name, $action);
81
    }
82
}
83