GridfieldInviteResendAction   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 115
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 115
rs 10
c 0
b 0
f 0
wmc 14

7 Methods

Rating   Name   Duplication   Size   Complexity  
A augmentColumns() 0 4 2
A getColumnsHandled() 0 3 1
A getColumnAttributes() 0 3 1
A getColumnMetadata() 0 4 2
A handleAction() 0 19 4
B getColumnContent() 0 32 3
A getActions() 0 3 1
1
<?php
2
3
/**
4
 * class GridfieldInviteResendAction adds the resend button to the CMS for easy re-inviting
5
 */
6
class GridfieldInviteResendAction implements GridField_ColumnProvider, GridField_ActionProvider
0 ignored issues
show
Bug introduced by
The type GridField_ColumnProvider was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Bug introduced by
The type GridField_ActionProvider was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
{
8
9
    /**
10
     * @param GridField $gridField
11
     * @param array $columns
12
     */
13
    public function augmentColumns($gridField, &$columns)
14
    {
15
        if (!in_array('Actions', $columns, true)) {
16
            $columns[] = 'Actions';
17
        }
18
    }
19
20
    /**
21
     * {@inheritDoc}
22
     */
23
    public function getColumnAttributes($gridField, $record, $columnName)
24
    {
25
        return array('class' => 'col-buttons');
26
    }
27
28
    /**
29
     * {@inheritDoc}
30
     */
31
    public function getColumnMetadata($gridField, $columnName)
32
    {
33
        if ($columnName === 'Actions') {
34
            return array('title' => '');
35
        }
36
    }
37
38
    /**
39
     * {@inheritDoc}
40
     */
41
    public function getColumnsHandled($gridField)
42
    {
43
        return array('Actions');
44
    }
45
46
    /**
47
     * @param GridField $gridField
48
     * @param SlackInvite $record
49
     * @param string $columnName
50
     * @return HTMLText
0 ignored issues
show
Bug introduced by
The type HTMLText was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
51
     */
52
    public function getColumnContent($gridField, $record, $columnName)
53
    {
54
        $config = SiteConfig::current_site_config();
0 ignored issues
show
Bug introduced by
The type SiteConfig was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
55
        // No point in showing the re-send button, if there's no token
56
        if ($config->SlackToken) {
57
            if (!$record->Invited) {
58
                $field = GridField_FormAction::create(
0 ignored issues
show
Bug introduced by
The type GridField_FormAction was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
59
                    $gridField,
60
                    'Retry' . $record->ID,
61
                    false,
62
                    'resend',
63
                    ['RecordID' => $record->ID]
64
                )
65
                    ->addExtraClass('gridfield-button-resend')
66
                    ->setAttribute('title', 'Retry invite')
67
                    ->setAttribute('data-icon', 'arrow-circle-135-left')
68
                    ->setDescription(_t('GridfieldInviteResendAction.Resend', 'Retry failed invitation'));
0 ignored issues
show
Bug introduced by
The function _t was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

68
                    ->setDescription(/** @scrutinizer ignore-call */ _t('GridfieldInviteResendAction.Resend', 'Retry failed invitation'));
Loading history...
69
            } else {
70
                $field = GridField_FormAction::create(
71
                    $gridField,
72
                    'Resend',
73
                    false,
74
                    'resend',
75
                    ['RecordID' => $record->ID]
76
                )
77
                    ->addExtraClass('gridfield-button-resend')
78
                    ->setAttribute('title', 'Resend invite')
79
                    ->setAttribute('data-icon', 'arrow-circle-double')
80
                    ->setDescription('Resend invite');
81
            }
82
83
            return $field->Field();
84
        }
85
    }
86
87
    /**
88
     * {@inheritDoc}
89
     */
90
    public function getActions($gridField)
91
    {
92
        return array('resend');
93
    }
94
95
    /**
96
     * @param GridField $gridField
97
     * @param $actionName
98
     * @param $arguments
99
     * @param $data
100
     * @throws \ValidationException
101
     */
102
    public function handleAction(GridField $gridField, $actionName, $arguments, $data)
103
    {
104
        if ($actionName === 'resend') {
105
            /** @var SlackInvite $item */
106
            $item = SlackInvite::get()->byID($arguments['RecordID']);
107
            if (!$item) {
108
                return;
109
            }
110
111
            $result = $item->resendInvite();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $result is correct as $item->resendInvite() targeting SlackInvite::resendInvite() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
112
            if ($result === true) {
113
                Controller::curr()->getResponse()->setStatusCode(
0 ignored issues
show
Bug introduced by
The type Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
114
                    200,
115
                    'User successfully invited.'
116
                );
117
            } else {
118
                Controller::curr()->getResponse()->setStatusCode(
119
                    200,
120
                    $result
121
                );
122
            }
123
        }
124
    }
125
}
126