Completed
Push — master ( 2c9601...116879 )
by Дмитрий
04:44
created

AbstractBaseProvider::getRedirectUri()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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