@@ -26,8 +26,7 @@ discard block |
||
26 | 26 | |
27 | 27 | use FacebookAds\Http\Client; |
28 | 28 | |
29 | -abstract class AbstractAdapter implements AdapterInterface |
|
30 | -{ |
|
29 | +abstract class AbstractAdapter implements AdapterInterface { |
|
31 | 30 | /** |
32 | 31 | * @var Client |
33 | 32 | */ |
@@ -36,24 +35,21 @@ discard block |
||
36 | 35 | /** |
37 | 36 | * @param Client $client |
38 | 37 | */ |
39 | - public function __construct(Client $client) |
|
40 | - { |
|
38 | + public function __construct(Client $client) { |
|
41 | 39 | $this->client = $client; |
42 | 40 | } |
43 | 41 | |
44 | 42 | /** |
45 | 43 | * @return Client |
46 | 44 | */ |
47 | - public function getClient() |
|
48 | - { |
|
45 | + public function getClient() { |
|
49 | 46 | return $this->client; |
50 | 47 | } |
51 | 48 | |
52 | 49 | /** |
53 | 50 | * @return string |
54 | 51 | */ |
55 | - public function getCaBundlePath() |
|
56 | - { |
|
52 | + public function getCaBundlePath() { |
|
57 | 53 | return $this->getClient()->getCaBundlePath(); |
58 | 54 | } |
59 | 55 | } |
@@ -33,8 +33,7 @@ discard block |
||
33 | 33 | use FacebookAds\Http\RequestInterface; |
34 | 34 | use FacebookAds\Http\ResponseInterface; |
35 | 35 | |
36 | -class CurlAdapter extends AbstractAdapter |
|
37 | -{ |
|
36 | +class CurlAdapter extends AbstractAdapter { |
|
38 | 37 | /** |
39 | 38 | * @var CurlInterface |
40 | 39 | */ |
@@ -49,8 +48,7 @@ discard block |
||
49 | 48 | * @param Client $client |
50 | 49 | * @param CurlInterface $curl |
51 | 50 | */ |
52 | - public function __construct(Client $client, CurlInterface $curl = null) |
|
53 | - { |
|
51 | + public function __construct(Client $client, CurlInterface $curl = null) { |
|
54 | 52 | parent::__construct($client); |
55 | 53 | $this->curl = $curl ?: AbstractCurl::createOptimalVersion(); |
56 | 54 | $this->curl->init(); |
@@ -59,16 +57,14 @@ discard block |
||
59 | 57 | /** |
60 | 58 | * @return Curl |
61 | 59 | */ |
62 | - public function getCurl() |
|
63 | - { |
|
60 | + public function getCurl() { |
|
64 | 61 | return $this->curl; |
65 | 62 | } |
66 | 63 | |
67 | 64 | /** |
68 | 65 | * @return \ArrayObject |
69 | 66 | */ |
70 | - public function getOpts() |
|
71 | - { |
|
67 | + public function getOpts() { |
|
72 | 68 | if ($this->opts === null) { |
73 | 69 | $this->opts = new \ArrayObject(array( |
74 | 70 | CURLOPT_CONNECTTIMEOUT => 10, |
@@ -85,16 +81,14 @@ discard block |
||
85 | 81 | /** |
86 | 82 | * @param \ArrayObject $opts |
87 | 83 | */ |
88 | - public function setOpts(\ArrayObject $opts) |
|
89 | - { |
|
84 | + public function setOpts(\ArrayObject $opts) { |
|
90 | 85 | $this->opts = $opts; |
91 | 86 | } |
92 | 87 | |
93 | 88 | /** |
94 | 89 | * @return int |
95 | 90 | */ |
96 | - protected function getheaderSize() |
|
97 | - { |
|
91 | + protected function getheaderSize() { |
|
98 | 92 | return $this->getCurl()->getInfo(CURLINFO_HEADER_SIZE); |
99 | 93 | } |
100 | 94 | |
@@ -103,8 +97,7 @@ discard block |
||
103 | 97 | * @param string $raw_response |
104 | 98 | * @return array |
105 | 99 | */ |
106 | - protected function extractResponseHeadersAndBody($raw_response) |
|
107 | - { |
|
100 | + protected function extractResponseHeadersAndBody($raw_response) { |
|
108 | 101 | $header_size = $this->getheaderSize(); |
109 | 102 | |
110 | 103 | $raw_headers = mb_substr($raw_response, 0, $header_size); |
@@ -117,8 +110,7 @@ discard block |
||
117 | 110 | * @param Headers $headers |
118 | 111 | * @param string $raw_headers |
119 | 112 | */ |
120 | - protected function parseHeaders(Headers $headers, $raw_headers) |
|
121 | - { |
|
113 | + protected function parseHeaders(Headers $headers, $raw_headers) { |
|
122 | 114 | $raw_headers = str_replace("\r\n", "\n", $raw_headers); |
123 | 115 | |
124 | 116 | // There will be multiple headers if a 301 was followed |
@@ -143,8 +135,7 @@ discard block |
||
143 | 135 | * @return ResponseInterface |
144 | 136 | * @throws Exception |
145 | 137 | */ |
146 | - public function sendRequest(RequestInterface $request) |
|
147 | - { |
|
138 | + public function sendRequest(RequestInterface $request) { |
|
148 | 139 | $response = $this->getClient()->createResponse(); |
149 | 140 | $this->getCurl()->reset(); |
150 | 141 | $curlopts = array( |
@@ -24,8 +24,7 @@ discard block |
||
24 | 24 | |
25 | 25 | namespace FacebookAds\Http\Adapter\Curl; |
26 | 26 | |
27 | -abstract class AbstractCurl implements CurlInterface |
|
28 | -{ |
|
27 | +abstract class AbstractCurl implements CurlInterface { |
|
29 | 28 | /** |
30 | 29 | * @var resource |
31 | 30 | */ |
@@ -34,28 +33,24 @@ discard block |
||
34 | 33 | /** |
35 | 34 | * @throws \RuntimeException |
36 | 35 | */ |
37 | - public function __construct() |
|
38 | - { |
|
36 | + public function __construct() { |
|
39 | 37 | if (!extension_loaded('curl')) { |
40 | 38 | throw new \RuntimeException("Extension curl not loaded"); |
41 | 39 | } |
42 | 40 | } |
43 | 41 | |
44 | - public function __clone() |
|
45 | - { |
|
42 | + public function __clone() { |
|
46 | 43 | $this->handle = curl_copy_handle($this->handle); |
47 | 44 | } |
48 | 45 | |
49 | - public function __destruct() |
|
50 | - { |
|
46 | + public function __destruct() { |
|
51 | 47 | curl_close($this->handle); |
52 | 48 | } |
53 | 49 | |
54 | 50 | /** |
55 | 51 | * @return CurlInterface |
56 | 52 | */ |
57 | - public static function createOptimalVersion() |
|
58 | - { |
|
53 | + public static function createOptimalVersion() { |
|
59 | 54 | if (version_compare(PHP_VERSION, '5.5.0') >= 0) { |
60 | 55 | return new Curl55(); |
61 | 56 | } else { |
@@ -66,32 +61,28 @@ discard block |
||
66 | 61 | /** |
67 | 62 | * @return resource |
68 | 63 | */ |
69 | - public function getHandle() |
|
70 | - { |
|
64 | + public function getHandle() { |
|
71 | 65 | return $this->handle; |
72 | 66 | } |
73 | 67 | |
74 | 68 | /** |
75 | 69 | * @return int |
76 | 70 | */ |
77 | - public function errno() |
|
78 | - { |
|
71 | + public function errno() { |
|
79 | 72 | return curl_errno($this->handle); |
80 | 73 | } |
81 | 74 | |
82 | 75 | /** |
83 | 76 | * @return string |
84 | 77 | */ |
85 | - public function error() |
|
86 | - { |
|
78 | + public function error() { |
|
87 | 79 | return curl_error($this->handle); |
88 | 80 | } |
89 | 81 | |
90 | 82 | /** |
91 | 83 | * @return mixed |
92 | 84 | */ |
93 | - public function exec() |
|
94 | - { |
|
85 | + public function exec() { |
|
95 | 86 | return curl_exec($this->handle); |
96 | 87 | } |
97 | 88 | |
@@ -99,24 +90,21 @@ discard block |
||
99 | 90 | * @param int $opt |
100 | 91 | * @return mixed |
101 | 92 | */ |
102 | - public function getInfo($opt = 0) |
|
103 | - { |
|
93 | + public function getInfo($opt = 0) { |
|
104 | 94 | return curl_getinfo($this->handle, $opt); |
105 | 95 | } |
106 | 96 | |
107 | 97 | /** |
108 | 98 | * @return void |
109 | 99 | */ |
110 | - public function init() |
|
111 | - { |
|
100 | + public function init() { |
|
112 | 101 | $this->handle = $this->handle ?: curl_init(); |
113 | 102 | } |
114 | 103 | |
115 | 104 | /** |
116 | 105 | * @param array $opts |
117 | 106 | */ |
118 | - public function setoptArray(array $opts) |
|
119 | - { |
|
107 | + public function setoptArray(array $opts) { |
|
120 | 108 | curl_setopt_array($this->handle, $opts); |
121 | 109 | } |
122 | 110 | |
@@ -125,8 +113,7 @@ discard block |
||
125 | 113 | * @param mixed $value |
126 | 114 | * @return bool |
127 | 115 | */ |
128 | - public function setopt($option, $value) |
|
129 | - { |
|
116 | + public function setopt($option, $value) { |
|
130 | 117 | return curl_setopt($this->handle, $option, $value); |
131 | 118 | } |
132 | 119 | |
@@ -134,8 +121,7 @@ discard block |
||
134 | 121 | * @param int $age |
135 | 122 | * @return array |
136 | 123 | */ |
137 | - public static function version($age) |
|
138 | - { |
|
124 | + public static function version($age) { |
|
139 | 125 | return curl_version($age); |
140 | 126 | } |
141 | 127 | } |
@@ -24,13 +24,11 @@ discard block |
||
24 | 24 | |
25 | 25 | namespace FacebookAds\Http\Adapter\Curl; |
26 | 26 | |
27 | -class Curl extends AbstractCurl |
|
28 | -{ |
|
27 | +class Curl extends AbstractCurl { |
|
29 | 28 | /** |
30 | 29 | * @throws \RuntimeException |
31 | 30 | */ |
32 | - public function __construct() |
|
33 | - { |
|
31 | + public function __construct() { |
|
34 | 32 | parent::__construct(); |
35 | 33 | if (version_compare(PHP_VERSION, '5.5.0') >= 0) { |
36 | 34 | throw new \RuntimeException("Unsupported Curl version"); |
@@ -41,8 +39,7 @@ discard block |
||
41 | 39 | * @param string $string |
42 | 40 | * @return string |
43 | 41 | */ |
44 | - public function escape($string) |
|
45 | - { |
|
42 | + public function escape($string) { |
|
46 | 43 | return rawurlencode($string); |
47 | 44 | } |
48 | 45 | |
@@ -50,8 +47,7 @@ discard block |
||
50 | 47 | * @param int $bitmask |
51 | 48 | * @return int |
52 | 49 | */ |
53 | - public function pause($bitmask) |
|
54 | - { |
|
50 | + public function pause($bitmask) { |
|
55 | 51 | return 0; |
56 | 52 | } |
57 | 53 | |
@@ -59,16 +55,14 @@ discard block |
||
59 | 55 | * @param string $filepath |
60 | 56 | * @return string |
61 | 57 | */ |
62 | - public function preparePostFileField($filepath) |
|
63 | - { |
|
58 | + public function preparePostFileField($filepath) { |
|
64 | 59 | return "@".$filepath; |
65 | 60 | } |
66 | 61 | |
67 | 62 | /** |
68 | 63 | * @return void |
69 | 64 | */ |
70 | - public function reset() |
|
71 | - { |
|
65 | + public function reset() { |
|
72 | 66 | $this->handle && curl_close($this->handle); |
73 | 67 | $this->handle = curl_init(); |
74 | 68 | } |
@@ -77,8 +71,7 @@ discard block |
||
77 | 71 | * @param int $errornum |
78 | 72 | * @return NULL|string |
79 | 73 | */ |
80 | - public static function strerror($errornum) |
|
81 | - { |
|
74 | + public static function strerror($errornum) { |
|
82 | 75 | return curl_strerror($errornum); |
83 | 76 | } |
84 | 77 | |
@@ -86,8 +79,7 @@ discard block |
||
86 | 79 | * @param string $string |
87 | 80 | * @return bool|string |
88 | 81 | */ |
89 | - public function unescape($string) |
|
90 | - { |
|
82 | + public function unescape($string) { |
|
91 | 83 | return curl_unescape($this->handle, $string); |
92 | 84 | } |
93 | 85 | } |
@@ -24,8 +24,7 @@ |
||
24 | 24 | |
25 | 25 | namespace FacebookAds\Http\Adapter\Curl; |
26 | 26 | |
27 | -interface CurlInterface |
|
28 | -{ |
|
27 | +interface CurlInterface { |
|
29 | 28 | /** |
30 | 29 | * @return resource |
31 | 30 | */ |
@@ -24,13 +24,11 @@ discard block |
||
24 | 24 | |
25 | 25 | namespace FacebookAds\Http\Adapter\Curl; |
26 | 26 | |
27 | -class Curl55 extends AbstractCurl |
|
28 | -{ |
|
27 | +class Curl55 extends AbstractCurl { |
|
29 | 28 | /** |
30 | 29 | * @throws \RuntimeException |
31 | 30 | */ |
32 | - public function __construct() |
|
33 | - { |
|
31 | + public function __construct() { |
|
34 | 32 | parent::__construct(); |
35 | 33 | if (version_compare(PHP_VERSION, '5.5.0') < 0) { |
36 | 34 | throw new \RuntimeException("Unsupported Curl version"); |
@@ -41,8 +39,7 @@ discard block |
||
41 | 39 | * @param string $string |
42 | 40 | * @return bool|string |
43 | 41 | */ |
44 | - public function escape($string) |
|
45 | - { |
|
42 | + public function escape($string) { |
|
46 | 43 | return curl_escape($this->handle, $string); |
47 | 44 | } |
48 | 45 | |
@@ -50,8 +47,7 @@ discard block |
||
50 | 47 | * @param int $bitmask |
51 | 48 | * @return int |
52 | 49 | */ |
53 | - public function pause($bitmask) |
|
54 | - { |
|
50 | + public function pause($bitmask) { |
|
55 | 51 | return curl_pause($this->handle, $bitmask); |
56 | 52 | } |
57 | 53 | |
@@ -59,16 +55,14 @@ discard block |
||
59 | 55 | * @param string $filepath |
60 | 56 | * @return \CURLFile |
61 | 57 | */ |
62 | - public function preparePostFileField($filepath) |
|
63 | - { |
|
58 | + public function preparePostFileField($filepath) { |
|
64 | 59 | return new \CURLFile($filepath); |
65 | 60 | } |
66 | 61 | |
67 | 62 | /** |
68 | 63 | * @return void |
69 | 64 | */ |
70 | - public function reset() |
|
71 | - { |
|
65 | + public function reset() { |
|
72 | 66 | $this->handle && curl_reset($this->handle); |
73 | 67 | } |
74 | 68 | |
@@ -76,8 +70,7 @@ discard block |
||
76 | 70 | * @param int $errornum |
77 | 71 | * @return NULL|string |
78 | 72 | */ |
79 | - public static function strerror($errornum) |
|
80 | - { |
|
73 | + public static function strerror($errornum) { |
|
81 | 74 | return curl_strerror($errornum); |
82 | 75 | } |
83 | 76 | |
@@ -85,8 +78,7 @@ discard block |
||
85 | 78 | * @param string $string |
86 | 79 | * @return bool|string |
87 | 80 | */ |
88 | - public function unescape($string) |
|
89 | - { |
|
81 | + public function unescape($string) { |
|
90 | 82 | return curl_unescape($this->handle, $string); |
91 | 83 | } |
92 | 84 | } |
@@ -24,13 +24,11 @@ discard block |
||
24 | 24 | |
25 | 25 | namespace FacebookAds\Http; |
26 | 26 | |
27 | -class Parameters extends \ArrayObject |
|
28 | -{ |
|
27 | +class Parameters extends \ArrayObject { |
|
29 | 28 | /** |
30 | 29 | * @param array $data |
31 | 30 | */ |
32 | - public function enhance(array $data) |
|
33 | - { |
|
31 | + public function enhance(array $data) { |
|
34 | 32 | foreach ($data as $key => $value) { |
35 | 33 | $this[$key] = $value; |
36 | 34 | } |
@@ -40,16 +38,14 @@ discard block |
||
40 | 38 | * @param mixed $value |
41 | 39 | * @return string |
42 | 40 | */ |
43 | - protected function exportNonScalar($value) |
|
44 | - { |
|
41 | + protected function exportNonScalar($value) { |
|
45 | 42 | return json_encode($value); |
46 | 43 | } |
47 | 44 | |
48 | 45 | /** |
49 | 46 | * @return array |
50 | 47 | */ |
51 | - public function export() |
|
52 | - { |
|
48 | + public function export() { |
|
53 | 49 | $data = array(); |
54 | 50 | foreach ($this as $key => $value) { |
55 | 51 | $data[$key] = is_null($value) || is_scalar($value) |
@@ -24,6 +24,5 @@ |
||
24 | 24 | |
25 | 25 | namespace FacebookAds\Exception; |
26 | 26 | |
27 | -class Exception extends \Exception |
|
28 | -{ |
|
27 | +class Exception extends \Exception { |
|
29 | 28 | } |
@@ -24,8 +24,7 @@ discard block |
||
24 | 24 | |
25 | 25 | namespace FacebookAds\Logger\CurlLogger; |
26 | 26 | |
27 | -final class JsonNode |
|
28 | -{ |
|
27 | +final class JsonNode { |
|
29 | 28 | /** |
30 | 29 | * @var int |
31 | 30 | */ |
@@ -51,8 +50,7 @@ discard block |
||
51 | 50 | * @return $this |
52 | 51 | * @throws \InvalidArgumentException |
53 | 52 | */ |
54 | - public static function factory($value) |
|
55 | - { |
|
53 | + public static function factory($value) { |
|
56 | 54 | $object = new self(); |
57 | 55 | switch (true) { |
58 | 56 | case is_object($value): |
@@ -73,16 +71,14 @@ discard block |
||
73 | 71 | return $object; |
74 | 72 | } |
75 | 73 | |
76 | - public function __construct() |
|
77 | - { |
|
74 | + public function __construct() { |
|
78 | 75 | $this->children = new \ArrayObject(); |
79 | 76 | } |
80 | 77 | |
81 | 78 | /** |
82 | 79 | * @return mixed |
83 | 80 | */ |
84 | - public function getValue() |
|
85 | - { |
|
81 | + public function getValue() { |
|
86 | 82 | return $this->value; |
87 | 83 | } |
88 | 84 | |
@@ -90,8 +86,7 @@ discard block |
||
90 | 86 | * @param mixed $value |
91 | 87 | * @return $this |
92 | 88 | */ |
93 | - public function setValue($value) |
|
94 | - { |
|
89 | + public function setValue($value) { |
|
95 | 90 | $this->value = $value; |
96 | 91 | |
97 | 92 | return $this; |
@@ -100,16 +95,14 @@ discard block |
||
100 | 95 | /** |
101 | 96 | * @return \ArrayObject |
102 | 97 | */ |
103 | - public function getChildren() |
|
104 | - { |
|
98 | + public function getChildren() { |
|
105 | 99 | return $this->children; |
106 | 100 | } |
107 | 101 | |
108 | 102 | /** |
109 | 103 | * @return int |
110 | 104 | */ |
111 | - public function getMaxTreeChildrenCount() |
|
112 | - { |
|
105 | + public function getMaxTreeChildrenCount() { |
|
113 | 106 | $max = $this->getChildren()->count(); |
114 | 107 | |
115 | 108 | /** @var JsonNode $child */ |
@@ -125,16 +118,14 @@ discard block |
||
125 | 118 | * @param int $indent |
126 | 119 | * @return string |
127 | 120 | */ |
128 | - protected function getPadding($indent) |
|
129 | - { |
|
121 | + protected function getPadding($indent) { |
|
130 | 122 | return str_repeat(' ', $indent * self::INDENT_UNIT); |
131 | 123 | } |
132 | 124 | |
133 | 125 | /** |
134 | 126 | * @return mixed |
135 | 127 | */ |
136 | - protected function getLastChildKey() |
|
137 | - { |
|
128 | + protected function getLastChildKey() { |
|
138 | 129 | if ($this->getChildren()->count() === 0) { |
139 | 130 | return null; |
140 | 131 | } |
@@ -149,8 +140,7 @@ discard block |
||
149 | 140 | * @param int $indent |
150 | 141 | * @return string |
151 | 142 | */ |
152 | - protected function encodeList($indent) |
|
153 | - { |
|
143 | + protected function encodeList($indent) { |
|
154 | 144 | $value = $this->getValue(); |
155 | 145 | if (empty($value) || (array_keys($value) === range(0, count($value) - 1))) { |
156 | 146 | $is_map = false; |
@@ -184,8 +174,7 @@ discard block |
||
184 | 174 | * @param int $indent |
185 | 175 | * @return string |
186 | 176 | */ |
187 | - public function encode($indent = 0) |
|
188 | - { |
|
177 | + public function encode($indent = 0) { |
|
189 | 178 | $value = $this->getValue(); |
190 | 179 | if (is_array($value) || is_object($value)) { |
191 | 180 | if ($this->getMaxTreeChildrenCount() > 2) { |