@@ -30,8 +30,7 @@ discard block |
||
| 30 | 30 | use FacebookAds\Logger\LoggerInterface; |
| 31 | 31 | use FacebookAds\Logger\NullLogger; |
| 32 | 32 | |
| 33 | -class Api |
|
| 34 | -{ |
|
| 33 | +class Api { |
|
| 35 | 34 | /** |
| 36 | 35 | * @var string |
| 37 | 36 | */ |
@@ -80,8 +79,7 @@ discard block |
||
| 80 | 79 | * @param string $access_token |
| 81 | 80 | * @return static |
| 82 | 81 | */ |
| 83 | - public static function init($app_id, $app_secret, $access_token) |
|
| 84 | - { |
|
| 82 | + public static function init($app_id, $app_secret, $access_token) { |
|
| 85 | 83 | $session = new Session($app_id, $app_secret, $access_token); |
| 86 | 84 | $api = new static(new Client(), $session); |
| 87 | 85 | static::setInstance($api); |
@@ -92,16 +90,14 @@ discard block |
||
| 92 | 90 | /** |
| 93 | 91 | * @return Api|null |
| 94 | 92 | */ |
| 95 | - public static function instance() |
|
| 96 | - { |
|
| 93 | + public static function instance() { |
|
| 97 | 94 | return static::$instance; |
| 98 | 95 | } |
| 99 | 96 | |
| 100 | 97 | /** |
| 101 | 98 | * @param Api $instance |
| 102 | 99 | */ |
| 103 | - public static function setInstance(Api $instance) |
|
| 104 | - { |
|
| 100 | + public static function setInstance(Api $instance) { |
|
| 105 | 101 | static::$instance = $instance; |
| 106 | 102 | } |
| 107 | 103 | |
@@ -109,8 +105,7 @@ discard block |
||
| 109 | 105 | * @param string $string |
| 110 | 106 | * @return string |
| 111 | 107 | */ |
| 112 | - public static function base64UrlEncode($string) |
|
| 113 | - { |
|
| 108 | + public static function base64UrlEncode($string) { |
|
| 114 | 109 | $str = strtr(base64_encode($string), '+/', '-_'); |
| 115 | 110 | $str = str_replace('=', '', $str); |
| 116 | 111 | return $str; |
@@ -151,8 +146,7 @@ discard block |
||
| 151 | 146 | * @param RequestInterface $request |
| 152 | 147 | * @return ResponseInterface |
| 153 | 148 | */ |
| 154 | - public function executeRequest(RequestInterface $request) |
|
| 155 | - { |
|
| 149 | + public function executeRequest(RequestInterface $request) { |
|
| 156 | 150 | $this->getLogger()->logRequest('debug', $request); |
| 157 | 151 | $response = $request->execute(); |
| 158 | 152 | $this->getLogger()->logResponse('debug', $response); |
@@ -163,8 +157,7 @@ discard block |
||
| 163 | 157 | /** |
| 164 | 158 | * @return string |
| 165 | 159 | */ |
| 166 | - public function getDefaultGraphVersion() |
|
| 167 | - { |
|
| 160 | + public function getDefaultGraphVersion() { |
|
| 168 | 161 | if ($this->defaultGraphVersion === null) { |
| 169 | 162 | $match = array(); |
| 170 | 163 | if (preg_match("/^\d+\.\d+/", static::VERSION, $match)) { |
@@ -178,8 +171,7 @@ discard block |
||
| 178 | 171 | /** |
| 179 | 172 | * @param string $version |
| 180 | 173 | */ |
| 181 | - public function setDefaultGraphVersion($version) |
|
| 182 | - { |
|
| 174 | + public function setDefaultGraphVersion($version) { |
|
| 183 | 175 | $this->defaultGraphVersion = $version; |
| 184 | 176 | } |
| 185 | 177 | |
@@ -204,24 +196,21 @@ discard block |
||
| 204 | 196 | /** |
| 205 | 197 | * @return Session |
| 206 | 198 | */ |
| 207 | - public function getSession() |
|
| 208 | - { |
|
| 199 | + public function getSession() { |
|
| 209 | 200 | return $this->session; |
| 210 | 201 | } |
| 211 | 202 | |
| 212 | 203 | /** |
| 213 | 204 | * @param LoggerInterface $logger |
| 214 | 205 | */ |
| 215 | - public function setLogger(LoggerInterface $logger) |
|
| 216 | - { |
|
| 206 | + public function setLogger(LoggerInterface $logger) { |
|
| 217 | 207 | $this->logger = $logger; |
| 218 | 208 | } |
| 219 | 209 | |
| 220 | 210 | /** |
| 221 | 211 | * @return LoggerInterface |
| 222 | 212 | */ |
| 223 | - public function getLogger() |
|
| 224 | - { |
|
| 213 | + public function getLogger() { |
|
| 225 | 214 | if ($this->logger === null) { |
| 226 | 215 | $this->logger = new NullLogger(); |
| 227 | 216 | } |
@@ -232,8 +221,7 @@ discard block |
||
| 232 | 221 | /** |
| 233 | 222 | * @return Client |
| 234 | 223 | */ |
| 235 | - public function getHttpClient() |
|
| 236 | - { |
|
| 224 | + public function getHttpClient() { |
|
| 237 | 225 | return $this->httpClient; |
| 238 | 226 | } |
| 239 | 227 | } |
@@ -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) { |
@@ -26,14 +26,12 @@ |
||
| 26 | 26 | |
| 27 | 27 | use FacebookAds\Http\Parameters; |
| 28 | 28 | |
| 29 | -class JsonAwareParameters extends Parameters |
|
| 30 | -{ |
|
| 29 | +class JsonAwareParameters extends Parameters { |
|
| 31 | 30 | /** |
| 32 | 31 | * @param mixed $value |
| 33 | 32 | * @return string |
| 34 | 33 | */ |
| 35 | - protected function exportNonScalar($value) |
|
| 36 | - { |
|
| 34 | + protected function exportNonScalar($value) { |
|
| 37 | 35 | return JsonNode::factory($value)->encode(); |
| 38 | 36 | } |
| 39 | 37 | } |
@@ -29,8 +29,7 @@ discard block |
||
| 29 | 29 | use FacebookAds\Http\ResponseInterface; |
| 30 | 30 | use FacebookAds\Logger\CurlLogger\JsonAwareParameters; |
| 31 | 31 | |
| 32 | -class CurlLogger implements LoggerInterface |
|
| 33 | -{ |
|
| 32 | +class CurlLogger implements LoggerInterface { |
|
| 34 | 33 | /** |
| 35 | 34 | * @var string |
| 36 | 35 | */ |
@@ -79,16 +78,14 @@ discard block |
||
| 79 | 78 | /** |
| 80 | 79 | * @param resource $handle |
| 81 | 80 | */ |
| 82 | - public function __construct($handle = null) |
|
| 83 | - { |
|
| 81 | + public function __construct($handle = null) { |
|
| 84 | 82 | $this->handle = is_resource($handle) ? $handle : STDOUT; |
| 85 | 83 | } |
| 86 | 84 | |
| 87 | 85 | /** |
| 88 | 86 | * @return bool |
| 89 | 87 | */ |
| 90 | - public function isJsonPrettyPrint() |
|
| 91 | - { |
|
| 88 | + public function isJsonPrettyPrint() { |
|
| 92 | 89 | return $this->jsonPrettyPrint; |
| 93 | 90 | } |
| 94 | 91 | |
@@ -96,8 +93,7 @@ discard block |
||
| 96 | 93 | * @param bool $json_pretty_print |
| 97 | 94 | * @return $this |
| 98 | 95 | */ |
| 99 | - public function setJsonPrettyPrint($json_pretty_print) |
|
| 100 | - { |
|
| 96 | + public function setJsonPrettyPrint($json_pretty_print) { |
|
| 101 | 97 | $this->jsonPrettyPrint = $json_pretty_print; |
| 102 | 98 | |
| 103 | 99 | return $this; |
@@ -107,8 +103,7 @@ discard block |
||
| 107 | 103 | * @param string $method |
| 108 | 104 | * @return string |
| 109 | 105 | */ |
| 110 | - public static function getMethodFlag($method) |
|
| 111 | - { |
|
| 106 | + public static function getMethodFlag($method) { |
|
| 112 | 107 | switch ($method) { |
| 113 | 108 | case RequestInterface::METHOD_GET: |
| 114 | 109 | return static::METHOD_GET_FLAG; |
@@ -126,8 +121,7 @@ discard block |
||
| 126 | 121 | * @param string $value |
| 127 | 122 | * @return string |
| 128 | 123 | */ |
| 129 | - public static function getParamFlag($method, $value) |
|
| 130 | - { |
|
| 124 | + public static function getParamFlag($method, $value) { |
|
| 131 | 125 | return $method === RequestInterface::METHOD_POST |
| 132 | 126 | ? static::PARAM_POST_FLAG |
| 133 | 127 | : (strstr($value, "\n") |
@@ -140,8 +134,7 @@ discard block |
||
| 140 | 134 | * @param int $indent |
| 141 | 135 | * @return string |
| 142 | 136 | */ |
| 143 | - protected function indent($string, $indent) |
|
| 144 | - { |
|
| 137 | + protected function indent($string, $indent) { |
|
| 145 | 138 | return str_replace("\n", " \n".str_repeat(' ', $indent), $string); |
| 146 | 139 | } |
| 147 | 140 | |
@@ -151,8 +144,7 @@ discard block |
||
| 151 | 144 | * @param bool $is_file |
| 152 | 145 | * @return string |
| 153 | 146 | */ |
| 154 | - protected function processParams(Parameters $params, $method, $is_file) |
|
| 155 | - { |
|
| 147 | + protected function processParams(Parameters $params, $method, $is_file) { |
|
| 156 | 148 | $chunks = array(); |
| 157 | 149 | if ($this->isJsonPrettyPrint()) { |
| 158 | 150 | $params = new JsonAwareParameters($params); |
@@ -181,8 +173,7 @@ discard block |
||
| 181 | 173 | * @param RequestInterface $request |
| 182 | 174 | * @return string |
| 183 | 175 | */ |
| 184 | - protected function processUrl(RequestInterface $request) |
|
| 185 | - { |
|
| 176 | + protected function processUrl(RequestInterface $request) { |
|
| 186 | 177 | return $request->getProtocol().$request->getDomain() |
| 187 | 178 | .'/v'.$request->getGraphVersion().$request->getPath(); |
| 188 | 179 | } |
@@ -190,8 +181,7 @@ discard block |
||
| 190 | 181 | /** |
| 191 | 182 | * @param string $buffer |
| 192 | 183 | */ |
| 193 | - protected function flush($buffer) |
|
| 194 | - { |
|
| 184 | + protected function flush($buffer) { |
|
| 195 | 185 | fwrite($this->handle, $buffer.PHP_EOL.PHP_EOL); |
| 196 | 186 | } |
| 197 | 187 | |
@@ -200,8 +190,7 @@ discard block |
||
| 200 | 190 | * @param string $message |
| 201 | 191 | * @param array $context |
| 202 | 192 | */ |
| 203 | - public function log($level, $message, array $context = array()) |
|
| 204 | - { |
|
| 193 | + public function log($level, $message, array $context = array()) { |
|
| 205 | 194 | // We only care about requests |
| 206 | 195 | } |
| 207 | 196 | |
@@ -210,8 +199,7 @@ discard block |
||
| 210 | 199 | * @param mixed $key |
| 211 | 200 | * @return mixed |
| 212 | 201 | */ |
| 213 | - protected function removeArrayKey(array &$array, $key) |
|
| 214 | - { |
|
| 202 | + protected function removeArrayKey(array &$array, $key) { |
|
| 215 | 203 | if (array_key_exists($key, $array)) { |
| 216 | 204 | $value = $array[$key]; |
| 217 | 205 | unset($array[$key]); |
@@ -226,8 +214,7 @@ discard block |
||
| 226 | 214 | * @param array $params |
| 227 | 215 | * @return array |
| 228 | 216 | */ |
| 229 | - protected function sortParams(array $params) |
|
| 230 | - { |
|
| 217 | + protected function sortParams(array $params) { |
|
| 231 | 218 | $access_token = $this->removeArrayKey($params, 'access_token'); |
| 232 | 219 | $appsecret_proof = $this->removeArrayKey($params, 'appsecret_proof'); |
| 233 | 220 | $access_token !== null && $params['access_token'] = $access_token; |
@@ -27,15 +27,13 @@ discard block |
||
| 27 | 27 | use FacebookAds\Http\RequestInterface; |
| 28 | 28 | use FacebookAds\Http\ResponseInterface; |
| 29 | 29 | |
| 30 | -class NullLogger implements LoggerInterface |
|
| 31 | -{ |
|
| 30 | +class NullLogger implements LoggerInterface { |
|
| 32 | 31 | /** |
| 33 | 32 | * @param string $level |
| 34 | 33 | * @param string $message |
| 35 | 34 | * @param array $context |
| 36 | 35 | */ |
| 37 | - public function log($level, $message, array $context = array()) |
|
| 38 | - { |
|
| 36 | + public function log($level, $message, array $context = array()) { |
|
| 39 | 37 | } |
| 40 | 38 | |
| 41 | 39 | /** |
@@ -43,8 +41,7 @@ discard block |
||
| 43 | 41 | * @param RequestInterface $request |
| 44 | 42 | * @param array $context |
| 45 | 43 | */ |
| 46 | - public function logRequest($level, RequestInterface $request, array $context = array()) |
|
| 47 | - { |
|
| 44 | + public function logRequest($level, RequestInterface $request, array $context = array()) { |
|
| 48 | 45 | } |
| 49 | 46 | |
| 50 | 47 | /** |
@@ -52,7 +49,6 @@ discard block |
||
| 52 | 49 | * @param ResponseInterface $response |
| 53 | 50 | * @param array $context |
| 54 | 51 | */ |
| 55 | - public function logResponse($level, ResponseInterface $response, array $context = array()) |
|
| 56 | - { |
|
| 52 | + public function logResponse($level, ResponseInterface $response, array $context = array()) { |
|
| 57 | 53 | } |
| 58 | 54 | } |
@@ -27,8 +27,7 @@ |
||
| 27 | 27 | use FacebookAds\Http\RequestInterface; |
| 28 | 28 | use FacebookAds\Http\ResponseInterface; |
| 29 | 29 | |
| 30 | -interface LoggerInterface |
|
| 31 | -{ |
|
| 30 | +interface LoggerInterface { |
|
| 32 | 31 | /** |
| 33 | 32 | * @param string $level |
| 34 | 33 | * @param string $message |