Completed
Push — master ( 902192...ba7f88 )
by Risan Bagja
02:36
created

AuthorizationFlow   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 1 Features 0
Metric Value
wmc 3
c 6
b 1
f 0
lcom 1
cbo 2
dl 0
loc 49
ccs 7
cts 7
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A authorizeUrl() 0 4 1
A authorize() 0 6 1
A buildAuthorizationUrl() 0 8 1
config() 0 1 ?
1
<?php
2
3
namespace OAuth1\Flows;
4
5
use OAuth1\Contracts\Tokens\RequestTokenInterface;
6
7
trait AuthorizationFlow
8
{
9
    /**
10
     * Authorize url.
11
     *
12
     * @return string
13
     */
14 2
    public function authorizeUrl()
15
    {
16 2
        return $this->config()->authorizeUrl();
17
    }
18
19
    /**
20
     * Request authorization.
21
     *
22
     * @codeCoverageIgnore
23
     *
24
     * @param \OAuth1\Contracts\Tokens\RequestTokenInterface $requestToken
25
     */
26
    public function authorize(RequestTokenInterface $requestToken)
27
    {
28
        header('Location: '.$this->buildAuthorizationUrl($requestToken));
29
30
        exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The method authorize() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
31
    }
32
33
    /**
34
     * Build authorization url.
35
     *
36
     * @param \OAuth1\Contracts\Tokens\RequestTokenInterface $requestToken
37
     *
38
     * @return string
39
     */
40 1
    public function buildAuthorizationUrl(RequestTokenInterface $requestToken)
41
    {
42 1
        $query = http_build_query([
43 1
            'oauth_token' => $requestToken->key(),
44 1
        ]);
45
46 1
        return $this->authorizeUrl().'?'.$query;
47
    }
48
49
    /**
50
     * Get client configuration.
51
     *
52
     * @return \OAuth1\Contracts\ConfigInterface
53
     */
54
    abstract public function config();
55
}
56