TwitterClient::factory()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 25
rs 8.8571
cc 1
eloc 17
nc 1
nop 4
1
<?php namespace Tuiter;
2
3
use GuzzleHttp\Client;
4
use GuzzleHttp\Subscriber\Oauth\Oauth1;
5
6
/**
7
 * Class TwitterClient
8
 * @package Tuiter
9
 */
10
class TwitterClient extends Client
11
{
12
    /**
13
     * @param $consumerKey
14
     * @param $consumerSecret
15
     * @param $token
16
     * @param $tokenSecret
17
     *
18
     * @return self
19
     */
20
    public static function factory(
21
        $consumerKey,
22
        $consumerSecret,
23
        $token,
24
        $tokenSecret
25
    ) {
26
        $client = new self([
27
            'base_url' => [
28
                'https://api.twitter.com/{version}/',
29
                ['version' => 'v1.1']
30
            ],
31
            'defaults' => ['auth' => 'oauth']
32
        ]);
33
34
        $oauth = new Oauth1([
35
            'consumer_key' => $consumerKey,
36
            'consumer_secret' => $consumerSecret,
37
            'token' => $token,
38
            'token_secret' => $tokenSecret
39
        ]);
40
41
        $client->getEmitter()->attach($oauth);
42
43
        return $client;
44
    }
45
}
46