Passed
Push — master ( c3677e...93f23d )
by Ryosuke
07:29
created

BaseClientTrait   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 47.83%

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 3
dl 0
loc 82
ccs 22
cts 46
cp 0.4783
rs 10
c 0
b 0
f 0

19 Methods

Rating   Name   Duplication   Size   Complexity  
getInternalCurl() 0 1 ?
setInternalCredential() 0 1 ?
setInternalOptions() 0 1 ?
getInternalCredential() 0 1 ?
getInternalOptions() 0 1 ?
setInternalCurl() 0 1 ?
A __construct() 0 6 1
A offsetGet() 0 4 1
A withCredentials() 0 7 1
A withOptions() 0 7 1
A getAuthorizeUrl() 0 4 1
A offsetSet() 0 4 1
A offsetUnset() 0 4 1
A offsetExists() 0 4 1
A __get() 0 4 1
A __isset() 0 4 1
A getCredentials() 0 4 1
A getOptions() 0 4 2
A getAuthenticateUrl() 0 4 1
1
<?php
2
3
namespace mpyw\Cowitter\Traits;
4
5
use mpyw\Cowitter\Helpers\CurlOptionNormalizer;
6
use mpyw\Cowitter\Components\CurlInitializer;
7
use mpyw\Cowitter\Components\Credential;
8
9
trait BaseClientTrait
10
{
11
    abstract protected function getInternalCredential();
12
    abstract protected function getInternalOptions();
13
    abstract protected function getInternalCurl();
14
    abstract protected function setInternalCredential(Credential $credential);
15
    abstract protected function setInternalOptions(array $options);
16
    abstract protected function setInternalCurl(CurlInitializer $curl);
17
18 69
    public function __construct(array $credentials, array $options = [])
19 69
    {
20 69
        $this->setInternalCredential(new Credential($credentials));
21 68
        $this->setInternalOptions(CurlOptionNormalizer::numerifyAll($options));
22 68
        $this->setInternalCurl(new CurlInitializer($this->getInternalCredential(), $this->getInternalOptions()));
23 68
    }
24
25 10
    public function offsetGet($offset)
26 10
    {
27 10
        return $this->getInternalCredential()->offsetGet($offset);
28
    }
29
30
    public function offsetSet($offset, $value)
31
    {
32
        return $this->getInternalCredential()->offsetSet($offset, $value);
33
    }
34
35
    public function offsetUnset($offset)
36
    {
37
        return $this->getInternalCredential()->offsetUnset($offset);
38
    }
39
40
    public function offsetExists($offset)
41
    {
42
        return $this->getInternalCredential()->offsetExists($offset);
43
    }
44
45
    public function __get($key)
46
    {
47
        return $this->getInternalCredential()->$key;
48
    }
49
50
    public function __isset($key)
51
    {
52
        return isset($this->getInternalCredential()->$key);
53
    }
54
55 12
    public function withCredentials(array $credentials)
56 12
    {
57 12
        return new static(
58 12
            array_replace($this->getInternalCredential()->toArray(), $credentials),
59 12
            $this->getInternalOptions()
60
        );
61
    }
62
63 6
    public function withOptions(array $options)
64 6
    {
65 6
        return new static(
66 6
            $this->getInternalCredential()->toArray(),
67 6
            array_replace($this->getInternalOptions(), $options)
68
        );
69
    }
70
71
    public function getCredentials($assoc = false)
72
    {
73
        return $this->getInternalCredential()->toArray($assoc);
74
    }
75
76
    public function getOptions($stringify = false)
77
    {
78
        return $stringify ? CurlOptionNormalizer::stringifyAll($this->getInternalOptions()) : $this->getInternalOptions();
79
    }
80
81 4
    public function getAuthorizeUrl($force_login = false)
82 4
    {
83 4
        return $this->getInternalCredential()->getAuthorizeUrl($force_login);
84
    }
85
86
    public function getAuthenticateUrl($force_login = false)
87
    {
88
        return $this->getInternalCredential()->getAuthenticateUrl($force_login);
89
    }
90
}
91