@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | protected $entryPoints = array(); |
62 | 62 | |
63 | 63 | public function __construct($server = '',array $credentials = array()){ |
64 | - if (!empty($server)) { |
|
64 | + if (!empty($server)){ |
|
65 | 65 | $this->setServer($server); |
66 | 66 | } |
67 | 67 | if (!empty($credentials)){ |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | /** |
74 | 74 | * @inheritdoc |
75 | 75 | */ |
76 | - public function setServer($server) { |
|
76 | + public function setServer($server){ |
|
77 | 77 | $this->server = $server; |
78 | 78 | $this->apiURL = Helpers::configureAPIURL($this->server); |
79 | 79 | return $this; |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | /** |
83 | 83 | * @inheritdoc |
84 | 84 | */ |
85 | - public function getAPIUrl() { |
|
85 | + public function getAPIUrl(){ |
|
86 | 86 | return $this->apiURL; |
87 | 87 | } |
88 | 88 | |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | /** |
126 | 126 | * @inheritdoc |
127 | 127 | */ |
128 | - public function getServer() { |
|
128 | + public function getServer(){ |
|
129 | 129 | return $this->server; |
130 | 130 | } |
131 | 131 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | $implements = class_implements($className); |
158 | 158 | if (is_array($implements) && in_array('SugarAPI\SDK\EntryPoint\Interfaces\EPInterface',$implements)){ |
159 | 159 | $this->entryPoints[$funcName] = $className; |
160 | - }else{ |
|
160 | + } else{ |
|
161 | 161 | throw new EntryPointException($className,'Class must extend SugarAPI\SDK\EntryPoint\Interfaces\EPInterface'); |
162 | 162 | } |
163 | 163 | return $this; |
@@ -176,12 +176,12 @@ discard block |
||
176 | 176 | $EntryPoint = new $Class($this->apiURL, $params); |
177 | 177 | |
178 | 178 | if ($EntryPoint->authRequired()){ |
179 | - if (isset($this->token) && $this->authenticated()) { |
|
179 | + if (isset($this->token) && $this->authenticated()){ |
|
180 | 180 | $EntryPoint->setAuth($this->getToken()->access_token); |
181 | 181 | } |
182 | 182 | } |
183 | 183 | return $EntryPoint; |
184 | - }else{ |
|
184 | + } else{ |
|
185 | 185 | throw new EntryPointException($name,'Unregistered EntryPoint'); |
186 | 186 | } |
187 | 187 | } |
@@ -190,13 +190,13 @@ discard block |
||
190 | 190 | * @inheritdoc |
191 | 191 | * @throws AuthenticationException - When Login request fails |
192 | 192 | */ |
193 | - public function login() { |
|
193 | + public function login(){ |
|
194 | 194 | $EP = new OAuth2Token($this->apiURL); |
195 | 195 | $response = $EP->execute($this->credentials)->getResponse(); |
196 | 196 | if ($response->getStatus()=='200'){ |
197 | 197 | $this->setToken($response->getBody(false)); |
198 | 198 | static::storeToken($this->token,$this->credentials['client_id']); |
199 | - } else { |
|
199 | + } else{ |
|
200 | 200 | $error = $response->getBody(); |
201 | 201 | throw new AuthenticationException("Login Response [".$error['error']."] ".$error['error_message']); |
202 | 202 | } |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | if ($response->getStatus()=='200'){ |
219 | 219 | $this->setToken($response->getBody(false)); |
220 | 220 | static::storeToken($this->token,$this->credentials['client_id']); |
221 | - }else{ |
|
221 | + } else{ |
|
222 | 222 | $error = $response->getBody(); |
223 | 223 | throw new AuthenticationException("Refresh Response [".$error['error']."] ".$error['error_message']); |
224 | 224 | } |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | if ($response->getStatus()=='200'){ |
237 | 237 | unset($this->token); |
238 | 238 | static::removeStoredToken($this->credentials['client_id']); |
239 | - }else{ |
|
239 | + } else{ |
|
240 | 240 | $error = $response->getBody(); |
241 | 241 | throw new AuthenticationException("Logout Response [".$error['error']."] ".$error['message']); |
242 | 242 | } |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | /** |
248 | 248 | * @inheritdoc |
249 | 249 | */ |
250 | - public static function storeToken($token, $client_id) { |
|
250 | + public static function storeToken($token, $client_id){ |
|
251 | 251 | static::$_STORED_TOKENS[$client_id] = $token; |
252 | 252 | return true; |
253 | 253 | } |
@@ -255,14 +255,14 @@ discard block |
||
255 | 255 | /** |
256 | 256 | * @inheritdoc |
257 | 257 | */ |
258 | - public static function getStoredToken($client_id) { |
|
258 | + public static function getStoredToken($client_id){ |
|
259 | 259 | return static::$_STORED_TOKENS[$client_id]; |
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
263 | 263 | * @inheritdoc |
264 | 264 | */ |
265 | - public static function removeStoredToken($client_id) { |
|
265 | + public static function removeStoredToken($client_id){ |
|
266 | 266 | unset(static::$_STORED_TOKENS[$client_id]); |
267 | 267 | return true; |
268 | 268 | } |
@@ -39,7 +39,7 @@ |
||
39 | 39 | public static function getSDKEntryPointRegistry(){ |
40 | 40 | $entryPoints = array(); |
41 | 41 | require __DIR__.DIRECTORY_SEPARATOR.'registry.php'; |
42 | - foreach ($entryPoints as $funcName => $className) { |
|
42 | + foreach ($entryPoints as $funcName => $className){ |
|
43 | 43 | $className = "SugarAPI\\SDK\\EntryPoint\\" . $className; |
44 | 44 | $entryPoints[$funcName] = $className; |
45 | 45 | } |
@@ -8,12 +8,12 @@ |
||
8 | 8 | |
9 | 9 | abstract class AbstractPostFileEntryPoint extends AbstractEntryPoint { |
10 | 10 | |
11 | - public function __construct($url, array $options = array()) { |
|
11 | + public function __construct($url, array $options = array()){ |
|
12 | 12 | $this->setRequest(new POSTFile()); |
13 | 13 | parent::__construct($url, $options); |
14 | 14 | } |
15 | 15 | |
16 | - public function execute($data = null) { |
|
16 | + public function execute($data = null){ |
|
17 | 17 | parent::execute($data); |
18 | 18 | $this->setResponse(new JSON($this->Request->getResponse(),$this->Request->getCurlObject())); |
19 | 19 | return $this; |
@@ -8,12 +8,12 @@ |
||
8 | 8 | |
9 | 9 | abstract class AbstractPostFileEntryPoint extends AbstractEntryPoint { |
10 | 10 | |
11 | - public function __construct($url, array $options = array()) { |
|
11 | + public function __construct($url, array $options = array()){ |
|
12 | 12 | $this->setRequest(new POSTFile()); |
13 | 13 | parent::__construct($url, $options); |
14 | 14 | } |
15 | 15 | |
16 | - public function execute($data = null) { |
|
16 | + public function execute($data = null){ |
|
17 | 17 | parent::execute($data); |
18 | 18 | $this->setResponse(new JSON($this->Request->getResponse(),$this->Request->getCurlObject())); |
19 | 19 | return $this; |
@@ -8,12 +8,12 @@ |
||
8 | 8 | |
9 | 9 | abstract class AbstractPostFileEntryPoint extends AbstractEntryPoint { |
10 | 10 | |
11 | - public function __construct($url, array $options = array()) { |
|
11 | + public function __construct($url, array $options = array()){ |
|
12 | 12 | $this->setRequest(new POSTFile()); |
13 | 13 | parent::__construct($url, $options); |
14 | 14 | } |
15 | 15 | |
16 | - public function execute($data = null) { |
|
16 | + public function execute($data = null){ |
|
17 | 17 | parent::execute($data); |
18 | 18 | $this->setResponse(new JSON($this->Request->getResponse(),$this->Request->getCurlObject())); |
19 | 19 | return $this; |
@@ -8,12 +8,12 @@ |
||
8 | 8 | |
9 | 9 | abstract class AbstractPostFileEntryPoint extends AbstractEntryPoint { |
10 | 10 | |
11 | - public function __construct($url, array $options = array()) { |
|
11 | + public function __construct($url, array $options = array()){ |
|
12 | 12 | $this->setRequest(new POSTFile()); |
13 | 13 | parent::__construct($url, $options); |
14 | 14 | } |
15 | 15 | |
16 | - public function execute($data = null) { |
|
16 | + public function execute($data = null){ |
|
17 | 17 | parent::execute($data); |
18 | 18 | $this->setResponse(new JSON($this->Request->getResponse(),$this->Request->getCurlObject())); |
19 | 19 | return $this; |
@@ -8,12 +8,12 @@ |
||
8 | 8 | |
9 | 9 | abstract class AbstractPostFileEntryPoint extends AbstractEntryPoint { |
10 | 10 | |
11 | - public function __construct($url, array $options = array()) { |
|
11 | + public function __construct($url, array $options = array()){ |
|
12 | 12 | $this->setRequest(new POSTFile()); |
13 | 13 | parent::__construct($url, $options); |
14 | 14 | } |
15 | 15 | |
16 | - public function execute($data = null) { |
|
16 | + public function execute($data = null){ |
|
17 | 17 | parent::execute($data); |
18 | 18 | $this->setResponse(new JSON($this->Request->getResponse(),$this->Request->getCurlObject())); |
19 | 19 | return $this; |
@@ -90,7 +90,7 @@ |
||
90 | 90 | /** |
91 | 91 | * Always make sure to destroy Curl Resource |
92 | 92 | */ |
93 | - public function __destruct() { |
|
93 | + public function __destruct(){ |
|
94 | 94 | if ($this->status!==self::STATUS_CLOSED){ |
95 | 95 | curl_close($this->CurlRequest); |
96 | 96 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | public function __construct($baseUrl,array $options = array()){ |
120 | 120 | $this->baseUrl = $baseUrl; |
121 | 121 | |
122 | - if (!empty($options)) { |
|
122 | + if (!empty($options)){ |
|
123 | 123 | $this->setOptions($options); |
124 | 124 | } |
125 | 125 | $this->configureURL(); |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | /** |
147 | 147 | * @inheritdoc |
148 | 148 | */ |
149 | - public function setAuth($accessToken) { |
|
149 | + public function setAuth($accessToken){ |
|
150 | 150 | $this->accessToken = $accessToken; |
151 | 151 | return $this; |
152 | 152 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | /** |
155 | 155 | * @inheritdoc |
156 | 156 | */ |
157 | - public function setUrl($url) { |
|
157 | + public function setUrl($url){ |
|
158 | 158 | $this->Url = $url; |
159 | 159 | return $this; |
160 | 160 | } |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | /** |
163 | 163 | * @inheritdoc |
164 | 164 | */ |
165 | - public function setRequest(RequestInterface $Request) { |
|
165 | + public function setRequest(RequestInterface $Request){ |
|
166 | 166 | $this->Request = $Request; |
167 | 167 | return $this; |
168 | 168 | } |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | /** |
171 | 171 | * @inheritdoc |
172 | 172 | */ |
173 | - public function setResponse(ResponseInterface $Response) { |
|
173 | + public function setResponse(ResponseInterface $Response){ |
|
174 | 174 | $this->Response = $Response; |
175 | 175 | return $this; |
176 | 176 | } |
@@ -220,10 +220,10 @@ discard block |
||
220 | 220 | public function execute($data = NULL){ |
221 | 221 | $data = ($data === NULL?$this->Data:$data); |
222 | 222 | $this->configureData($data); |
223 | - if ($this->verifyOptions() && is_object($this->Request)) { |
|
223 | + if ($this->verifyOptions() && is_object($this->Request)){ |
|
224 | 224 | $this->configureRequest(); |
225 | 225 | $this->Request->send(); |
226 | - }else{ |
|
226 | + } else{ |
|
227 | 227 | throw new InvalidRequestException(get_called_class(),"Request property not configured"); |
228 | 228 | } |
229 | 229 | return $this; |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | /** |
233 | 233 | * @inheritdoc |
234 | 234 | */ |
235 | - public function authRequired() { |
|
235 | + public function authRequired(){ |
|
236 | 236 | return $this->_AUTH_REQUIRED; |
237 | 237 | } |
238 | 238 | |
@@ -242,10 +242,10 @@ discard block |
||
242 | 242 | * @throws RequiredDataException |
243 | 243 | */ |
244 | 244 | protected function configureRequest(){ |
245 | - if ($this->verifyUrl()) { |
|
245 | + if ($this->verifyUrl()){ |
|
246 | 246 | $this->Request->setURL($this->Url); |
247 | 247 | } |
248 | - if ($this->verifyData() && !empty($this->Data)) { |
|
248 | + if ($this->verifyData() && !empty($this->Data)){ |
|
249 | 249 | $this->Request->setBody($this->Data); |
250 | 250 | } |
251 | 251 | $this->configureAuth(); |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | * Configures the authentication header on the Request object |
256 | 256 | */ |
257 | 257 | protected function configureAuth(){ |
258 | - if ($this->authRequired()) { |
|
258 | + if ($this->authRequired()){ |
|
259 | 259 | $this->Request->addHeader('OAuth-Token', $this->accessToken); |
260 | 260 | } |
261 | 261 | } |
@@ -292,12 +292,12 @@ discard block |
||
292 | 292 | */ |
293 | 293 | protected function configureURL(){ |
294 | 294 | $url = $this->_URL; |
295 | - if ($this->requiresOptions()) { |
|
295 | + if ($this->requiresOptions()){ |
|
296 | 296 | $urlParts = explode("/", $this->_URL); |
297 | 297 | $o = 0; |
298 | - foreach ($urlParts as $key => $part) { |
|
299 | - if (strpos($part, "$") !== FALSE) { |
|
300 | - if (isset($this->Options[$o])) { |
|
298 | + foreach ($urlParts as $key => $part){ |
|
299 | + if (strpos($part, "$") !== FALSE){ |
|
300 | + if (isset($this->Options[$o])){ |
|
301 | 301 | $urlParts[$key] = $this->Options[$o]; |
302 | 302 | $o++; |
303 | 303 | } |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | * @throws RequiredDataException |
344 | 344 | */ |
345 | 345 | protected function verifyData(){ |
346 | - if (isset($this->_DATA_TYPE)||!empty($this->_DATA_TYPE)) { |
|
346 | + if (isset($this->_DATA_TYPE)||!empty($this->_DATA_TYPE)){ |
|
347 | 347 | $this->verifyDataType(); |
348 | 348 | } |
349 | 349 | if (!empty($this->_REQUIRED_DATA)){ |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | * @throws RequiredDataException |
359 | 359 | */ |
360 | 360 | protected function verifyDataType(){ |
361 | - if (gettype($this->Data) !== $this->_DATA_TYPE) { |
|
361 | + if (gettype($this->Data) !== $this->_DATA_TYPE){ |
|
362 | 362 | throw new RequiredDataException(get_called_class(),"Valid DataType is {$this->_DATA_TYPE}"); |
363 | 363 | } |
364 | 364 | return true; |