Passed
Push — master ( fd7b57...b473d1 )
by Simon
02:17
created

SlackSignupForm::getFormFields()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 14
nc 2
nop 0
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
4
class SlackSignupForm extends Form
0 ignored issues
show
Bug introduced by
The type Form 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...
5
{
6
    private $siteConfig;
7
8
    /**
9
     * SlackSignupForm constructor.
10
     * @param Controller $controller
11
     * @param string $name
12
     * @param FieldList $fields
13
     * @param FieldList $actions
14
     * @param null $validator
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $validator is correct as it would always require null to be passed?
Loading history...
15
     */
16
    public function __construct(
17
        Controller $controller = null,
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...
18
        $name,
19
        FieldList $fields = null,
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...
20
        FieldList $actions = null,
21
        $validator = null
22
    ) {
23
        $this->siteConfig = 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...
24
        if (!$controller) {
25
            $controller = Controller::curr();
26
        }
27
        if (!$fields) {
28
            $fields = $this->getFormFields();
29
        }
30
        if (!$actions) {
31
            $actions = $this->getFormActions();
32
        }
33
34
        parent::__construct($controller, $name, $fields, $actions, $validator);
35
    }
36
37
    /**
38
     * @return FieldList
39
     */
40
    protected function getFormFields()
41
    {
42
        if (!$this->siteConfig->SlackToken) {
43
            return FieldList::create([
44
                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...
45
                    'Setup',
46
                    _t('SlackSignupForm.Setup', 'StripeSlack has not yet been configured correctly')
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
                    /** @scrutinizer ignore-call */ 
47
                    _t('SlackSignupForm.Setup', 'StripeSlack has not yet been configured correctly')
Loading history...
47
                )
48
            ]);
49
        }
50
        $fields = FieldList::create(
51
            [
52
                LiteralField::create(
53
                    'Intro',
54
                    _t('SlackSignupForm.Intro', 'Fill out the form below to request access to Slack')
55
                ),
56
                TextField::create('Name', _t('SlackSignupForm.Name', 'My name is')),
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...
57
                EmailField::create('Email', _t('SlackSignupForm.Email', 'My email address is'))
0 ignored issues
show
Bug introduced by
The type EmailField 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...
58
                    ->setAttribute('required', true),
59
            ]
60
        );
61
62
        $this->extend('updateFormFields', $fields);
63
64
        return $fields;
65
    }
66
67
    /**
68
     * @return FieldList
69
     */
70
    protected function getFormActions()
71
    {
72
        if (!$this->siteConfig->SlackToken) {
73
            return FieldList::create();
74
        }
75
76
        return FieldList::create([
77
            FormAction::create('submitSlackForm', _t('SlackSignupForm.Submit', 'Submit'))
0 ignored issues
show
Bug introduced by
The type 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...
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

77
            FormAction::create('submitSlackForm', /** @scrutinizer ignore-call */ _t('SlackSignupForm.Submit', 'Submit'))
Loading history...
78
        ]);
79
    }
80
81
    /**
82
     * @param array $data
83
     * @param SlackSignupForm $form
84
     */
85
    protected function submitSlackForm($data, $form)
86
    {
87
        $signup = SlackInvite::create();
88
        $form->saveInto($signup);
89
        $userID = $signup->write();
90
        /** @var SlackInvite $signup We need to re-fetch from the database after writing */
91
        $signup = SlackInvite::get()->byID($userID);
92
        $this->redirectSlack($signup->Invited);
93
    }
94
95
    /**
96
     * This method seems long, but it's primarily switching between CMS and normal user
97
     * Plus a check if the URL's are set on the config.
98
     *
99
     * @param boolean $success
100
     * @return bool|SS_HTTPResponse
0 ignored issues
show
Bug introduced by
The type SS_HTTPResponse 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...
101
     */
102
    public function redirectSlack($success)
103
    {
104
        $config = SiteConfig::current_site_config();
105
        if (!$success) {
106
            if ($config->SlackErrorBackURLID) {
107
                return $this->controller->redirect($config->SlackErrorBackURL()->Link());
108
            }
109
            $this->controller->redirect($this->controller->Link('error'));
110
        }
111
        if ($config->SlackBackURLID) {
112
            return $this->controller->redirect($config->SlackBackURL()->Link());
113
        }
114
115
        return $this->controller->redirect($this->controller->Link('success'));
116
    }
117
}
118