@@ -9,7 +9,7 @@ |
||
9 | 9 | const UPDATED_AT = 'updated_at'; |
10 | 10 | const DELETED = 'delete'; |
11 | 11 | const NAME = 'name'; |
12 | - const COUNTRY_CODE = 'country_code'; |
|
12 | + const COUNTRY_CODE = 'country_code'; |
|
13 | 13 | const IPHONE_APP_ID = 'iphone_app_id'; |
14 | 14 | const IPHONE_DEEP_LINK = 'iphone_deep_link'; |
15 | 15 | const IPAD_APP_ID = 'ipad_app_id'; |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | * @param string $path |
276 | 276 | * @param array $parameters |
277 | 277 | * |
278 | - * @param array $headers |
|
278 | + * @param string[] $headers |
|
279 | 279 | * @return Response |
280 | 280 | * @throws BadRequest |
281 | 281 | * @throws Forbidden |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | * @param string $path |
319 | 319 | * @param array $parameters |
320 | 320 | * |
321 | - * @param array $headers |
|
321 | + * @param string[] $headers |
|
322 | 322 | * @return Response |
323 | 323 | * @throws BadRequest |
324 | 324 | * @throws Forbidden |
@@ -811,6 +811,10 @@ discard block |
||
811 | 811 | // This function takes a input like a=b&a=c&d=e and returns the parsed |
812 | 812 | // parameters like this |
813 | 813 | // array('a' => array('b','c'), 'd' => 'e') |
814 | + |
|
815 | + /** |
|
816 | + * @param string $input |
|
817 | + */ |
|
814 | 818 | public static function parse_parameters($input) |
815 | 819 | { |
816 | 820 | if (!isset($input) || !$input) { |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | $this->response->setApiPath($path); |
236 | 236 | $url = sprintf('%s/%s', self::API_HOST_OAUTH, $path); |
237 | 237 | $request = Request::fromConsumerAndToken($this->consumer, $this->token, $method, $url, $parameters); |
238 | - $authorization = 'Authorization: Basic ' . $this->encodeAppAuthorization($this->consumer); |
|
238 | + $authorization = 'Authorization: Basic '.$this->encodeAppAuthorization($this->consumer); |
|
239 | 239 | $result = $this->request($request->getNormalizedHttpUrl(), $method, $authorization, $parameters); |
240 | 240 | $response = JsonDecoder::decode($result, $this->decodeJsonAsArray); |
241 | 241 | $this->response->setBody($response); |
@@ -525,9 +525,9 @@ discard block |
||
525 | 525 | public function manageErrors($response) |
526 | 526 | { |
527 | 527 | $errors = []; |
528 | - if(isset($response->errors)){ |
|
528 | + if (isset($response->errors)) { |
|
529 | 529 | $errors = $response->errors; |
530 | - } else if(isset($response->operation_errors)){ |
|
530 | + } else if (isset($response->operation_errors)) { |
|
531 | 531 | $errors = $response->operation_errors; |
532 | 532 | } |
533 | 533 | |
@@ -573,7 +573,7 @@ discard block |
||
573 | 573 | $request->signRequest($this->signatureMethod, $this->consumer, $this->token); |
574 | 574 | $authorization = $request->toHeader(); |
575 | 575 | } else { |
576 | - $authorization = 'Authorization: Bearer ' . $this->bearer; |
|
576 | + $authorization = 'Authorization: Bearer '.$this->bearer; |
|
577 | 577 | } |
578 | 578 | if (strpos($url, TONUpload::DEFAULT_DOMAIN) === 0) { |
579 | 579 | return $this->request($url, $method, $authorization, $parameters, $headers); |
@@ -599,7 +599,7 @@ discard block |
||
599 | 599 | /* Curl settings */ |
600 | 600 | $options = [ |
601 | 601 | CURLOPT_VERBOSE => false, |
602 | - CURLOPT_CAINFO => __DIR__ . DIRECTORY_SEPARATOR . 'cacert.pem', |
|
602 | + CURLOPT_CAINFO => __DIR__.DIRECTORY_SEPARATOR.'cacert.pem', |
|
603 | 603 | CURLOPT_CONNECTTIMEOUT => $this->connectionTimeout, |
604 | 604 | CURLOPT_HEADER => true, |
605 | 605 | CURLOPT_HTTPHEADER => array_merge(['Accept: */*', $authorization, 'Expect:'], $headers, ['Connection: close']), |
@@ -629,7 +629,7 @@ discard block |
||
629 | 629 | $options[CURLOPT_POSTFIELDS] = $postfields['raw']; |
630 | 630 | $options[CURLOPT_HTTPHEADER] = array_merge($options[CURLOPT_HTTPHEADER], [ |
631 | 631 | 'Content-Type: application/json', |
632 | - 'Content-Length: '. strlen($postfields['raw']) |
|
632 | + 'Content-Length: '.strlen($postfields['raw']) |
|
633 | 633 | ]); |
634 | 634 | } else { |
635 | 635 | $options[CURLOPT_POSTFIELDS] = Util::buildHttpQuery($postfields); |
@@ -648,7 +648,7 @@ discard block |
||
648 | 648 | } |
649 | 649 | |
650 | 650 | if (in_array($method, ['GET', 'PUT', 'DELETE']) && !empty($postfields) && !isset($postfields['raw'])) { |
651 | - $options[CURLOPT_URL] .= '?' . Util::buildHttpQuery($postfields); |
|
651 | + $options[CURLOPT_URL] .= '?'.Util::buildHttpQuery($postfields); |
|
652 | 652 | } |
653 | 653 | |
654 | 654 | $curlHandle = curl_init(); |
@@ -724,7 +724,7 @@ discard block |
||
724 | 724 | $key = $consumer->key; |
725 | 725 | $secret = $consumer->secret; |
726 | 726 | |
727 | - return base64_encode($key . ':' . $secret); |
|
727 | + return base64_encode($key.':'.$secret); |
|
728 | 728 | } |
729 | 729 | |
730 | 730 | /** |
@@ -758,7 +758,7 @@ discard block |
||
758 | 758 | */ |
759 | 759 | public function getAccountId() |
760 | 760 | { |
761 | - if(!$this->account instanceof Account){ |
|
761 | + if (!$this->account instanceof Account) { |
|
762 | 762 | return ''; |
763 | 763 | } |
764 | 764 | return $this->account->getId(); |
@@ -769,7 +769,7 @@ discard block |
||
769 | 769 | */ |
770 | 770 | public function getAccountTimezone() |
771 | 771 | { |
772 | - if(!$this->account instanceof Account){ |
|
772 | + if (!$this->account instanceof Account) { |
|
773 | 773 | return 'UTC'; |
774 | 774 | } |
775 | 775 | return $this->account->getTimezone(); |
@@ -884,9 +884,9 @@ discard block |
||
884 | 884 | $token = $token['oauth_token']; |
885 | 885 | } |
886 | 886 | if (empty($sign_in_with_twitter)) { |
887 | - return $this->authorizeURL() . "?oauth_token={$token}"; |
|
887 | + return $this->authorizeURL()."?oauth_token={$token}"; |
|
888 | 888 | } |
889 | 889 | |
890 | - return $this->authenticateURL() . "?oauth_token={$token}"; |
|
890 | + return $this->authenticateURL()."?oauth_token={$token}"; |
|
891 | 891 | } |
892 | 892 | } |
@@ -36,23 +36,23 @@ discard block |
||
36 | 36 | $j = 1; |
37 | 37 | $l = 1; |
38 | 38 | foreach ($campaignsData as $campaign) { |
39 | - echo $i . ': ' . $campaign->getId() . ' ' . $campaign->getName() . ' ' . $campaign->getStartTime()->format('Y-m-d') . ' - ' . $campaign->getEntityStatus() . PHP_EOL; |
|
39 | + echo $i.': '.$campaign->getId().' '.$campaign->getName().' '.$campaign->getStartTime()->format('Y-m-d').' - '.$campaign->getEntityStatus().PHP_EOL; |
|
40 | 40 | $lineItems = $campaign->getLineItems([TwitterAds\Fields\LineItemFields::COUNT => 2]); |
41 | 41 | /** @var LineItem $lineItem */ |
42 | 42 | foreach ($lineItems as $lineItem) { |
43 | - echo "\t" . $j . ': ' . $lineItem->getId() . ' ' . $lineItem->getName() . ' ' . PHP_EOL; |
|
44 | - echo "\t\tBid: " . ($lineItem->getBidAmountLocalMicro() / 1000000) . PHP_EOL; |
|
45 | - echo "\t\tObjective: " . $lineItem->getObjective() . PHP_EOL; |
|
46 | - echo "\t\tCharge By: " . $lineItem->getChargeBy() . PHP_EOL; |
|
47 | - echo "\t\tBid Unit: " . $lineItem->getBidUnit() . PHP_EOL; |
|
48 | - echo "\t\tOptimization: " . $lineItem->getOptimization() . PHP_EOL; |
|
49 | - echo "\t\tBid Type: " . $lineItem->getBidType() . PHP_EOL; |
|
43 | + echo "\t".$j.': '.$lineItem->getId().' '.$lineItem->getName().' '.PHP_EOL; |
|
44 | + echo "\t\tBid: ".($lineItem->getBidAmountLocalMicro() / 1000000).PHP_EOL; |
|
45 | + echo "\t\tObjective: ".$lineItem->getObjective().PHP_EOL; |
|
46 | + echo "\t\tCharge By: ".$lineItem->getChargeBy().PHP_EOL; |
|
47 | + echo "\t\tBid Unit: ".$lineItem->getBidUnit().PHP_EOL; |
|
48 | + echo "\t\tOptimization: ".$lineItem->getOptimization().PHP_EOL; |
|
49 | + echo "\t\tBid Type: ".$lineItem->getBidType().PHP_EOL; |
|
50 | 50 | $targetingCriterias = $lineItem->getTargetingCriteria(); |
51 | 51 | /** @var TwitterAds\Campaign\TargetingCriteria $targetingCriteria */ |
52 | 52 | foreach ($targetingCriterias as $targetingCriteria) { |
53 | - echo "\t\t" . $l . ': ' . $targetingCriteria->getId() . ' ' . $targetingCriteria->getName() . ' ' . |
|
53 | + echo "\t\t".$l.': '.$targetingCriteria->getId().' '.$targetingCriteria->getName().' '. |
|
54 | 54 | |
55 | - $targetingCriteria->getTargetingType() . ' ' . $targetingCriteria->getTargetingValue() . PHP_EOL; |
|
55 | + $targetingCriteria->getTargetingType().' '.$targetingCriteria->getTargetingValue().PHP_EOL; |
|
56 | 56 | |
57 | 57 | $l++; |
58 | 58 | } |
@@ -78,14 +78,14 @@ discard block |
||
78 | 78 | ); |
79 | 79 | $stats = $stats[0]->id_data[0]->metrics; |
80 | 80 | if (!is_null($stats->billed_charge_local_micro)) { |
81 | - echo "\t\t\t Start: " . $date[0]->format('Y-m-d H:i:s') . PHP_EOL; |
|
82 | - echo "\t\t\t End: " . $date[1]->format('Y-m-d H:i:s') . PHP_EOL; |
|
83 | - echo "\t\t\t " . ($stats->billed_charge_local_micro[0] / 1000000) . '€' . PHP_EOL; |
|
81 | + echo "\t\t\t Start: ".$date[0]->format('Y-m-d H:i:s').PHP_EOL; |
|
82 | + echo "\t\t\t End: ".$date[1]->format('Y-m-d H:i:s').PHP_EOL; |
|
83 | + echo "\t\t\t ".($stats->billed_charge_local_micro[0] / 1000000).'€'.PHP_EOL; |
|
84 | 84 | echo "\t\t\t\t App clicks: "; |
85 | 85 | getStats($stats->app_clicks); |
86 | - echo "\t\t\t\t Installs:" . PHP_EOL; |
|
86 | + echo "\t\t\t\t Installs:".PHP_EOL; |
|
87 | 87 | getStats($stats->mobile_conversion_installs); |
88 | - echo "\t\t\t\t Checkouts:" . PHP_EOL; |
|
88 | + echo "\t\t\t\t Checkouts:".PHP_EOL; |
|
89 | 89 | getStats($stats->mobile_conversion_checkouts_initiated); |
90 | 90 | } |
91 | 91 | } |
@@ -105,14 +105,14 @@ discard block |
||
105 | 105 | if ($stat instanceof stdClass) { |
106 | 106 | foreach (get_object_vars($stat) as $key => $val) { |
107 | 107 | if (is_array($val)) { |
108 | - echo "\t\t\t\t\t " . $key . ': ' . $val[0] . PHP_EOL; |
|
108 | + echo "\t\t\t\t\t ".$key.': '.$val[0].PHP_EOL; |
|
109 | 109 | } else { |
110 | - echo "\t\t\t\t\t " . $key . ' 0' . PHP_EOL; |
|
110 | + echo "\t\t\t\t\t ".$key.' 0'.PHP_EOL; |
|
111 | 111 | } |
112 | 112 | } |
113 | 113 | } else if (is_array($stat)) { |
114 | 114 | foreach ($stat as $s) { |
115 | - echo $s . PHP_EOL; |
|
115 | + echo $s.PHP_EOL; |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 |
@@ -36,23 +36,23 @@ discard block |
||
36 | 36 | $j = 1; |
37 | 37 | $l = 1; |
38 | 38 | foreach ($campaignsData as $campaign) { |
39 | - echo $i . ': ' . $campaign->getId() . ' ' . $campaign->getName() . ' ' . $campaign->getStartTime()->format('Y-m-d') . ' - ' . $campaign->getEntityStatus() . PHP_EOL; |
|
39 | + echo $i.': '.$campaign->getId().' '.$campaign->getName().' '.$campaign->getStartTime()->format('Y-m-d').' - '.$campaign->getEntityStatus().PHP_EOL; |
|
40 | 40 | $lineItems = $campaign->getLineItems([TwitterAds\Fields\LineItemFields::COUNT => 2]); |
41 | 41 | /** @var LineItem $lineItem */ |
42 | 42 | foreach ($lineItems as $lineItem) { |
43 | - echo "\t" . $j . ': ' . $lineItem->getId() . ' ' . $lineItem->getName() . ' ' . PHP_EOL; |
|
44 | - echo "\t\tBid: " . ($lineItem->getBidAmountLocalMicro() / 1000000) . PHP_EOL; |
|
45 | - echo "\t\tObjective: " . $lineItem->getObjective() . PHP_EOL; |
|
46 | - echo "\t\tCharge By: " . $lineItem->getChargeBy() . PHP_EOL; |
|
47 | - echo "\t\tBid Unit: " . $lineItem->getBidUnit() . PHP_EOL; |
|
48 | - echo "\t\tOptimization: " . $lineItem->getOptimization() . PHP_EOL; |
|
49 | - echo "\t\tBid Type: " . $lineItem->getBidType() . PHP_EOL; |
|
43 | + echo "\t".$j.': '.$lineItem->getId().' '.$lineItem->getName().' '.PHP_EOL; |
|
44 | + echo "\t\tBid: ".($lineItem->getBidAmountLocalMicro() / 1000000).PHP_EOL; |
|
45 | + echo "\t\tObjective: ".$lineItem->getObjective().PHP_EOL; |
|
46 | + echo "\t\tCharge By: ".$lineItem->getChargeBy().PHP_EOL; |
|
47 | + echo "\t\tBid Unit: ".$lineItem->getBidUnit().PHP_EOL; |
|
48 | + echo "\t\tOptimization: ".$lineItem->getOptimization().PHP_EOL; |
|
49 | + echo "\t\tBid Type: ".$lineItem->getBidType().PHP_EOL; |
|
50 | 50 | $targetingCriterias = $lineItem->getTargetingCriteria(); |
51 | 51 | /** @var TwitterAds\Campaign\TargetingCriteria $targetingCriteria */ |
52 | 52 | foreach ($targetingCriterias as $targetingCriteria) { |
53 | - echo "\t\t" . $l . ': ' . $targetingCriteria->getId() . ' ' . $targetingCriteria->getName() . ' ' . |
|
53 | + echo "\t\t".$l.': '.$targetingCriteria->getId().' '.$targetingCriteria->getName().' '. |
|
54 | 54 | |
55 | - $targetingCriteria->getTargetingType() . ' ' . $targetingCriteria->getTargetingValue() . PHP_EOL; |
|
55 | + $targetingCriteria->getTargetingType().' '.$targetingCriteria->getTargetingValue().PHP_EOL; |
|
56 | 56 | |
57 | 57 | $l++; |
58 | 58 | } |
@@ -76,26 +76,26 @@ discard block |
||
76 | 76 | AnalyticsFields::PLACEMENT => Enumerations::PLACEMENT_ALL_ON_TWITTER |
77 | 77 | ], $async |
78 | 78 | ); |
79 | - while($job->getStatus() == TwitterAds\Fields\JobFields::PROCESSING){ |
|
80 | - echo 'Job is still processing. Waiting 5 more seconds' .PHP_EOL; |
|
79 | + while ($job->getStatus() == TwitterAds\Fields\JobFields::PROCESSING) { |
|
80 | + echo 'Job is still processing. Waiting 5 more seconds'.PHP_EOL; |
|
81 | 81 | $job->read(); |
82 | 82 | sleep(5); |
83 | 83 | } |
84 | 84 | |
85 | - if($job->getStatus() == TwitterAds\Fields\JobFields::SUCCESS){ |
|
85 | + if ($job->getStatus() == TwitterAds\Fields\JobFields::SUCCESS) { |
|
86 | 86 | $result = gzfile($job->getUrl()); |
87 | 87 | $result = implode('', $result); |
88 | 88 | $stats = json_decode($result)->data; |
89 | 89 | $stats = $stats[0]->id_data[0]->metrics; |
90 | 90 | if (!is_null($stats->billed_charge_local_micro)) { |
91 | - echo "\t\t\t Start: " . $date[0]->format('Y-m-d H:i:s') . PHP_EOL; |
|
92 | - echo "\t\t\t End: " . $date[1]->format('Y-m-d H:i:s') . PHP_EOL; |
|
93 | - echo "\t\t\t " . ($stats->billed_charge_local_micro[0] / 1000000) . '€' . PHP_EOL; |
|
91 | + echo "\t\t\t Start: ".$date[0]->format('Y-m-d H:i:s').PHP_EOL; |
|
92 | + echo "\t\t\t End: ".$date[1]->format('Y-m-d H:i:s').PHP_EOL; |
|
93 | + echo "\t\t\t ".($stats->billed_charge_local_micro[0] / 1000000).'€'.PHP_EOL; |
|
94 | 94 | echo "\t\t\t\t App clicks: "; |
95 | 95 | getStats($stats->app_clicks); |
96 | - echo "\t\t\t\t Installs:" . PHP_EOL; |
|
96 | + echo "\t\t\t\t Installs:".PHP_EOL; |
|
97 | 97 | getStats($stats->mobile_conversion_installs); |
98 | - echo "\t\t\t\t Checkouts:" . PHP_EOL; |
|
98 | + echo "\t\t\t\t Checkouts:".PHP_EOL; |
|
99 | 99 | getStats($stats->mobile_conversion_checkouts_initiated); |
100 | 100 | } |
101 | 101 | } |
@@ -116,14 +116,14 @@ discard block |
||
116 | 116 | if ($stat instanceof stdClass) { |
117 | 117 | foreach (get_object_vars($stat) as $key => $val) { |
118 | 118 | if (is_array($val)) { |
119 | - echo "\t\t\t\t\t " . $key . ': ' . $val[0] . PHP_EOL; |
|
119 | + echo "\t\t\t\t\t ".$key.': '.$val[0].PHP_EOL; |
|
120 | 120 | } else { |
121 | - echo "\t\t\t\t\t " . $key . ' 0' . PHP_EOL; |
|
121 | + echo "\t\t\t\t\t ".$key.' 0'.PHP_EOL; |
|
122 | 122 | } |
123 | 123 | } |
124 | 124 | } else if (is_array($stat)) { |
125 | 125 | foreach ($stat as $s) { |
126 | - echo $s . PHP_EOL; |
|
126 | + echo $s.PHP_EOL; |
|
127 | 127 | } |
128 | 128 | } |
129 | 129 |
@@ -129,7 +129,7 @@ |
||
129 | 129 | */ |
130 | 130 | public function getAudienceSize() |
131 | 131 | { |
132 | - return (int)$this->audience_size; |
|
132 | + return (int) $this->audience_size; |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -59,7 +59,7 @@ |
||
59 | 59 | { |
60 | 60 | $endTime = isset($params[AnalyticsFields::END_TIME]) ? $params[AnalyticsFields::END_TIME] : new DateTime('now'); |
61 | 61 | $endTime->setTime($endTime->format('H'), 0, 0); |
62 | - $startTime = isset($params[AnalyticsFields::START_TIME]) ? $params[AnalyticsFields::START_TIME] : new DateTime($endTime->format('c') . ' - 7 days'); |
|
62 | + $startTime = isset($params[AnalyticsFields::START_TIME]) ? $params[AnalyticsFields::START_TIME] : new DateTime($endTime->format('c').' - 7 days'); |
|
63 | 63 | $startTime->setTime($startTime->format('H'), 0, 0); |
64 | 64 | $granularity = isset($params[AnalyticsFields::GRANULARITY]) ? $params[AnalyticsFields::GRANULARITY] : Enumerations::GRANULARITY_TOTAL; |
65 | 65 | $placement = isset($params[AnalyticsFields::PLACEMENT]) ? $params[AnalyticsFields::PLACEMENT] : Enumerations::PLACEMENT_ALL_ON_TWITTER; |
@@ -37,7 +37,7 @@ |
||
37 | 37 | $instance = $instance ?: TwitterAds::instance(); |
38 | 38 | if (!$instance) { |
39 | 39 | throw new InvalidArgumentException( |
40 | - 'An Api instance must be provided as argument or ' . |
|
40 | + 'An Api instance must be provided as argument or '. |
|
41 | 41 | 'set as instance in the \TwitterAds\Api' |
42 | 42 | ); |
43 | 43 | } |