Completed
Push — master ( d08c69...d34b48 )
by Дмитрий
14:26
created

src/Provider/AbstractBaseProvider.php (1 issue)

php_md.boolean_get_method_name

Coding Style Naming Minor

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
     * @var array
46
     */
47
    protected $options = [];
48
49 303
    /**
50
     * @param ClientInterface $httpClient
51 303
     * @param SessionInterface $session
52 303
     * @param array $parameters
53 303
     */
54
    public function __construct(ClientInterface $httpClient, SessionInterface $session, Consumer $consumer, array $parameters)
55 303
    {
56
        $this->httpClient = $httpClient;
57
        $this->session = $session;
58
        $this->consumer = $consumer;
59 303
60
        if (isset($parameters['scope'])) {
61
            $this->setScope($parameters['scope']);
62
        }
63 303
64 299
        if (isset($parameters['fields'])) {
65 299
            $this->setFields($parameters['fields']);
66 303
        }
67
68
        if (isset($parameters['redirectUri'])) {
69
            $this->redirectUri = $parameters['redirectUri'];
70
        }
71 43
72
        if (isset($parameters['options'])) {
73 43
            $this->options = $parameters['options'];
74
        }
75
    }
76
77
    /**
78
     * @param string $key
79 43
     * @param bool $default
80
     * @return bool
81 43
     */
82
    public function getBoolOption($key, $default)
0 ignored issues
show
Coding Style Naming introduced by
The 'getBoolOption()' method which returns a boolean should be named 'is...()' or 'has...()'
Loading history...
83
    {
84
        if (array_key_exists($key, $this->options)) {
85
            return (bool) $this->options[$key];
86
        }
87
88
        return $default;
89
    }
90
91
    /**
92
     * @return mixed
93
     */
94
    protected function getRedirectUri()
95
    {
96
        return $this->redirectUri;
97
    }
98
99
    /**
100
     * @return string
101
     */
102
    public function getRedirectUrl()
103
    {
104
        return $this->getRedirectUri() . '/' . $this->getName() . '/';
105
    }
106
107
    /**
108
     * @return string
109
     */
110
    abstract public function getBaseUri();
111
112
    /**
113
     * Return Provider's name
114
     *
115
     * @return string
116
     */
117
    abstract public function getName();
118
119
    /**
120
     * @param array $requestParameters
121
     * @return \SocialConnect\Provider\AccessTokenInterface
122
     */
123
    abstract public function getAccessTokenByRequestParameters(array $requestParameters);
124
125
    /**
126
     * @return string
127
     */
128
    abstract public function makeAuthUrl();
129
130
    /**
131
     * Get current user identity from social network by $accessToken
132
     *
133
     * @param AccessTokenInterface $accessToken
134
     * @return \SocialConnect\Common\Entity\User
135
     *
136
     * @throws \SocialConnect\Provider\Exception\InvalidResponse
137
     */
138
    abstract public function getIdentity(AccessTokenInterface $accessToken);
139
140
    /**
141
     * @return array
142
     */
143
    public function getScope()
144
    {
145
        return $this->scope;
146
    }
147
148
    /**
149
     * @param array $scope
150
     */
151
    public function setScope(array $scope)
152
    {
153
        $this->scope = $scope;
154
    }
155
156
    /**
157
     * @return string
158
     */
159
    public function getScopeInline()
160 6
    {
161
        return implode(',', $this->scope);
162 6
    }
163
164
    /**
165
     * @return array
166
     */
167
    public function getFields()
168 1
    {
169
        return $this->fields;
170 1
    }
171
172
    /**
173
     * @param array $fields
174
     */
175
    public function setFields(array $fields)
176
    {
177
        $this->fields = $fields;
178
    }
179
180
    /**
181
     * @return string
182
     */
183
    public function getFieldsInline()
184
    {
185
        return implode(',', $this->fields);
186
    }
187
188
    /**
189
     * @return \SocialConnect\Provider\Consumer
190
     */
191
    public function getConsumer()
192
    {
193
        return $this->consumer;
194
    }
195
}
196