Passed
Push — master ( 9b73ba...d26d78 )
by Ryosuke
03:10
created

OAuth2ClientTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 2 Features 0
Metric Value
wmc 6
c 4
b 2
f 0
lcom 1
cbo 1
dl 0
loc 50
ccs 30
cts 30
cp 1
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
withCredentials() 0 1 ?
getInternalCredential() 0 1 ?
getInternalCurl() 0 1 ?
A oauthForBearerToken() 0 10 1
A oauthForBearerTokenAsync() 0 11 1
A invalidateBearerToken() 0 4 1
A invalidateBearerTokenAsync() 0 4 1
A get2() 0 4 1
A get2Async() 0 4 1
1
<?php
2
3
namespace mpyw\Cowitter\Traits;
4
5
use mpyw\Co\CoInterface;
6
use mpyw\Cowitter\Helpers\ResponseYielder;
7
8
trait OAuth2ClientTrait
9
{
10
    abstract public function withCredentials(array $credentails);
11
    abstract protected function getInternalCredential();
12
    abstract protected function getInternalCurl();
13
14 1
    public function oauthForBearerToken()
15 1
    {
16 1
        $obj = ResponseYielder::syncExecDecoded($this->getInternalCurl()->oauthForBearerToken());
17 1
        return $this->withCredentials([
18 1
            $this->getInternalCredential()['consumer_key'],
19 1
            $this->getInternalCredential()['consumer_secret'],
20 1
            $obj->access_token,
21 1
            '',
22
        ]);
23
    }
24
25 1
    public function oauthForBearerTokenAsync()
26 1
    {
27 1
        $obj = (yield ResponseYielder::asyncExecDecoded($this->getInternalCurl()->oauthForBearerToken()));
28 1
        yield CoInterface::RETURN_WITH => $this->withCredentials([
29 1
            $this->getInternalCredential()['consumer_key'],
30 1
            $this->getInternalCredential()['consumer_secret'],
31 1
            $obj->access_token,
32 1
            '',
33
        ]);
34
        // @codeCoverageIgnoreStart
35
    }
36
    // @codeCoverageIgnoreEnd
37
38 1
    public function invalidateBearerToken()
39 1
    {
40 1
        ResponseYielder::syncExecDecoded($this->getInternalCurl()->invalidateBearerToken());
41 1
    }
42
43 1
    public function invalidateBearerTokenAsync()
44 1
    {
45 1
        yield ResponseYielder::asyncExecDecoded($this->getInternalCurl()->invalidateBearerToken());
46 1
    }
47
48 1
    public function get2($endpoint, array $params = [], $return_response_object = false)
49 1
    {
50 1
        return ResponseYielder::syncExecDecoded($this->getInternalCurl()->get2($endpoint, $params), $return_response_object);
51
    }
52
53 1
    public function get2Async($endpoint, array $params = [], $return_response_object = false)
54 1
    {
55 1
        return ResponseYielder::asyncExecDecoded($this->getInternalCurl()->get2($endpoint, $params), $return_response_object);
56
    }
57
}
58