Completed
Push — master ( 360314...c2aa1e )
by Ryosuke
08:47
created

BaseClientTrait::__get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
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 6
    public function __construct(array $credentials, array $options = [])
19 6
    {
20 6
        $this->setInternalCredential(new Credential($credentials));
21 6
        $this->setInternalOptions(CurlOptionNormalizer::numerifyAll($options));
22 6
        $this->setInternalCurl(new CurlInitializer($this->getInternalCredential(), $this->getInternalOptions()));
23 6
    }
24
25
    public function offsetGet($offset)
26
    {
27
        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
    public function withCredentials(array $credentials)
56
    {
57
        return new static($credentials, $this->getInternalOptions());
58
    }
59
60
    public function withOptions(array $options)
61
    {
62
        return new static($this->getInternalCredential()->toArray(), $options);
63
    }
64
65
    public function getCredentials($assoc = false)
66
    {
67
        return $this->getInternalCredential()->toArray($assoc);
68
    }
69
70
    public function getOptions($stringify = false)
71
    {
72
        return $stringify ? CurlOptionNormalizer::stringifyAll($this->getInternalOptions()) : $this->getInternalOptions();
73
    }
74
75
    public function getAuthorizeUrl($force_login = false)
76
    {
77
        return $this->getInternalCredential()->getAuthorizeUrl($force_login);
78
    }
79
80
    public function getAuthenticateUrl($force_login = false)
81
    {
82
        return $this->getInternalCredential()->getAuthenticateUrl($force_login);
83
    }
84
}
85