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.

WorkflowFieldItemController   A
last analyzed

Complexity

Total Complexity 19

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 19
lcom 1
cbo 6
dl 0
loc 99
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A index() 0 4 1
A edit() 0 4 1
A Form() 0 17 5
A doSave() 0 21 5
A delete() 0 17 4
A RootField() 0 4 1
A Link() 0 4 1
1
<?php
2
3
namespace Symbiote\AdvancedWorkflow\FormFields;
4
5
use SilverStripe\Control\Controller;
6
use SilverStripe\Forms\FormAction;
7
use SilverStripe\Forms\Form;
8
use SilverStripe\Forms\FieldList;
9
use SilverStripe\ORM\DataObject;
10
use SilverStripe\Security\SecurityToken;
11
12
/**
13
 * Handles individual record data editing or deleting.
14
 *
15
 * @package silverstripe-advancedworkflow
16
 */
17
class WorkflowFieldItemController extends Controller
18
{
19
    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...
20
        'index',
21
        'edit',
22
        'delete',
23
        'Form'
24
    );
25
26
    protected $parent;
27
    protected $name;
28
29
    public function __construct($parent, $name, $record)
30
    {
31
        $this->parent = $parent;
32
        $this->name   = $name;
33
        $this->record = $record;
0 ignored issues
show
Documentation introduced by
The property record does not exist on object<Symbiote\Advanced...lowFieldItemController>. 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...
34
35
        parent::__construct();
36
    }
37
38
    public function index()
39
    {
40
        return $this->edit();
41
    }
42
43
    public function edit()
44
    {
45
        return $this->Form()->forTemplate();
46
    }
47
48
    public function Form()
49
    {
50
        $record    = $this->record;
0 ignored issues
show
Documentation introduced by
The property record does not exist on object<Symbiote\Advanced...lowFieldItemController>. 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...
51
        $fields    = $record->getCMSFields();
52
        $validator = $record->hasMethod('getValidator') ? $record->getValidator() : null;
53
54
        $save = FormAction::create('doSave', _t('WorkflowReminderTask.SAVE', 'Save'));
55
        $save->addExtraClass('btn btn-primary font-icon-save')
56
             ->setUseButtonTag(true);
57
58
        /** @skipUpgrade */
59
        $form = Form::create($this, 'Form', $fields, FieldList::create($save), $validator);
60
        if ($record && $record instanceof DataObject && $record->exists()) {
61
            $form->loadDataFrom($record);
62
        }
63
        return $form;
64
    }
65
66
    public function doSave($data, $form)
0 ignored issues
show
Unused Code introduced by
The parameter $data is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
67
    {
68
        $record = $form->getRecord();
69
70
        if (!$record || !$record->exists()) {
71
            $record = $this->record;
0 ignored issues
show
Documentation introduced by
The property record does not exist on object<Symbiote\Advanced...lowFieldItemController>. 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...
72
        }
73
74
        if (!$record->canEdit()) {
75
            $this->httpError(403);
76
        }
77
78
        if (!$record->isInDb()) {
79
            $record->write();
80
        }
81
82
        $form->saveInto($record);
83
        $record->write();
84
85
        return $this->RootField()->forTemplate();
86
    }
87
88
    public function delete($request)
89
    {
90
        if (!SecurityToken::inst()->checkRequest($request)) {
91
            $this->httpError(400);
92
        }
93
94
        if (!$request->isPOST()) {
95
            $this->httpError(400);
96
        }
97
98
        if (!$this->record->canDelete()) {
0 ignored issues
show
Documentation introduced by
The property record does not exist on object<Symbiote\Advanced...lowFieldItemController>. 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...
99
            $this->httpError(403);
100
        }
101
102
        $this->record->delete();
0 ignored issues
show
Documentation introduced by
The property record does not exist on object<Symbiote\Advanced...lowFieldItemController>. 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...
103
        return $this->RootField()->forTemplate();
104
    }
105
106
    public function RootField()
107
    {
108
        return $this->parent->RootField();
109
    }
110
111
    public function Link($action = null)
112
    {
113
        return Controller::join_links($this->parent->Link(), $this->name, $action);
114
    }
115
}
116