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.

FileWorkflowApplicable   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 5
dl 0
loc 72
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A updateSummaryFields() 0 5 1
A updateCMSFields() 0 25 3
B onAfterWrite() 0 37 8
1
<?php
2
3
namespace Symbiote\AdvancedWorkflow\Extensions;
4
5
use SilverStripe\Forms\FieldList;
6
use SilverStripe\Forms\Form;
7
8
/**
9
 * WorkflowApplicable extension specifically for File objects, which don't have the same CMS
10
 * UI structure so need to be handled a little differently. Additionally, it doesn't really
11
 * work without custom code to handle the triggering of workflow, and in general is not
12
 * ready for production use just yet.
13
 *
14
 * @author  [email protected]
15
 * @license BSD License (http://silverstripe.org/bsd-license/)
16
 * @package advancedworkflow
17
 */
18
class FileWorkflowApplicable extends WorkflowApplicable
19
{
20
    public function updateSummaryFields(&$fields)
21
    {
22
        $fields['ID'] = 'ID';
23
        $fields['ParentID'] = 'ParentID';
24
    }
25
26
    public function updateCMSFields(FieldList $fields)
27
    {
28
        if (!$this->owner->ID) {
29
            return $fields;
30
        }
31
        parent::updateCMSFields($fields);
32
33
        // add the workflow fields directly. It's a requirement of workflow on file objects
34
        // that CMS admins mark the workflow step as being editable for files to be administerable
35
        $active = $this->getWorkflowService()->getWorkflowFor($this->owner);
36
        if ($active) {
37
            $current = $active->CurrentAction();
38
            $wfFields = $active->getWorkflowFields();
39
40
            // loading data in a somewhat hack way
41
            $form = new Form($this, 'DummyForm', $wfFields, new FieldList());
0 ignored issues
show
Documentation introduced by
$this is of type this<Symbiote\AdvancedWo...FileWorkflowApplicable>, but the function expects a null|object<SilverStripe\Control\RequestHandler>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
42
            $form->loadDataFrom($current);
43
44
            $fields->findOrMakeTab(
45
                'Root.WorkflowActions',
46
                _t('Workflow.WorkflowActionsTabTitle', 'Workflow Actions')
47
            );
48
            $fields->addFieldsToTab('Root.WorkflowActions', $wfFields);
49
        }
50
    }
51
52
    public function onAfterWrite()
53
    {
54
        parent::onAfterWrite();
55
56
        $workflow = $this->getWorkflowService()->getWorkflowFor($this->owner);
57
        $rawData = $this->owner->toMap();
58
        if ($workflow && $this->owner->TransitionID) {
59
            // we want to transition, so do so if that's a valid transition to take.
60
            $action = $workflow->CurrentAction();
61
            if (!$this->canEditWorkflow()) {
62
                return;
63
            }
64
65
            $allowedFields = $workflow->getWorkflowFields()->saveableFields();
66
            unset($allowedFields['TransitionID']);
67
68
            $allowed = array_keys($allowedFields);
69
70
            foreach ($allowed as $field) {
71
                if (isset($rawData[$field])) {
72
                    $action->$field = $rawData[$field];
73
                }
74
            }
75
76
            $action->write();
77
78
            if (isset($rawData['TransitionID']) && $rawData['TransitionID']) {
79
                // unset the transition ID so this doesn't get re-executed
80
                $this->owner->TransitionID = null;
81
                $this->getWorkflowService()->executeTransition($this->owner, $rawData['TransitionID']);
82
            } else {
83
                // otherwise, just try to execute the current workflow to see if it
84
                // can now proceed based on user input
85
                $workflow->execute();
86
            }
87
        }
88
    }
89
}
90