Completed
Push — master ( a054a0...cffdc3 )
by Johnny
02:13
created

Client   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 407
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 8

Test Coverage

Coverage 0%

Importance

Changes 7
Bugs 1 Features 3
Metric Value
wmc 20
c 7
b 1
f 3
lcom 2
cbo 8
dl 0
loc 407
ccs 0
cts 248
cp 0
rs 10

19 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 173 1
A registerResource() 0 3 1
A getSupportedFunctions() 0 3 1
A setClientId() 0 5 1
A setRedirectUri() 0 5 1
A setClientSecret() 0 5 1
A setApiUrl() 0 5 1
A setForceRelogin() 0 5 1
A setAccessToken() 0 4 1
A getClientId() 0 4 1
A getRedirectUri() 0 4 1
A getClientSecret() 0 4 1
A getApiUrl() 0 4 1
A isForceRelogin() 0 4 1
A getAccessToken() 0 4 1
A getAuthModel() 0 3 1
A sendCommand() 0 4 1
A getTransport() 0 8 2
A setTransport() 0 5 1
1
<?php
2
namespace Redbox\Twitch;
3
use Redbox\Twitch\Transport\TransportInterface;
4
use Redbox\Twitch\Transport\HttpRequest;
5
use Redbox\Twitch\Transport\Http;
6
use Redbox\Twitch\Commands;
7
use Redbox\Twitch\Auth\AuthModel;
8
9
class Client
10
{
11
12
    /**
13
     * @var TransportInterface
14
     */
15
    protected $transport;
16
17
    /**
18
     * @var string
19
     */
20
    protected $client_id;
21
22
    /**
23
     * @var string
24
     */
25
    protected $redirect_uri;
26
27
    /**
28
     * @var string
29
     */
30
    protected $client_secret;
31
32
    /**
33
     * @var bool
34
     */
35
    protected $force_relogin;
36
37
    /**
38
     * @var string
39
     */
40
    protected $access_token;
41
42
    /*
43
     * @var string
44
     */
45
    protected $api_url;
46
47
    // --- NEW --
48
49
    /**
50
     * @var array
51
     */
52
    protected $resources = [];
53
54
    /**
55
     * @var Resource\Auth
56
     */
57
    public $auth;
58
59
    /**
60
     * @var Resource\Game
61
     */
62
    public $games;
63
64
    /**
65
     * @var Resource\Root
66
     */
67
    public $root;
68
69
    /**
70
     * @var Resource\Teams
71
     */
72
    public $teams;
73
74
    /**
75
     * @var Resource\Videos
76
     */
77
    public $videos;
78
79
    /**
80
     * @var Resource\Ingests
81
     */
82
    public $ingests;
83
84
    public function __construct()
85
    {
86
        $this->setApiUrl('https://api.twitch.tv/kraken');
87
88
89
        $this->auth = new Resource\Auth(
90
            $this,
91
            "Auth",
92
            array(
93
                'methods' => array(
94
                    'requestAccessToken' => array(
95
                        'path'        => 'oauth2/token',
96
                        'httpMethod'  => HttpRequest::REQUEST_METHOD_POST,
97
                        'requiresAuth'=> false,
98
                    )
99
                )
100
            )
101
        );
102
        $this->games = new Resource\Games(
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Redbox\Twitch\Resou...ype' => 'integer')))))) of type object<Redbox\Twitch\Resource\Games> is incompatible with the declared type object<Redbox\Twitch\Resource\Game> of property $games.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
103
            $this,
104
            "Games",
105
            array(
106
                'methods' => array(
107
                    'listTopGames' => array(
108
                        'path'        => 'games/top',
109
                        'httpMethod'  => HttpRequest::REQUEST_METHOD_GET,
110
                        'requiresAuth'=> false,
111
                        'parameters'  => array (
112
                            'limit'   => array (
113
                                'type'    => 'integer',
114
                                'min'     => 0,
115
                                'max'     => 100,
116
                            ),
117
                            'offset'  => array (
118
                                'type'    => 'integer',
119
                            )
120
                        )
121
                    )
122
                )
123
            )
124
        );
125
        $this->root = new Resource\Root(
126
            $this,
127
            "Root",
128
            array(
129
                'methods' => array(
130
                    'getRoot' => array(
131
                        'path'        => '/',
132
                        'httpMethod'  => HttpRequest::REQUEST_METHOD_GET,
133
                        'requiresAuth'=> false,
134
                        'parameters'  => array()
135
                    )
136
                )
137
            )
138
        );
139
        $this->ingests = new Resource\Ingests(
140
            $this,
141
            "Ingests",
142
            array(
143
                'methods' => array(
144
                    'get' => array(
145
                        'path'        => '/ingests',
146
                        'httpMethod'  => HttpRequest::REQUEST_METHOD_GET,
147
                        'requiresAuth'=> false,
148
                        'parameters'  => array()
149
                    )
150
                )
151
            )
152
        );
153
154
        $this->teams = new Resource\Teams(
155
            $this,
156
            "Teams",
157
            array(
158
                'methods' => array(
159
                    'listTeams' => array(
160
                        'path'        => '/teams',
161
                        'httpMethod'  => HttpRequest::REQUEST_METHOD_GET,
162
                        'requiresAuth'=> false,
163
                        'parameters'  => array (
164
                            'limit'   => array (
165
                                'type'    => 'integer',
166
                                'min'     => 0,
167
                                'max'     => 100,
168
                            ),
169
                            'offset'  => array (
170
                                'type'    => 'integer',
171
                            )
172
                        )
173
                    ),
174
                    'getTeamByName' => array(
175
                        'path'        => '/teams/:team/',
176
                        'httpMethod'  => HttpRequest::REQUEST_METHOD_GET,
177
                        'requiresAuth'=> false,
178
                        'parameters'  => array (
179
                            'team'   => array (
180
                                'type'      => 'string',
181
                                'url_part'  => true,
182
                            )
183
                        )
184
                    )
185
                )
186
            )
187
        );
188
        $this->videos = new Resource\Videos(
189
            $this,
190
            "Videos",
191
            array(
192
                'methods' => array(
193
                    'listTopVideos' => array(
194
                        'path'        => 'videos/top',
195
                        'httpMethod'  => HttpRequest::REQUEST_METHOD_GET,
196
                        'requiresAuth'=> false,
197
                        'parameters'  => array (
198
                            'limit'   => array (
199
                                'type'    => 'integer',
200
                                'min'     => 0,
201
                                'max'     => 100,
202
                            ),
203
                            'offset' => array (
204
                                'type' => 'integer',
205
                            ),
206
                            'game' => array (
207
                                'type' => 'string',
208
                            ),
209
                            'period' => array (
210
                                'type'             => 'string',
211
                                'restricted_value' => array(
212
                                    'week', 'month', 'all'
213
                                )
214
                            )
215
                        )
216
                    ),
217
                    'getVideo' => array(
218
                        'path'        => 'videos/:id/',
219
                        'httpMethod'  => HttpRequest::REQUEST_METHOD_GET,
220
                        'requiresAuth'=> false,
221
                        'parameters'  => array (
222
                            'id'   => array (
223
                                'type'      => 'string',
224
                                'url_part'  => true,
225
                            )
226
                        )
227
                    ),
228
                    'getChannelVideos' => array(
229
                        'path'        => 'channels/:channel/videos',
230
                        'httpMethod'  => HttpRequest::REQUEST_METHOD_GET,
231
                        'requiresAuth'=> false,
232
                        'parameters'  => array (
233
                            'limit'   => array (
234
                                'type'    => 'integer',
235
                                'min'     => 0,
236
                                'max'     => 100,
237
                            ),
238
                            'offset' => array (
239
                                'type' => 'integer',
240
                            ),
241
                            'broadcasts' => array (
242
                                'type' => 'bool',
243
                            ),
244
                            'hls' => array(
245
                                'type' => 'bool'
246
                            ),
247
                            'channel'   => array (
248
                                'type'      => 'string',
249
                                'url_part'  => true,
250
                            )
251
                        )
252
                    )
253
                )
254
            )
255
        );
256
    }
257
258
    public function registerResource($name="", Resource\ResourceAbstract $instance) {
259
        $this->resources[$name] = $instance;
260
    }
261
262
    public function getSupportedFunctions() {
263
        return $this->resources;
264
    }
265
266
    /* -- Setters */
267
268
    /**
269
     * @param string $client_id
270
     */
271
    public function setClientId($client_id)
272
    {
273
        $this->client_id = $client_id;
274
        return $this;
275
    }
276
277
    /**
278
     * @param string $redirect_uri
279
     */
280
    public function setRedirectUri($redirect_uri)
281
    {
282
        $this->redirect_uri = $redirect_uri;
283
        return $this;
284
    }
285
286
    /**
287
     * @param string $client_secret
288
     */
289
    public function setClientSecret($client_secret)
290
    {
291
        $this->client_secret = $client_secret;
292
        return $this;
293
    }
294
295
    /**
296
     * @param string $api_url
297
     */
298
    public function setApiUrl($api_url)
299
    {
300
        $this->api_url = $api_url;
301
        return $this;
302
    }
303
304
    /**
305
     * @param boolean $force_relogin
306
     */
307
    public function setForceRelogin($force_relogin)
308
    {
309
        $this->force_relogin = $force_relogin;
310
        return $this;
311
    }
312
313
    /**
314
     * @param string $access_token
315
     */
316
    public function setAccessToken($access_token)
317
    {
318
        $this->access_token = $access_token;
319
    }
320
321
322
    /* -- Getters  */
323
324
    /**
325
     * @return string
326
     */
327
    public function getClientId()
328
    {
329
        return $this->client_id;
330
    }
331
332
    /**
333
     * @return string
334
     */
335
    public function getRedirectUri()
336
    {
337
        return $this->redirect_uri;
338
    }
339
340
    /**
341
     * @return string
342
     */
343
    public function getClientSecret()
344
    {
345
        return $this->client_secret;
346
    }
347
348
    /**
349
     * @return string
350
     */
351
    public function getApiUrl()
352
    {
353
        return $this->api_url;
354
    }
355
356
    /**
357
     * @return boolean
358
     */
359
    public function isForceRelogin()
360
    {
361
        return $this->force_relogin;
362
    }
363
364
    /**
365
     * @return string
366
     */
367
    public function getAccessToken()
368
    {
369
        return $this->access_token;
370
    }
371
372
    public function getAuthModel() {
373
        return new AuthModel($this);
374
    }
375
376
    /**
377
     * Send command to server
378
     *
379
     * @param CommandInterface $command Phue command
380
     *
381
     * @return mixed Command result
382
     */
383
    public function sendCommand(Commands\CommandInterface $command)
384
    {
385
        return $command->send($this);
386
    }
387
388
    /**
389
     * Get transport
390
     *
391
     * @return TransportInterface Transport
392
     */
393
    public function getTransport()
394
    {
395
        // Set transport if haven't
396
        if ($this->transport === null) {
397
            $this->setTransport(new Http($this));
398
        }
399
        return $this->transport;
400
    }
401
402
    /**
403
     * Set transport
404
     *
405
     * @param TransportInterface $transport Transport
406
     *
407
     * @return self This object
408
     */
409
    public function setTransport(TransportInterface $transport)
410
    {
411
        $this->transport = $transport;
412
        return $this;
413
    }
414
415
}