AuthModel::createAuthUrl()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
ccs 0
cts 16
cp 0
rs 9.4286
cc 3
eloc 13
nc 4
nop 2
crap 12
1
<?php
2
namespace Redbox\Twitch\Auth;
3
use Redbox\Twitch\Client;
4
5
class AuthModel
6
{
7
    /**
8
     * @var Client
9
     */
10
    protected $client;
11
12
    public function __construct(Client $client)
13
    {
14
        $this->client = $client;
15
    }
16
17
    public function createAuthUrl($scopes = '', $state = null) {
18
        $addy = '';
19
        if ($this->client->isForceRelogin() === true) {
20
            $addy .= '&force_verify=true';
21
        }
22
23
        if ($state)
24
            $addy .= '&state='.$state;
25
26
        $url =  sprintf('%s/oauth2/authorize/?response_type=code&client_id=%s&redirect_uri=%s&scope=%s%s',
27
            $this->client->getApiUrl(),
28
            $this->client->getClientId(),
29
            $this->client->getRedirectUri(),
30
            urlencode($scopes),
31
            $addy
32
        );
33
        return $url;
34
    }
35
}