Completed
Push — master ( 78d48a...8014f5 )
by Дмитрий
11:07
created

AbstractBaseProvider::__construct()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4.3731

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 10
cts 14
cp 0.7143
rs 9.2
c 0
b 0
f 0
cc 4
eloc 10
nc 8
nop 4
crap 4.3731
1
<?php
2
/**
3
 * SocialConnect project
4
 * @author: Patsura Dmitry https://github.com/ovr <[email protected]>
5
 */
6
7
namespace SocialConnect\Provider;
8
9
use SocialConnect\Common\Http\Client\ClientInterface;
10
use SocialConnect\Provider\Session\SessionInterface;
11
12
abstract class AbstractBaseProvider
13
{
14
    /**
15
     * @var Consumer
16
     */
17
    protected $consumer;
18
19
    /**
20
     * @var array
21
     */
22
    protected $scope = [];
23
24
    /**
25
     * @var array
26
     */
27
    protected $fields = [];
28
29
    /**
30
     * @var ClientInterface
31
     */
32
    protected $httpClient;
33
34
    /**
35
     * @var string
36
     */
37
    protected $redirectUri;
38
39
    /**
40
     * @var SessionInterface
41
     */
42
    protected $session;
43
44
    /**
45
     * @param ClientInterface $httpClient
46
     * @param SessionInterface $session
47
     * @param array $parameters
48
     */
49 12
    public function __construct(ClientInterface $httpClient, SessionInterface $session, Consumer $consumer, array $parameters)
50
    {
51 12
        $this->httpClient = $httpClient;
52 12
        $this->session = $session;
53 12
        $this->consumer = $consumer;
54
55 12
        if (isset($parameters['scope'])) {
56
            $this->setScope($parameters['scope']);
57
        }
58
59 12
        if (isset($parameters['fields'])) {
60
            $this->setFields($parameters['fields']);
61
        }
62
63 12
        if (isset($parameters['redirectUri'])) {
64 10
            $this->redirectUri = $parameters['redirectUri'];
65 10
        }
66 12
    }
67
68
    /**
69
     * @return mixed
70
     */
71 3
    protected function getRedirectUri()
72
    {
73 3
        return $this->redirectUri;
74
    }
75
76
    /**
77
     * @return string
78
     */
79 3
    public function getRedirectUrl()
80
    {
81 3
        return $this->getRedirectUri() . '/' . $this->getName() . '/';
82
    }
83
84
    /**
85
     * @return string
86
     */
87
    abstract public function getBaseUri();
88
89
    /**
90
     * Return Provider's name
91
     *
92
     * @return string
93
     */
94
    abstract public function getName();
95
96
    /**
97
     * @param array $requestParameters
98
     * @return \SocialConnect\Provider\AccessTokenInterface
99
     */
100
    abstract public function getAccessTokenByRequestParameters(array $requestParameters);
101
102
    /**
103
     * @return string
104
     */
105
    abstract public function makeAuthUrl();
106
107
    /**
108
     * Get current user identity from social network by $accessToken
109
     *
110
     * @param AccessTokenInterface $accessToken
111
     * @return \SocialConnect\Common\Entity\User
112
     *
113
     * @throws \SocialConnect\Provider\Exception\InvalidResponse
114
     */
115
    abstract public function getIdentity(AccessTokenInterface $accessToken);
116
117
    /**
118
     * @return array
119
     */
120
    public function getScope()
121
    {
122
        return $this->scope;
123
    }
124
125
    /**
126
     * @param array $scope
127
     */
128
    public function setScope(array $scope)
129
    {
130
        $this->scope = $scope;
131
    }
132
133
    /**
134
     * @return string
135
     */
136
    public function getScopeInline()
137
    {
138
        return implode(',', $this->scope);
139
    }
140
141
    /**
142
     * @return array
143
     */
144
    public function getFields()
145
    {
146
        return $this->fields;
147
    }
148
149
    /**
150
     * @param array $fields
151
     */
152
    public function setFields(array $fields)
153
    {
154
        $this->fields = $fields;
155
    }
156
157
    /**
158
     * @return string
159
     */
160 3
    public function getFieldsInline()
161
    {
162 3
        return implode(',', $this->fields);
163
    }
164
165
    /**
166
     * @return \SocialConnect\Provider\Consumer
167
     */
168 1
    public function getConsumer()
169
    {
170 1
        return $this->consumer;
171
    }
172
}
173