@@ -63,9 +63,9 @@ discard block |
||
63 | 63 | */ |
64 | 64 | protected $entryPoints = array(); |
65 | 65 | |
66 | - public function __construct($server = '',array $credentials = array()){ |
|
66 | + public function __construct($server = '', array $credentials = array()){ |
|
67 | 67 | $server = (empty($server)?$this->server:$server); |
68 | - if (!empty($server)) { |
|
68 | + if (!empty($server)){ |
|
69 | 69 | $this->setServer($server); |
70 | 70 | } |
71 | 71 | $credentials = (empty($credentials)?$this->credentials:$credentials); |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @inheritdoc |
80 | 80 | * @param string $server |
81 | 81 | */ |
82 | - public function setServer($server) { |
|
82 | + public function setServer($server){ |
|
83 | 83 | $this->server = $server; |
84 | 84 | $this->apiURL = Helpers::configureAPIURL($this->server); |
85 | 85 | return $this; |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | /** |
89 | 89 | * @inheritdoc |
90 | 90 | */ |
91 | - public function getAPIUrl() { |
|
91 | + public function getAPIUrl(){ |
|
92 | 92 | return $this->apiURL; |
93 | 93 | } |
94 | 94 | |
@@ -98,9 +98,9 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function setCredentials(array $credentials){ |
100 | 100 | $this->credentials = $credentials; |
101 | - if (isset($this->credentials['client_id'])) { |
|
101 | + if (isset($this->credentials['client_id'])){ |
|
102 | 102 | $token = static::getStoredToken($this->credentials['client_id']); |
103 | - if (!empty($token)) { |
|
103 | + if (!empty($token)){ |
|
104 | 104 | $this->setToken($token); |
105 | 105 | } |
106 | 106 | } |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | /** |
134 | 134 | * @inheritdoc |
135 | 135 | */ |
136 | - public function getServer() { |
|
136 | + public function getServer(){ |
|
137 | 137 | return $this->server; |
138 | 138 | } |
139 | 139 | |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | * @inheritdoc |
142 | 142 | */ |
143 | 143 | public function authenticated(){ |
144 | - return time() < $this->expiration; |
|
144 | + return time()<$this->expiration; |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -163,10 +163,10 @@ discard block |
||
163 | 163 | */ |
164 | 164 | public function registerEntryPoint($funcName, $className){ |
165 | 165 | $implements = class_implements($className); |
166 | - if (is_array($implements) && in_array('SugarAPI\SDK\EntryPoint\Interfaces\EPInterface',$implements)){ |
|
166 | + if (is_array($implements) && in_array('SugarAPI\SDK\EntryPoint\Interfaces\EPInterface', $implements)){ |
|
167 | 167 | $this->entryPoints[$funcName] = $className; |
168 | 168 | }else{ |
169 | - throw new EntryPointException($className,'Class must extend SugarAPI\SDK\EntryPoint\Interfaces\EPInterface'); |
|
169 | + throw new EntryPointException($className, 'Class must extend SugarAPI\SDK\EntryPoint\Interfaces\EPInterface'); |
|
170 | 170 | } |
171 | 171 | return $this; |
172 | 172 | } |
@@ -184,13 +184,13 @@ discard block |
||
184 | 184 | $EntryPoint = new $Class($this->apiURL, $params); |
185 | 185 | |
186 | 186 | if ($EntryPoint->authRequired()){ |
187 | - if (isset($this->token) && $this->authenticated()) { |
|
187 | + if (isset($this->token) && $this->authenticated()){ |
|
188 | 188 | $EntryPoint->setAuth($this->getToken()->access_token); |
189 | 189 | } |
190 | 190 | } |
191 | 191 | return $EntryPoint; |
192 | 192 | }else{ |
193 | - throw new EntryPointException($name,'Unregistered EntryPoint'); |
|
193 | + throw new EntryPointException($name, 'Unregistered EntryPoint'); |
|
194 | 194 | } |
195 | 195 | } |
196 | 196 | |
@@ -198,13 +198,13 @@ discard block |
||
198 | 198 | * @inheritdoc |
199 | 199 | * @throws AuthenticationException - When Login request fails |
200 | 200 | */ |
201 | - public function login() { |
|
201 | + public function login(){ |
|
202 | 202 | $EP = new OAuth2Token($this->apiURL); |
203 | 203 | $response = $EP->execute($this->credentials)->getResponse(); |
204 | 204 | if ($response->getStatus()=='200'){ |
205 | 205 | $this->setToken($response->getBody(FALSE)); |
206 | - static::storeToken($this->token,$this->credentials['client_id']); |
|
207 | - } else { |
|
206 | + static::storeToken($this->token, $this->credentials['client_id']); |
|
207 | + }else{ |
|
208 | 208 | $error = $response->getBody(); |
209 | 209 | throw new AuthenticationException("Login Response [".$error['error']."] ".$error['error_message']); |
210 | 210 | } |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | $response = $EP->execute($refreshOptions)->getResponse(); |
226 | 226 | if ($response->getStatus()=='200'){ |
227 | 227 | $this->setToken($response->getBody(FALSE)); |
228 | - static::storeToken($this->token,$this->credentials['client_id']); |
|
228 | + static::storeToken($this->token, $this->credentials['client_id']); |
|
229 | 229 | }else{ |
230 | 230 | $error = $response->getBody(); |
231 | 231 | throw new AuthenticationException("Refresh Response [".$error['error']."] ".$error['error_message']); |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | * @inheritdoc |
257 | 257 | * @param \stdClass $token |
258 | 258 | */ |
259 | - public static function storeToken($token, $client_id) { |
|
259 | + public static function storeToken($token, $client_id){ |
|
260 | 260 | static::$_STORED_TOKENS[$client_id] = $token; |
261 | 261 | return TRUE; |
262 | 262 | } |
@@ -264,14 +264,14 @@ discard block |
||
264 | 264 | /** |
265 | 265 | * @inheritdoc |
266 | 266 | */ |
267 | - public static function getStoredToken($client_id) { |
|
267 | + public static function getStoredToken($client_id){ |
|
268 | 268 | return (isset(static::$_STORED_TOKENS[$client_id])?static::$_STORED_TOKENS[$client_id]:NULL); |
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
272 | 272 | * @inheritdoc |
273 | 273 | */ |
274 | - public static function removeStoredToken($client_id) { |
|
274 | + public static function removeStoredToken($client_id){ |
|
275 | 275 | unset(static::$_STORED_TOKENS[$client_id]); |
276 | 276 | return TRUE; |
277 | 277 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | |
66 | 66 | public function __construct($server = '',array $credentials = array()){ |
67 | 67 | $server = (empty($server)?$this->server:$server); |
68 | - if (!empty($server)) { |
|
68 | + if (!empty($server)){ |
|
69 | 69 | $this->setServer($server); |
70 | 70 | } |
71 | 71 | $credentials = (empty($credentials)?$this->credentials:$credentials); |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @inheritdoc |
80 | 80 | * @param string $server |
81 | 81 | */ |
82 | - public function setServer($server) { |
|
82 | + public function setServer($server){ |
|
83 | 83 | $this->server = $server; |
84 | 84 | $this->apiURL = Helpers::configureAPIURL($this->server); |
85 | 85 | return $this; |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | /** |
89 | 89 | * @inheritdoc |
90 | 90 | */ |
91 | - public function getAPIUrl() { |
|
91 | + public function getAPIUrl(){ |
|
92 | 92 | return $this->apiURL; |
93 | 93 | } |
94 | 94 | |
@@ -98,9 +98,9 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function setCredentials(array $credentials){ |
100 | 100 | $this->credentials = $credentials; |
101 | - if (isset($this->credentials['client_id'])) { |
|
101 | + if (isset($this->credentials['client_id'])){ |
|
102 | 102 | $token = static::getStoredToken($this->credentials['client_id']); |
103 | - if (!empty($token)) { |
|
103 | + if (!empty($token)){ |
|
104 | 104 | $this->setToken($token); |
105 | 105 | } |
106 | 106 | } |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | /** |
134 | 134 | * @inheritdoc |
135 | 135 | */ |
136 | - public function getServer() { |
|
136 | + public function getServer(){ |
|
137 | 137 | return $this->server; |
138 | 138 | } |
139 | 139 | |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | $implements = class_implements($className); |
166 | 166 | if (is_array($implements) && in_array('SugarAPI\SDK\EntryPoint\Interfaces\EPInterface',$implements)){ |
167 | 167 | $this->entryPoints[$funcName] = $className; |
168 | - }else{ |
|
168 | + } else{ |
|
169 | 169 | throw new EntryPointException($className,'Class must extend SugarAPI\SDK\EntryPoint\Interfaces\EPInterface'); |
170 | 170 | } |
171 | 171 | return $this; |
@@ -184,12 +184,12 @@ discard block |
||
184 | 184 | $EntryPoint = new $Class($this->apiURL, $params); |
185 | 185 | |
186 | 186 | if ($EntryPoint->authRequired()){ |
187 | - if (isset($this->token) && $this->authenticated()) { |
|
187 | + if (isset($this->token) && $this->authenticated()){ |
|
188 | 188 | $EntryPoint->setAuth($this->getToken()->access_token); |
189 | 189 | } |
190 | 190 | } |
191 | 191 | return $EntryPoint; |
192 | - }else{ |
|
192 | + } else{ |
|
193 | 193 | throw new EntryPointException($name,'Unregistered EntryPoint'); |
194 | 194 | } |
195 | 195 | } |
@@ -198,13 +198,13 @@ discard block |
||
198 | 198 | * @inheritdoc |
199 | 199 | * @throws AuthenticationException - When Login request fails |
200 | 200 | */ |
201 | - public function login() { |
|
201 | + public function login(){ |
|
202 | 202 | $EP = new OAuth2Token($this->apiURL); |
203 | 203 | $response = $EP->execute($this->credentials)->getResponse(); |
204 | 204 | if ($response->getStatus()=='200'){ |
205 | 205 | $this->setToken($response->getBody(FALSE)); |
206 | 206 | static::storeToken($this->token,$this->credentials['client_id']); |
207 | - } else { |
|
207 | + } else{ |
|
208 | 208 | $error = $response->getBody(); |
209 | 209 | throw new AuthenticationException("Login Response [".$error['error']."] ".$error['error_message']); |
210 | 210 | } |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | if ($response->getStatus()=='200'){ |
227 | 227 | $this->setToken($response->getBody(FALSE)); |
228 | 228 | static::storeToken($this->token,$this->credentials['client_id']); |
229 | - }else{ |
|
229 | + } else{ |
|
230 | 230 | $error = $response->getBody(); |
231 | 231 | throw new AuthenticationException("Refresh Response [".$error['error']."] ".$error['error_message']); |
232 | 232 | } |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | if ($response->getStatus()=='200'){ |
245 | 245 | unset($this->token); |
246 | 246 | static::removeStoredToken($this->credentials['client_id']); |
247 | - }else{ |
|
247 | + } else{ |
|
248 | 248 | $error = $response->getBody(); |
249 | 249 | throw new AuthenticationException("Logout Response [".$error['error']."] ".$error['message']); |
250 | 250 | } |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | * @inheritdoc |
257 | 257 | * @param \stdClass $token |
258 | 258 | */ |
259 | - public static function storeToken($token, $client_id) { |
|
259 | + public static function storeToken($token, $client_id){ |
|
260 | 260 | static::$_STORED_TOKENS[$client_id] = $token; |
261 | 261 | return TRUE; |
262 | 262 | } |
@@ -264,14 +264,14 @@ discard block |
||
264 | 264 | /** |
265 | 265 | * @inheritdoc |
266 | 266 | */ |
267 | - public static function getStoredToken($client_id) { |
|
267 | + public static function getStoredToken($client_id){ |
|
268 | 268 | return (isset(static::$_STORED_TOKENS[$client_id])?static::$_STORED_TOKENS[$client_id]:NULL); |
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
272 | 272 | * @inheritdoc |
273 | 273 | */ |
274 | - public static function removeStoredToken($client_id) { |
|
274 | + public static function removeStoredToken($client_id){ |
|
275 | 275 | unset(static::$_STORED_TOKENS[$client_id]); |
276 | 276 | return TRUE; |
277 | 277 | } |