StripeSlackSiteConfigExtension   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 98
rs 10
c 0
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A updateFieldLabels() 0 17 1
B updateCMSFields() 0 39 5
A onBeforeWrite() 0 9 2
1
<?php
2
3
4
/**
5
 * Class StripeSlackSiteConfigExtension
6
 *
7
 * @property SiteConfig|StripeSlackSiteConfigExtension $owner
8
 * @property string $SlackURL
9
 * @property string $SlackClientID
10
 * @property string $SlackClientSecret
11
 * @property string $SlackChannel
12
 * @property string $SlackToken
13
 * @property boolean $ClearSecrets
14
 * @property int $SlackBackURLID
15
 * @property int $SlackErrorBackURLID
16
 * @method SiteTree SlackBackURL()
17
 * @method SiteTree SlackErrorBackURL()
18
 */
19
class StripeSlackSiteConfigExtension extends DataExtension
0 ignored issues
show
Bug introduced by
The type DataExtension 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...
20
{
21
    private static $db = [
22
        'SlackURL'          => 'Varchar(255)',
23
        'SlackClientID'     => 'Varchar(255)',
24
        'SlackClientSecret' => 'Varchar(255)',
25
        'SlackChannel'      => 'Varchar(255)',
26
        'SlackToken'        => 'Varchar(255)',
27
        // This is here to support the IDE's
28
        'ClearSecrets'      => 'Boolean(false)'
29
    ];
30
31
    private static $has_one = [
0 ignored issues
show
Unused Code introduced by
The property $has_one is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
32
        'SlackBackURL'      => SiteTree::class,
0 ignored issues
show
Bug introduced by
The type SiteTree 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...
33
        'SlackErrorBackURL' => SiteTree::class
34
    ];
35
36
    private static $helptexts = [
37
        'Link'         => 'To activate your StripeSlack, Please have an admin activate StripeSlack by clicking on this link.',
38
        'ClearSecrets' => 'Checking this checkbox will clear out the Client Secret and (invisible in the CMS) Client Token. In case your admin left the group, or you want a new admin to sent the invite',
39
        'Channel'      => 'You can get the ID by right clicking on your channel and select "copy link". Open the copied link in a browser and copy the part after "messages/" in to this field',
40
        'URLHelp'      => 'Include the "https://" part',
41
        'Extended'     => '<p><a href="https://github.com/Firesphere/silverstripe-stripeslack/blob/master/readme.md">Extensive instructions can be found on GitHub</a></p>'
42
    ];
43
44
    public function updateFieldLabels(&$labels)
45
    {
46
        $labels['SlackURL'] = _t('StripeSlackSiteConfigExtension.SlackURL', 'URL Of the Slack channel');
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

46
        $labels['SlackURL'] = /** @scrutinizer ignore-call */ _t('StripeSlackSiteConfigExtension.SlackURL', 'URL Of the Slack channel');
Loading history...
47
        $labels['SlackClientID'] = _t('StripeSlackSiteConfigExtension.SlackClientID', 'Client ID for your Slack App');
48
        $labels['SlackClientSecret'] = _t(
49
            'StripeSlackSiteConfigExtension.SlackClientSecret',
50
            'Client Secret for your Slack App'
51
        );
52
        $labels['SlackChannel'] = _t('StripeSlackSiteConfigExtension.SlackChannel', 'The ID of your channel');
53
        $labels['ClearSecrets'] = _t('StripeSlackSiteConfigExtension.ClearSecrets', 'Clear Secrets and Tokens');
54
        $labels['SlackBackURL'] = _t(
55
            'StripeSlackSiteConfigExtension.SlackBackURL',
56
            'URL to redirect when request is successful (leave empty if you want use the Stripe Slack Page)'
57
        );
58
        $labels['SlackErrorBackURL'] = _t(
59
            'StripeSlackSiteConfigExtension.SlackErrorBackURL',
60
            'URL to redirect when request is unsuccessful (leave empty if you want to use the Stripe Slack Page)'
61
        );
62
    }
63
64
    public function updateCMSFields(FieldList $fields)
0 ignored issues
show
Bug introduced by
The type FieldList 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...
65
    {
66
        $fields->removeByName(['SlackToken']);
67
        $fields->addFieldsToTab('Root.Slack', [
68
            $url = TextField::create('SlackURL', $this->owner->fieldLabel('SlackURL')),
0 ignored issues
show
Bug introduced by
The type TextField 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...
69
            $channel = TextField::create('SlackChannel', $this->owner->fieldLabel('SlackChannel')),
70
            TextField::create('SlackClientID', $this->owner->fieldLabel('SlackClientID')),
71
            PasswordField::create('SlackClientSecret', $this->owner->fieldLabel('SlackClientSecret')),
0 ignored issues
show
Bug introduced by
The type PasswordField 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...
72
            TreeDropdownField::create('SlackBackURLID', $this->owner->fieldLabel('SlackBackURL'), 'SiteTree'),
0 ignored issues
show
Bug introduced by
The type TreeDropdownField 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...
73
            TreeDropdownField::create('SlackErrorBackURLID', $this->owner->fieldLabel('SlackErrorBackURL'), 'SiteTree'),
74
        ]);
75
        if (
76
            $this->owner->SlackURL &&
77
            $this->owner->SlackClientID &&
78
            $this->owner->SlackClientSecret &&
79
            !$this->owner->SlackToken
80
        ) {
81
            $domain = Director::absoluteURL('/SlackAuthorization/');
82
            $text = LiteralField::create(
0 ignored issues
show
Bug introduced by
The type LiteralField 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...
83
                'link',
84
                '<p><a href="' . $this->owner->SlackURL . '/oauth/authorize?client_id=' . $this->owner->SlackClientID . '&scope=client&redirect_uri=' . $domain . '">' .
85
                static::$helptexts['Link'] .
0 ignored issues
show
Bug introduced by
Since $helptexts is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $helptexts to at least protected.
Loading history...
86
                '</a></p>'
87
            );
88
            $fields->addFieldToTab('Root.Slack', $text);
89
        } else {
90
            $fields->addFieldsToTab(
91
                'Root.Slack',
92
                [
93
                    $secretField = CheckboxField::create('ClearSecrets', $this->owner->fieldLabel('ClearSecrets')),
0 ignored issues
show
Bug introduced by
The type CheckboxField 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...
94
                    ReadonlyField::create('Users on Slack', SlackStatusController::create()->usercount(new SS_HTTPRequest('GET', '/SlackStatus/usercount')))
0 ignored issues
show
Bug introduced by
The type ReadonlyField 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 SS_HTTPRequest 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...
95
                ]
96
            );
97
            $secretField->setDescription(static::$helptexts['ClearSecrets']);
98
        }
99
        $channel->setDescription(static::$helptexts['Channel']);
100
        $url->setDescription(static::$helptexts['URLHelp']);
101
102
        $fields->addFieldToTab('Root.Slack', LiteralField::create('instructions', static::$helptexts['Extended']));
103
    }
104
105
    /**
106
     * Clear out the secrets if the checkbox is checked
107
     */
108
    public function onBeforeWrite()
109
    {
110
        parent::onBeforeWrite();
111
        if ($this->owner->ClearSecrets) {
112
            $this->owner->SlackClientSecret = '';
113
            $this->owner->SlackToken = '';
114
        }
115
        // Always set back to false so the checkbox won't stay ticked
116
        $this->owner->ClearSecrets = false;
117
    }
118
}
119