Slack   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 40
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getDefaultRequestOptions() 0 14 2
1
<?php namespace nyx\auth\id\protocols\oauth2\providers;
2
3
// Internal dependencies
4
use nyx\auth\id\protocols\oauth2;
5
use nyx\auth;
6
7
/**
8
 * Slack Identity Provider (OAuth 2.0)
9
 *
10
 * @package     Nyx\Auth
11
 * @version     0.1.0
12
 * @author      Michal Chojnacki <[email protected]>
13
 * @copyright   2012-2017 Nyx Dev Team
14
 * @link        https://github.com/unyx/nyx
15
 */
16
class Slack extends oauth2\Provider
17
{
18
    /**
19
     * {@inheritDoc}
20
     */
21
    const URL_AUTHORIZE = 'https://slack.com/oauth/authorize';
22
    const URL_EXCHANGE  = 'https://slack.com/api/oauth.access';
23
    const URL_IDENTIFY  = 'https://slack.com/api/users.identity';
24
25
    /**
26
     * {@inheritDoc}
27
     */
28
    const IDENTITY = auth\id\identities\Slack::class;
29
30
    /**
31
     * {@inheritDoc}
32
     *
33
     * Note: The "identity" scopes cannot be requested alongside other scopes, as Slack otherwise
34
     * returns an 'invalid_scope' error.
35
     */
36
    protected $defaultScopes = ['identity.basic', 'identity.email', 'identity.avatar'];
37
38
    /**
39
     * {@inheritDoc}
40
     */
41
    protected function getDefaultRequestOptions(auth\interfaces\Token $token = null) : array
42
    {
43
        if (isset($token)) {
44
            return parent::getDefaultRequestOptions($token);
45
        }
46
47
        // Slack expects the token to be present in each authorized request as the 'token' parameter.
48
        // Note: Passing it in the body yielded 'not_authed' (ie. no token) errors from Slack.
49
        return array_merge_recursive(parent::getDefaultRequestOptions(), [
50
            'query' => [
51
                'token' => $token->getId()
0 ignored issues
show
Bug introduced by
The method getId cannot be called on $token (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
52
            ]
53
        ]);
54
    }
55
}
56