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.

GridFieldWorkflowRestrictedEditButton   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A augmentColumns() 0 6 2
A getColumnAttributes() 0 14 4
A getColumnMetadata() 0 6 2
A getColumnsHandled() 0 4 1
A getColumnContent() 0 7 1
1
<?php
2
3
namespace Symbiote\AdvancedWorkflow\Forms\GridField;
4
5
use SilverStripe\Control\Controller;
6
use SilverStripe\Forms\GridField\GridField_ColumnProvider;
7
use SilverStripe\Forms\GridField\GridFieldEditButton;
8
use SilverStripe\Security\Permission;
9
use SilverStripe\Security\Security;
10
use SilverStripe\View\ArrayData;
11
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowInstance;
12
13
/**
14
 *
15
 * @package advancedworkflow
16
 */
17
class GridFieldWorkflowRestrictedEditButton implements GridField_ColumnProvider
18
{
19
    /**
20
     * Add a column
21
     *
22
     * @param type $gridField
23
     * @param array $columns
24
     */
25
    public function augmentColumns($gridField, &$columns)
26
    {
27
        if (!in_array('Actions', $columns)) {
28
            $columns[] = 'Actions';
29
        }
30
    }
31
32
    /**
33
     * Append a 'disabled' CSS class to GridField rows whose WorkflowInstance records are not viewable/editable
34
     * by the current user.
35
     *
36
     * This is used to visually "grey out" records and it's leveraged in some overriding JavaScript, to maintain
37
     * an ability to click the target object's hyperlink.
38
     *
39
     * @param GridField $gridField
40
     * @param DataObject $record
41
     * @param string $columnName
42
     * @return array
43
     */
44
    public function getColumnAttributes($gridField, $record, $columnName)
45
    {
46
        $defaultAtts = array('class' => 'col-buttons');
47
        if ($record instanceof WorkflowInstance) {
48
            $isAdmin = Permission::check('ADMIN');
49
            $isAssigned = $record->getAssignedMembers()->find('ID', Security::getCurrentUser()->ID);
50
            if (!$isAdmin && !$isAssigned) {
51
                $atts['class'] = $defaultAtts['class'].' disabled';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$atts was never initialized. Although not strictly required by PHP, it is generally a good practice to add $atts = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
52
                return $atts;
53
            }
54
            return $defaultAtts;
55
        }
56
        return $defaultAtts;
57
    }
58
59
    /**
60
     * Add the title
61
     *
62
     * @param GridField $gridField
63
     * @param string $columnName
64
     * @return array
65
     */
66
    public function getColumnMetadata($gridField, $columnName)
67
    {
68
        if ($columnName == 'Actions') {
69
            return array('title' => '');
70
        }
71
    }
72
73
    /**
74
     * Which columns are handled by this component
75
     *
76
     * @param type $gridField
77
     * @return type
78
     */
79
    public function getColumnsHandled($gridField)
80
    {
81
        return array('Actions');
82
    }
83
84
    /**
85
     * @param GridField $gridField
86
     * @param DataObject $record
87
     * @param string $columnName
88
     *
89
     * @return string - the HTML for the column
90
     */
91
    public function getColumnContent($gridField, $record, $columnName)
92
    {
93
        $data = new ArrayData(array(
94
            'Link' => Controller::join_links($gridField->Link('item'), $record->ID, 'edit')
95
        ));
96
        return $data->renderWith(GridFieldEditButton::class);
97
    }
98
}
99