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

SlackAuthController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 72
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 15 1
A getQuery() 0 10 1
A saveToken() 0 7 1
A getConfig() 0 11 2
1
<?php
2
3
4
/**
5
 * Class SlackAuthController
6
 *
7
 */
8
class SlackAuthController extends Controller
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...
9
{
10
11
    /**
12
     * It seems like a lot is going on here
13
     * But in reality, it's mainly just configuration stuff
14
     *
15
     * @param SS_HTTPRequest $request
16
     */
17
    public function index(SS_HTTPRequest $request)
0 ignored issues
show
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...
18
    {
19
        list($code, $config, $baseURL, $url) = $this->getConfig($request);
20
21
        $query = $this->getQuery($config, $code);
22
23
        // Setup and request the code
24
        // @todo rewrite to Guzzle for SS4
25
        $service = RestfulService::create($baseURL, 'GET', null, 0);
0 ignored issues
show
Bug introduced by
The type RestfulService 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...
26
        $response = $service->request($url . $query);
27
28
        $this->saveToken($response, $config);
29
30
        // A successful write should go back to the admin
31
        $this->redirect('/admin/settings#Root_Slack');
32
    }
33
34
    /**
35
     * @param $config
36
     * @param $code
37
     * @return string
38
     */
39
    public function getQuery($config, $code)
40
    {
41
        $params = [
42
            'client_id'     => $config->SlackClientID,
43
            'client_secret' => $config->SlackClientSecret,
44
            'code'          => $code,
45
            'redirect_uri'  => Director::absoluteURL('/SlackAuthorization/'),
46
        ];
47
48
        return http_build_query($params);
49
    }
50
51
    /**
52
     * @param RestfulService_Response $response
0 ignored issues
show
Bug introduced by
The type RestfulService_Response 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...
53
     * @param SiteConfig $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...
54
     * @throws \ValidationException
55
     */
56
    public function saveToken($response, $config)
57
    {
58
        // Convert the JSON to use in our config (hidden from user view)
59
        $result = Convert::json2array($response->getBody());
0 ignored issues
show
Bug introduced by
The type Convert 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...
60
61
        $config->SlackToken = $result['access_token'];
62
        $config->write();
63
    }
64
65
    /**
66
     * @param SS_HTTPRequest $request
67
     * @return array
68
     */
69
    public function getConfig(SS_HTTPRequest $request)
70
    {
71
        // Code param
72
        $code = $request->getVar('code');
73
        $config = SiteConfig::current_site_config();
74
        // Build the URL
75
        $baseURL = $config->SlackURL;
76
        $baseURL = (substr($baseURL, -1) === '/') ? $baseURL : $baseURL . '/';
77
        $url = 'api/oauth.access?';
78
79
        return array($code, $config, $baseURL, $url);
80
    }
81
}
82