Completed
Push — master ( fd48c6...d6eea8 )
by Mike
02:42
created
src/Exception/AuthenticationException.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -2,12 +2,12 @@
 block discarded – undo
2 2
 
3 3
 namespace SugarAPI\SDK\Exception;
4 4
 
5
-class AuthenticationException extends SDKException{
5
+class AuthenticationException extends SDKException {
6 6
 
7 7
     protected $message = 'Authentication Exception occurred when attempting to Login to SugarCRM instance. Message: %s';
8 8
 
9
-    public function __construct($message) {
10
-        $message = sprintf($this->message,$message);
9
+    public function __construct($message){
10
+        $message = sprintf($this->message, $message);
11 11
         parent::__construct($message);
12 12
     }
13 13
 
Please login to merge, or discard this patch.
src/EntryPoint/Abstracts/AbstractEntryPoint.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -85,13 +85,13 @@  discard block
 block discarded – undo
85 85
      */
86 86
     protected $accessToken;
87 87
 
88
-    public function __construct($url,$options = array()){
88
+    public function __construct($url, $options = array()){
89 89
         $this->url = $url;
90 90
         $this->Module = $this->_MODULE;
91 91
 
92
-        if (!empty($options)) {
93
-            if (empty($this->Module)) {
94
-                if (strpos($this->_URL, '$module') !== FALSE) {
92
+        if (!empty($options)){
93
+            if (empty($this->Module)){
94
+                if (strpos($this->_URL, '$module')!==FALSE){
95 95
                     $this->module($options[0]);
96 96
                     array_shift($options);
97 97
                 }
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
      * @inheritdoc
131 131
      */
132 132
     public function execute(){
133
-        if ($this->verifyURL() && $this->validateData()) {
133
+        if ($this->verifyURL() && $this->validateData()){
134 134
             $this->configureURL();
135 135
             $this->Request->setURL($this->url);
136 136
             $this->Request->send();
@@ -144,14 +144,14 @@  discard block
 block discarded – undo
144 144
     /**
145 145
      * @inheritdoc
146 146
      */
147
-    public function authRequired() {
147
+    public function authRequired(){
148 148
         return $this->_AUTH_REQUIRED;
149 149
     }
150 150
 
151 151
     /**
152 152
      * @inheritdoc
153 153
      */
154
-    public function configureAuth($accessToken) {
154
+    public function configureAuth($accessToken){
155 155
         if ($this->authRequired()){
156 156
             $this->accessToken = $accessToken;
157 157
             $this->Request->addHeader('OAuth-Token', $accessToken);
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
     /**
163 163
      * @inheritdoc
164 164
      */
165
-    public function getModule() {
165
+    public function getModule(){
166 166
         return $this->Module;
167 167
     }
168 168
 
@@ -201,30 +201,30 @@  discard block
 block discarded – undo
201 201
      */
202 202
     protected function configureURL(){
203 203
         $url = $this->_URL;
204
-        if (strpos($this->_URL,"$")!==FALSE) {
205
-            if (count($this->Options) > 0 || !empty($this->Module)) {
204
+        if (strpos($this->_URL, "$")!==FALSE){
205
+            if (count($this->Options)>0 || !empty($this->Module)){
206 206
                 $urlParts = explode("/", $this->_URL);
207 207
                 $o = 0;
208
-                foreach ($urlParts as $key => $part) {
209
-                    if (strpos($part, '$module') !== FALSE) {
210
-                        if (isset($this->Module)) {
208
+                foreach ($urlParts as $key => $part){
209
+                    if (strpos($part, '$module')!==FALSE){
210
+                        if (isset($this->Module)){
211 211
                             $urlParts[$key] = $this->Module;
212 212
                             continue;
213
-                        } else {
214
-                            if (isset($this->Options[$o])) {
213
+                        }else{
214
+                            if (isset($this->Options[$o])){
215 215
                                 $this->Module = $this->Options[$o];
216 216
                                 array_shift($this->Options);
217 217
                             }
218 218
                         }
219 219
                     }
220
-                    if (strpos($part, "$") !== FALSE) {
221
-                        if (isset($this->Options[$o])) {
220
+                    if (strpos($part, "$")!==FALSE){
221
+                        if (isset($this->Options[$o])){
222 222
                             $urlParts[$key] = $this->Options[$o];
223 223
                             $o++;
224 224
                         }
225 225
                     }
226 226
                 }
227
-                $url = implode($urlParts,"/");
227
+                $url = implode($urlParts, "/");
228 228
             }
229 229
         }
230 230
         $this->url = $this->url.$url;
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
      * Setup the Response Object Property, not called until after Request Execution
242 242
      */
243 243
     protected function setupResponse(){
244
-        $this->Response = new JSONResponse($this->Request->getResponse(),$this->Request->getCurlObject());
244
+        $this->Response = new JSONResponse($this->Request->getResponse(), $this->Request->getCurlObject());
245 245
     }
246 246
 
247 247
     /**
@@ -250,14 +250,14 @@  discard block
 block discarded – undo
250 250
      * @throws EntryPointException
251 251
      */
252 252
     protected function verifyURL(){
253
-        $urlVarCount = substr_count($this->_URL,"$");
253
+        $urlVarCount = substr_count($this->_URL, "$");
254 254
         $optionCount = 0;
255 255
         if (!empty($this->Module)){
256 256
             $optionCount++;
257 257
         }
258 258
         $optionCount += count($this->Options);
259 259
         if ($urlVarCount!==$optionCount){
260
-            if (empty($this->Module) && strpos($this->_URL,'$module')){
260
+            if (empty($this->Module) && strpos($this->_URL, '$module')){
261 261
                 throw new EntryPointException('Module is required for EntryPoint '.get_called_class());
262 262
             }else{
263 263
                 throw new EntryPointException('EntryPoint URL ('.$this->_URL.') requires more parameters than passed.');
@@ -273,11 +273,11 @@  discard block
 block discarded – undo
273 273
      * @throws EntryPointException
274 274
      */
275 275
     protected function validateData(){
276
-        if (empty($this->_REQUIRED_DATA)||count($this->_REQUIRED_DATA)==0){
276
+        if (empty($this->_REQUIRED_DATA) || count($this->_REQUIRED_DATA)==0){
277 277
             return true;
278 278
         }else{
279 279
             $errors = array();
280
-            foreach($this->_REQUIRED_DATA as $property){
280
+            foreach ($this->_REQUIRED_DATA as $property){
281 281
                 if (isset($this->Data[$property]) || $this->Data[$property]!==null){
282 282
                     continue;
283 283
                 }else{
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
                 }
286 286
             }
287 287
             if (count($errors)>0){
288
-                throw new EntryPointException('EntryPoint requires specific properties in Request data. Missing the following '.implode($errors,","));
288
+                throw new EntryPointException('EntryPoint requires specific properties in Request data. Missing the following '.implode($errors, ","));
289 289
             }else{
290 290
                 return true;
291 291
             }
Please login to merge, or discard this patch.
src/EntryPoint/Abstracts/GET/FileEntryPoint.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
     /**
18 18
      * @inheritdoc
19 19
      */
20
-    protected function setupRequest() {
20
+    protected function setupRequest(){
21 21
         $this->Request = new GETFile();
22 22
     }
23 23
 
@@ -25,8 +25,8 @@  discard block
 block discarded – undo
25 25
      * @inheritdoc
26 26
      * File Response Object has option File Destination parameter, which is passed using DownloadDir property
27 27
      */
28
-    protected function setupResponse() {
29
-        $this->Response = new FileResponse($this->Request->getResponse(),$this->Request->getCurlObject(),$this->downloadDir);
28
+    protected function setupResponse(){
29
+        $this->Response = new FileResponse($this->Request->getResponse(), $this->Request->getCurlObject(), $this->downloadDir);
30 30
     }
31 31
 
32 32
     /**
Please login to merge, or discard this patch.
src/EntryPoint/Abstracts/POST/FileEntryPoint.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@
 block discarded – undo
10 10
     /**
11 11
      * @inheritdoc
12 12
      */
13
-    protected function setupRequest() {
13
+    protected function setupRequest(){
14 14
         $this->Request = new POSTFile();
15 15
     }
16 16
 
Please login to merge, or discard this patch.
src/SugarAPI.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 
29 29
     private $entryPoints = array();
30 30
 
31
-    public function __construct($instance='',array $authOptions = array()){
31
+    public function __construct($instance = '', array $authOptions = array()){
32 32
         $this->loadDefaults();
33 33
         if (!empty($instance)){
34 34
             $this->setInstance($instance);
@@ -40,8 +40,8 @@  discard block
 block discarded – undo
40 40
     }
41 41
 
42 42
     protected function loadDefaults(){
43
-        include __DIR__ .DIRECTORY_SEPARATOR.'defaults.php';
44
-        if (isset($defaults)) {
43
+        include __DIR__.DIRECTORY_SEPARATOR.'defaults.php';
44
+        if (isset($defaults)){
45 45
             static::$_DEFAULTS = $defaults;
46 46
             if (isset($defaults['instance'])){
47 47
                 $this->setInstance($defaults['instance']);
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
     }
54 54
 
55 55
     public function setAuthOptions(array $options){
56
-        foreach($this->authOptions as $key => $value){
56
+        foreach ($this->authOptions as $key => $value){
57 57
             if (isset($options[$key])){
58 58
                 $this->authOptions[$key] = $options[$key];
59 59
             }
@@ -61,27 +61,27 @@  discard block
 block discarded – undo
61 61
     }
62 62
 
63 63
     protected function registerSDKEntryPoints(){
64
-        require __DIR__ .DIRECTORY_SEPARATOR.'EntryPoint' .DIRECTORY_SEPARATOR.'registry.php';
65
-        foreach($entryPoints as $funcName => $className){
64
+        require __DIR__.DIRECTORY_SEPARATOR.'EntryPoint'.DIRECTORY_SEPARATOR.'registry.php';
65
+        foreach ($entryPoints as $funcName => $className){
66 66
             $className = "SugarAPI\\SDK\\EntryPoint\\".$className;
67
-            $this->registerEntryPoint($funcName,$className);
67
+            $this->registerEntryPoint($funcName, $className);
68 68
         }
69 69
     }
70 70
 
71
-    public function registerEntryPoint($funcName,$className){
71
+    public function registerEntryPoint($funcName, $className){
72 72
         if (isset($this->entryPoints[$funcName])){
73 73
             throw new SDKException('SDK method already defined. Method '.$funcName.' references Class '.$className);
74 74
         }
75 75
         $this->entryPoints[$funcName] = $className;
76 76
     }
77 77
 
78
-    public function __call($name,$params){
79
-        if (array_key_exists($name,$this->entryPoints)){
78
+    public function __call($name, $params){
79
+        if (array_key_exists($name, $this->entryPoints)){
80 80
             $Class = $this->entryPoints[$name];
81
-            $EntryPoint = new $Class($this->url,$params);
81
+            $EntryPoint = new $Class($this->url, $params);
82 82
 
83 83
             if ($EntryPoint->authRequired()){
84
-                if (isset($this->authToken)) {
84
+                if (isset($this->authToken)){
85 85
                     $EntryPoint->configureAuth($this->authToken->access_token);
86 86
                 }else{
87 87
                     throw new AuthenticationException('no_auth');
@@ -105,17 +105,17 @@  discard block
 block discarded – undo
105 105
         }
106 106
     }
107 107
     public function setInstance($instance){
108
-        if (strpos("https",$instance)!==FALSE){
108
+        if (strpos("https", $instance)!==FALSE){
109 109
             $this->secure = TRUE;
110 110
         }
111
-        if (strpos("http",$instance)===FALSE){
111
+        if (strpos("http", $instance)===FALSE){
112 112
             $instance = "http://".$instance;
113 113
         }
114
-        if (strpos("rest/v10",$instance)!==FALSE){
115
-            $instance = str_replace("rest/v10","",$instance);
114
+        if (strpos("rest/v10", $instance)!==FALSE){
115
+            $instance = str_replace("rest/v10", "", $instance);
116 116
         }
117 117
         $this->instance = $instance;
118
-        $this->url = rtrim($this->instance,"/").self::API_URL;
118
+        $this->url = rtrim($this->instance, "/").self::API_URL;
119 119
     }
120 120
     public function getURL(){
121 121
         return $this->url;
Please login to merge, or discard this patch.
examples/UpdateRecord.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,21 +1,21 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-require_once __DIR__ . '/../vendor/autoload.php';
3
+require_once __DIR__.'/../vendor/autoload.php';
4 4
 
5 5
 $record_id = '436dcb0b-14a9-c0d4-3046-5706b186b9b8';
6 6
 
7 7
 try{
8
-    $SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Pro/7621/',array('username' => 'admin','password'=>'asdf'));
8
+    $SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Pro/7621/', array('username' => 'admin', 'password'=>'asdf'));
9 9
     $SugarAPI->login();
10
-    $EP = $SugarAPI->updateRecord('Accounts',$record_id);
10
+    $EP = $SugarAPI->updateRecord('Accounts', $record_id);
11 11
     $EP->getRequest()->setOption();
12
-    $record = $SugarAPI->updateRecord('Accounts',$record_id)->data(array(
12
+    $record = $SugarAPI->updateRecord('Accounts', $record_id)->data(array(
13 13
         'name' => 'Test Record 5',
14 14
         'email1' => '[email protected]'
15 15
     ))->execute()->getResponse()->getBody();
16 16
     echo "Updated Record: ".$record->id;
17 17
 
18
-}catch(\SugarAPI\SDK\Exception\AuthenticationException $ex){
18
+}catch (\SugarAPI\SDK\Exception\AuthenticationException $ex){
19 19
     print $ex->getMessage();
20 20
 }
21 21
 
Please login to merge, or discard this patch.
examples/GetFile.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-require_once __DIR__ . '/../vendor/autoload.php';
3
+require_once __DIR__.'/../vendor/autoload.php';
4 4
 
5 5
 $recordID = 'ac096703-67fd-8dd2-980a-57097932f07a';
6 6
 
7 7
 try{
8
-    $SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Ent/7700/',array('username' => 'admin','password'=>'asdf'));
8
+    $SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Ent/7700/', array('username' => 'admin', 'password'=>'asdf'));
9 9
     $SugarAPI->login();
10
-    $EP = $SugarAPI->getAttachment('Notes',$recordID,'filename')->downloadTo(__DIR__)->execute();
10
+    $EP = $SugarAPI->getAttachment('Notes', $recordID, 'filename')->downloadTo(__DIR__)->execute();
11 11
     $response = $EP->getResponse();
12 12
     if ($response->getStatus()=='200'){
13 13
         if (file_exists($response->file())){
@@ -20,6 +20,6 @@  discard block
 block discarded – undo
20 20
         print_r($response->getBody());
21 21
     }
22 22
 
23
-}catch(\SugarAPI\SDK\Exception\SDKException $ex){
23
+}catch (\SugarAPI\SDK\Exception\SDKException $ex){
24 24
     print $ex->getMessage();
25 25
 }
26 26
\ No newline at end of file
Please login to merge, or discard this patch.
examples/CreateRecord.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-require_once __DIR__ . '/../vendor/autoload.php';
3
+require_once __DIR__.'/../vendor/autoload.php';
4 4
 
5 5
 try{
6
-    $SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Pro/7621/',array('username' => 'admin','password'=>'asdf'));
6
+    $SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Pro/7621/', array('username' => 'admin', 'password'=>'asdf'));
7 7
     $SugarAPI->login();
8 8
     $EP = $SugarAPI->createRecord('Accounts');
9 9
     $EP->data(array(
@@ -13,12 +13,12 @@  discard block
 block discarded – undo
13 13
     $response = $EP->execute()->getResponse();
14 14
     if ($response->getStatus()=='200'){
15 15
         $record = $response->getBody();
16
-        $EP2 = $SugarAPI->getRecord('Accounts',$record->id)->data(array('fields' => 'name,email1'));
16
+        $EP2 = $SugarAPI->getRecord('Accounts', $record->id)->data(array('fields' => 'name,email1'));
17 17
         $getResponse = $EP2->execute()->getResponse();
18 18
         print $EP2->getUrl();
19 19
         print_r($getResponse->getBody());
20 20
     }
21 21
 
22
-}catch(\SugarAPI\SDK\Exception\AuthenticationException $ex){
22
+}catch (\SugarAPI\SDK\Exception\AuthenticationException $ex){
23 23
     print $ex->getMessage();
24 24
 }
25 25
\ No newline at end of file
Please login to merge, or discard this patch.
examples/FavoriteRecord.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,18 +1,18 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-require_once __DIR__ . '/../vendor/autoload.php';
3
+require_once __DIR__.'/../vendor/autoload.php';
4 4
 
5 5
 $record_id = 'a887c75b-b89a-852e-8e67-56f1ccdee355';
6 6
 
7 7
 try{
8
-    $SugarAPI = new \SugarAPI\SDK\SugarAPI('localhost/ent77',array('username' => 'admin','password'=>'admin123'));
8
+    $SugarAPI = new \SugarAPI\SDK\SugarAPI('localhost/ent77', array('username' => 'admin', 'password'=>'admin123'));
9 9
     $SugarAPI->login();
10
-    $EP = $SugarAPI->favorite('Accounts',$record_id);
10
+    $EP = $SugarAPI->favorite('Accounts', $record_id);
11 11
     $response = $EP->execute()->getResponse()->getBody();
12 12
 
13 13
     print_r($response);
14 14
 
15
-}catch(\SugarAPI\SDK\Exception\AuthenticationException $ex){
15
+}catch (\SugarAPI\SDK\Exception\AuthenticationException $ex){
16 16
     print $ex->getMessage();
17 17
 }
18 18
 
Please login to merge, or discard this patch.