Completed
Push — master ( b579d6...72e21a )
by Hector
11:54
created

PromotedTweet::getPaused()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: hborras
5
 * Date: 17/04/16
6
 * Time: 22:41.
7
 */
8
namespace Hborras\TwitterAdsSDK\TwitterAds\Creative;
9
10
use Hborras\TwitterAdsSDK\TwitterAds\Analytics;
11
use Hborras\TwitterAdsSDK\TwitterAds\Fields\AnalyticsFields;
12
use Hborras\TwitterAdsSDK\TwitterAds\Fields\PromotedTweetFields;
13
14 View Code Duplication
class PromotedTweet extends Analytics
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
{
16
    const RESOURCE_COLLECTION = 'accounts/{account_id}/promoted_tweets';
17
    const RESOURCE            = 'accounts/{account_id}/promoted_tweets/{id}';
18
    const RESOURCE_STATS      = 'stats/accounts/{account_id}/promoted_tweets/{id}';
19
20
    const ENTITY = 'PROMOTED_TWEET';
21
22
    /** Read Only */
23
    protected $id;
24
    protected $approval_status;
25
    protected $created_at;
26
    protected $updated_at;
27
    protected $deleted;
28
29
    protected $properties = [
30
        PromotedTweetFields::TWEET_ID,
31
        PromotedTweetFields::ENTITY_STATUS,
32
    ];
33
34
    /** Writable */
35
    protected $tweet_id;
36
    protected $entity_status;
37
38
    /**
39
     * @param $metricGroups
40
     * @param array $params
41
     * @param bool $async
42
     * @return mixed
43
     */
44
    public function stats($metricGroups, $params = [], $async = false)
45
    {
46
        $params[AnalyticsFields::ENTITY] = AnalyticsFields::PROMOTED_TWEET;
47
        return parent::stats($metricGroups, $params, $async);
48
    }
49
50
    /**
51
     * Saves or updates the current object instance depending on the
52
     * presence of `object->getId()`.
53
     */
54
    public function save()
55
    {
56
        $params = $this->toParams();
57
        if (isset($params[PromotedTweetFields::TWEET_ID])) {
58
            $params[PromotedTweetFields::TWEET_IDS] = $params[PromotedTweetFields::TWEET_ID];
59
            unset($params[PromotedTweetFields::TWEET_ID]);
60
        }
61
62
        if ($this->getId()) {
63
            $resource = str_replace(static::RESOURCE_REPLACE, $this->getTwitterAds()->getAccountId(), static::RESOURCE);
64
            $resource = str_replace(static::RESOURCE_ID_REPLACE, $this->getId(), $resource);
65
            $response = $this->getTwitterAds()->put($resource, $params);
66
67
            return $this->fromResponse($response->getBody()->data);
68
        } else {
69
            $resource = str_replace(static::RESOURCE_REPLACE, $this->getTwitterAds()->getAccountId(), static::RESOURCE_COLLECTION);
70
            $response = $this->getTwitterAds()->post($resource, $params);
71
72
            return $this->fromResponse($response->getBody()->data[0]);
73
        }
74
    }
75
76
    /**
77
     * @return mixed
78
     */
79
    public function getId()
80
    {
81
        return $this->id;
82
    }
83
84
    /**
85
     * @return mixed
86
     */
87
    public function getApprovalStatus()
88
    {
89
        return $this->approval_status;
90
    }
91
92
    /**
93
     * @return mixed
94
     */
95
    public function getCreatedAt()
96
    {
97
        return $this->created_at;
98
    }
99
100
    /**
101
     * @return mixed
102
     */
103
    public function getUpdatedAt()
104
    {
105
        return $this->updated_at;
106
    }
107
108
    /**
109
     * @return mixed
110
     */
111
    public function getDeleted()
112
    {
113
        return $this->deleted;
114
    }
115
116
    /**
117
     * @return array
118
     */
119
    public function getProperties()
120
    {
121
        return $this->properties;
122
    }
123
124
    /**
125
     * @return mixed
126
     */
127
    public function getTweetId()
128
    {
129
        return $this->tweet_id;
130
    }
131
132
    /**
133
     * @param array $properties
134
     */
135
    public function setProperties($properties)
136
    {
137
        $this->properties = $properties;
138
    }
139
140
    /**
141
     * @param mixed $tweet_id
142
     */
143
    public function setTweetId($tweet_id)
144
    {
145
        $this->tweet_id = $tweet_id;
146
    }
147
148
    /**
149
     * @return mixed
150
     */
151
    public function getEntityStatus()
152
    {
153
        return $this->entity_status;
154
    }
155
156
    /**
157
     * @param mixed $entity_status
158
     */
159
    public function setEntityStatus($entity_status)
160
    {
161
        $this->entity_status = $entity_status;
162
    }
163
}
164