TweetDestroyer   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 64
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A withParams() 0 10 1
A destroy() 0 12 2
A extractTweetId() 0 4 2
1
<?php namespace Tuiter;
2
3
use GuzzleHttp\Exception\RequestException;
4
5
/**
6
 * Class TweetDestroyer
7
 * @package Tuiter
8
 */
9
final class TweetDestroyer
10
{
11
    /**
12
     * @var TwitterClient
13
     */
14
    private $client;
15
16
    /**
17
     * @param TwitterClient $client
18
     */
19
    public function __construct(TwitterClient $client)
20
    {
21
        $this->client = $client;
22
    }
23
24
    /**
25
     * Factory
26
     *
27
     * @param $consumerKey
28
     * @param $consumerSecret
29
     * @param $token
30
     * @param $tokenSecret
31
     *
32
     * @return self
33
     */
34
    public static function withParams(
35
        $consumerKey,
36
        $consumerSecret,
37
        $token,
38
        $tokenSecret
39
    ) {
40
        return new self(TwitterClient::factory(
41
            $consumerKey, $consumerSecret, $token, $tokenSecret
42
        ));
43
    }
44
45
    /**
46
     * @param $tweetId
47
     *
48
     * @return mixed
49
     */
50
    public function destroy($tweetId)
51
    {
52
        $tweetId = $this->extractTweetId($tweetId);
53
54
        try {
55
            $response = $this->client->post("statuses/destroy/{$tweetId}.json");
56
        } catch (RequestException $e) {
57
            $response = $e->getResponse();
58
        }
59
60
        return $response->json();
61
    }
62
63
    /**
64
     * @param $tweetId
65
     *
66
     * @return string
67
     */
68
    private function extractTweetId($tweetId)
69
    {
70
        return $tweetId instanceof Tweet ? $tweetId->id : $tweetId;
71
    }
72
}
73