Completed
Push — master ( e6cd79...15515b )
by Mike
02:12
created
src/Request/Abstracts/AbstractRequest.php 1 patch
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -133,6 +133,7 @@
 block discarded – undo
133 133
 
134 134
     /**
135 135
      * @inheritdoc
136
+     * @param string $body
136 137
      */
137 138
     public function setBody($body) {
138 139
         $this->body = $body;
Please login to merge, or discard this patch.
src/SugarAPI.php 4 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -68,6 +68,9 @@
 block discarded – undo
68 68
         }
69 69
     }
70 70
 
71
+    /**
72
+     * @param string $className
73
+     */
71 74
     public function registerEntryPoint($funcName,$className){
72 75
         if (isset($this->entryPoints[$funcName])){
73 76
             throw new SDKException('SDK method already defined. Method '.$funcName.' references Class '.$className);
Please login to merge, or discard this patch.
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -2,8 +2,6 @@
 block discarded – undo
2 2
 
3 3
 namespace SugarAPI\SDK;
4 4
 
5
-use SugarAPI\SDK\Exception\InitializationFailure;
6
-use SugarAPI\SDK\Exception\InvalidEntryPoint;
7 5
 use SugarAPI\SDK\Exception\AuthenticationException;
8 6
 use SugarAPI\SDK\Exception\SDKException;
9 7
 
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -28,102 +28,102 @@
 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
-        if (!empty($instance)){
33
+        if (!empty($instance)) {
34 34
             $this->setInstance($instance);
35 35
         }
36
-        if (!empty($authOptions)){
36
+        if (!empty($authOptions)) {
37 37
             $this->setAuthOptions($authOptions);
38 38
         }
39 39
         $this->registerSDKEntryPoints();
40 40
     }
41 41
 
42
-    protected function loadDefaults(){
43
-        include __DIR__ .DIRECTORY_SEPARATOR.'defaults.php';
42
+    protected function loadDefaults() {
43
+        include __DIR__.DIRECTORY_SEPARATOR.'defaults.php';
44 44
         if (isset($defaults)) {
45 45
             static::$_DEFAULTS = $defaults;
46
-            if (isset($defaults['instance'])){
46
+            if (isset($defaults['instance'])) {
47 47
                 $this->setInstance($defaults['instance']);
48 48
             }
49
-            if (isset($defaults['auth']) && is_array($defaults['auth'])){
49
+            if (isset($defaults['auth']) && is_array($defaults['auth'])) {
50 50
                 $this->setAuthOptions($defaults['auth']);
51 51
             }
52 52
         }
53 53
     }
54 54
 
55
-    public function setAuthOptions(array $options){
56
-        foreach($this->authOptions as $key => $value){
57
-            if (isset($options[$key])){
55
+    public function setAuthOptions(array $options) {
56
+        foreach ($this->authOptions as $key => $value) {
57
+            if (isset($options[$key])) {
58 58
                 $this->authOptions[$key] = $options[$key];
59 59
             }
60 60
         }
61 61
     }
62 62
 
63
-    protected function registerSDKEntryPoints(){
64
-        require __DIR__ .DIRECTORY_SEPARATOR.'EntryPoint' .DIRECTORY_SEPARATOR.'registry.php';
65
-        foreach($entryPoints as $funcName => $className){
63
+    protected function registerSDKEntryPoints() {
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){
72
-        if (isset($this->entryPoints[$funcName])){
71
+    public function registerEntryPoint($funcName, $className) {
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
-            if ($EntryPoint->authRequired()){
83
+            if ($EntryPoint->authRequired()) {
84 84
                 if (isset($this->authToken)) {
85 85
                     $EntryPoint->getRequest()->addHeader('OAuth-Token', $this->authToken->access_token);
86
-                }else{
86
+                }else {
87 87
                     throw new AuthenticationException('no_auth');
88 88
                 }
89 89
             }
90 90
             return $EntryPoint;
91
-        }else{
91
+        }else {
92 92
             throw new SDKException('Method '.$name.', is not a registered method of the SugarAPI SDK');
93 93
         }
94 94
     }
95
-    public function login(){
96
-        if (empty($this->authOptions['username']) || empty($this->authOptions['password'])){
95
+    public function login() {
96
+        if (empty($this->authOptions['username']) || empty($this->authOptions['password'])) {
97 97
             throw new AuthenticationException("Username or Password was not provided.");
98 98
         }
99 99
         $EP = $this->accessToken();
100 100
         $response = $EP->data($this->authOptions)->execute()->getResponse();
101
-        if ($response->getStatus()=='200'){
101
+        if ($response->getStatus()=='200') {
102 102
             $this->authToken = $response->getBody();
103
-        }else{
103
+        }else {
104 104
             throw new AuthenticationException($response->getBody());
105 105
         }
106 106
     }
107
-    public function setInstance($instance){
108
-        if (strpos("https",$instance)!==FALSE){
107
+    public function setInstance($instance) {
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
-    public function getURL(){
120
+    public function getURL() {
121 121
         return $this->url;
122 122
     }
123
-    public function getToken(){
123
+    public function getToken() {
124 124
         return $this->authToken;
125 125
     }
126
-    public function getAuthOptions(){
126
+    public function getAuthOptions() {
127 127
         return $this->authOptions;
128 128
     }
129 129
 }
130 130
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -83,12 +83,12 @@  discard block
 block discarded – undo
83 83
             if ($EntryPoint->authRequired()){
84 84
                 if (isset($this->authToken)) {
85 85
                     $EntryPoint->getRequest()->addHeader('OAuth-Token', $this->authToken->access_token);
86
-                }else{
86
+                } else{
87 87
                     throw new AuthenticationException('no_auth');
88 88
                 }
89 89
             }
90 90
             return $EntryPoint;
91
-        }else{
91
+        } else{
92 92
             throw new SDKException('Method '.$name.', is not a registered method of the SugarAPI SDK');
93 93
         }
94 94
     }
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
         $response = $EP->data($this->authOptions)->execute()->getResponse();
101 101
         if ($response->getStatus()=='200'){
102 102
             $this->authToken = $response->getBody();
103
-        }else{
103
+        } else{
104 104
             throw new AuthenticationException($response->getBody());
105 105
         }
106 106
     }
Please login to merge, or discard this patch.
src/EntryPoint/GET/RecordFileField.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@
 block discarded – undo
4 4
 
5 5
 use SugarAPI\SDK\EntryPoint\Abstracts\GET\FileEntryPoint as GETFileEntryPoint;
6 6
 
7
-class RecordFileField extends GETFileEntryPoint{
7
+class RecordFileField extends GETFileEntryPoint {
8 8
 
9 9
     protected $_URL = '$module/$record/file/$field';
10 10
 
Please login to merge, or discard this patch.
src/EntryPoint/Abstracts/AbstractEntryPoint.php 1 patch
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -22,13 +22,13 @@  discard block
 block discarded – undo
22 22
     protected $Request;
23 23
     protected $Response;
24 24
 
25
-    public function __construct($url,$options = array()){
25
+    public function __construct($url, $options = array()) {
26 26
         $this->url = $url;
27 27
         $this->Module = $this->_MODULE;
28 28
 
29 29
         if (!empty($options)) {
30 30
             if (empty($this->Module)) {
31
-                if (strpos($this->_URL, '$module') !== FALSE) {
31
+                if (strpos($this->_URL, '$module')!==FALSE) {
32 32
                     $this->module($options[0]);
33 33
                     array_shift($options);
34 34
                 }
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
     /**
42 42
      * @inheritdoc
43 43
      */
44
-    public function module($module){
44
+    public function module($module) {
45 45
         $this->Module = $module;
46 46
         return $this;
47 47
     }
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
     /**
50 50
      * @inheritdoc
51 51
      */
52
-    public function options(array $options){
52
+    public function options(array $options) {
53 53
         $this->Options = $options;
54 54
         return $this;
55 55
     }
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
     /**
58 58
      * @inheritdoc
59 59
      */
60
-    public function data(array $data){
60
+    public function data(array $data) {
61 61
         $this->Data = $data;
62 62
         $this->Request->setBody($this->Data);
63 63
         return $this;
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
     /**
67 67
      * @inheritdoc
68 68
      */
69
-    public function execute(){
69
+    public function execute() {
70 70
         if ($this->verifyURL() && $this->validateData()) {
71 71
             $this->configureURL();
72 72
             $this->Request->setURL($this->url);
@@ -96,28 +96,28 @@  discard block
 block discarded – undo
96 96
     /**
97 97
      *
98 98
      */
99
-    public function getData(){
99
+    public function getData() {
100 100
         return $this->Data;
101 101
     }
102 102
 
103 103
     /**
104 104
      * @inheritdoc
105 105
      */
106
-    public function getURL(){
106
+    public function getURL() {
107 107
         return $this->url;
108 108
     }
109 109
 
110 110
     /**
111 111
      * @inheritdoc
112 112
      */
113
-    public function getResponse(){
113
+    public function getResponse() {
114 114
         return $this->Response;
115 115
     }
116 116
 
117 117
     /**
118 118
      * @inheritdoc
119 119
      */
120
-    public function getRequest(){
120
+    public function getRequest() {
121 121
         return $this->Request;
122 122
     }
123 123
 
@@ -126,32 +126,32 @@  discard block
 block discarded – undo
126 126
      * - Replaces $module with $this->Module
127 127
      * - Replcaes all other variables starting with $, with options in the order they were given
128 128
      */
129
-    protected function configureURL(){
129
+    protected function configureURL() {
130 130
         $url = $this->_URL;
131
-        if (strpos($this->_URL,"$")!==FALSE) {
132
-            if (count($this->Options) > 0 || !empty($this->Module)) {
131
+        if (strpos($this->_URL, "$")!==FALSE) {
132
+            if (count($this->Options)>0 || !empty($this->Module)) {
133 133
                 $urlParts = explode("/", $this->_URL);
134 134
                 $o = 0;
135 135
                 foreach ($urlParts as $key => $part) {
136
-                    if (strpos($part, '$module') !== FALSE) {
136
+                    if (strpos($part, '$module')!==FALSE) {
137 137
                         if (isset($this->Module)) {
138 138
                             $urlParts[$key] = $this->Module;
139 139
                             continue;
140
-                        } else {
140
+                        }else {
141 141
                             if (isset($this->Options[$o])) {
142 142
                                 $this->Module = $this->Options[$o];
143 143
                                 array_shift($this->Options);
144 144
                             }
145 145
                         }
146 146
                     }
147
-                    if (strpos($part, "$") !== FALSE) {
147
+                    if (strpos($part, "$")!==FALSE) {
148 148
                         if (isset($this->Options[$o])) {
149 149
                             $urlParts[$key] = $this->Options[$o];
150 150
                             $o++;
151 151
                         }
152 152
                     }
153 153
                 }
154
-                $url = implode($urlParts,"/");
154
+                $url = implode($urlParts, "/");
155 155
             }
156 156
         }
157 157
         $this->url = $this->url.$url;
@@ -160,15 +160,15 @@  discard block
 block discarded – undo
160 160
     /**
161 161
      * Setup the Request Object property, setup on initial Construct of EntryPoint
162 162
      */
163
-    protected function setupRequest(){
163
+    protected function setupRequest() {
164 164
         $this->Request = new POST();
165 165
     }
166 166
 
167 167
     /**
168 168
      * Setup the Response Object Property, not called until after Request Execution
169 169
      */
170
-    protected function setupResponse(){
171
-        $this->Response = new JSONResponse($this->Request->getResponse(),$this->Request->getCurlObject());
170
+    protected function setupResponse() {
171
+        $this->Response = new JSONResponse($this->Request->getResponse(), $this->Request->getCurlObject());
172 172
     }
173 173
 
174 174
     /**
@@ -176,20 +176,20 @@  discard block
 block discarded – undo
176 176
      * @return bool
177 177
      * @throws EntryPointExecutionFailure
178 178
      */
179
-    protected function verifyURL(){
180
-        $urlVarCount = substr_count($this->_URL,"$");
179
+    protected function verifyURL() {
180
+        $urlVarCount = substr_count($this->_URL, "$");
181 181
         $optionCount = 0;
182
-        if (!empty($this->Module)){
182
+        if (!empty($this->Module)) {
183 183
             $optionCount++;
184 184
         }
185 185
         $optionCount += count($this->Options);
186
-        if ($urlVarCount!==$optionCount){
187
-            if (empty($this->Module) && strpos($this->_URL,'$module')){
186
+        if ($urlVarCount!==$optionCount) {
187
+            if (empty($this->Module) && strpos($this->_URL, '$module')) {
188 188
                 throw new EntryPointException('Module is required for EntryPoint '.get_called_class());
189
-            }else{
189
+            }else {
190 190
                 throw new EntryPointException('EntryPoint URL ('.$this->_URL.') requires more parameters than passed.');
191 191
             }
192
-        }else{
192
+        }else {
193 193
             return true;
194 194
         }
195 195
     }
@@ -197,21 +197,21 @@  discard block
 block discarded – undo
197 197
     /**
198 198
      * @return bool
199 199
      */
200
-    protected function validateData(){
201
-        if (empty($this->_REQUIRED_DATA)||count($this->_REQUIRED_DATA)==0){
200
+    protected function validateData() {
201
+        if (empty($this->_REQUIRED_DATA) || count($this->_REQUIRED_DATA)==0) {
202 202
             return true;
203
-        }else{
203
+        }else {
204 204
             $errors = array();
205
-            foreach($this->_REQUIRED_DATA as $property){
206
-                if (isset($this->Data[$property]) || $this->Data[$property]!==null){
205
+            foreach ($this->_REQUIRED_DATA as $property) {
206
+                if (isset($this->Data[$property]) || $this->Data[$property]!==null) {
207 207
                     continue;
208
-                }else{
208
+                }else {
209 209
                     $errors[] = $property;
210 210
                 }
211 211
             }
212
-            if (count($errors)>0){
213
-                throw new EntryPointException('EntryPoint requires specific properties in Request data. Missing the following '.implode($errors,","));
214
-            }else{
212
+            if (count($errors)>0) {
213
+                throw new EntryPointException('EntryPoint requires specific properties in Request data. Missing the following '.implode($errors, ","));
214
+            }else {
215 215
                 return true;
216 216
             }
217 217
         }
Please login to merge, or discard this patch.
src/EntryPoint/Abstracts/GET/FileEntryPoint.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,10 +14,10 @@
 block discarded – undo
14 14
         $this->Request = new GETFile();
15 15
     }
16 16
     protected function setupResponse() {
17
-        $this->Response = new FileResponse($this->Request->getResponse(),$this->Request->getCurlObject(),$this->downloadDir);
17
+        $this->Response = new FileResponse($this->Request->getResponse(), $this->Request->getCurlObject(), $this->downloadDir);
18 18
     }
19 19
 
20
-    public function downloadTo($path){
20
+    public function downloadTo($path) {
21 21
         $this->downloadDir = $path;
22 22
         return $this;
23 23
     }
Please login to merge, or discard this patch.
src/EntryPoint/POST/CreateRecord.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@
 block discarded – undo
4 4
 
5 5
 use SugarAPI\SDK\EntryPoint\Abstracts\POST\JSONEntryPoint as POSTEntryPoint;
6 6
 
7
-class CreateRecord extends POSTEntryPoint{
7
+class CreateRecord extends POSTEntryPoint {
8 8
 
9 9
     protected $_URL = '$module';
10 10
 
Please login to merge, or discard this patch.
src/Response/JSON.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
      * Get JSON Response
12 12
      */
13
-    public function json(){
13
+    public function json() {
14 14
         return $this->body;
15 15
     }
16 16
 
Please login to merge, or discard this patch.
src/Response/Abstracts/AbstractResponse.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 
5 5
 use SugarAPI\SDK\Response\Interfaces\ResponseInterface;
6 6
 
7
-abstract class AbstractResponse implements ResponseInterface{
7
+abstract class AbstractResponse implements ResponseInterface {
8 8
 
9 9
     protected $CurlResponse;
10 10
     protected $headers;
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
     protected $status;
13 13
     protected $error;
14 14
 
15
-    public function __construct($curlResponse,$curlRequest){
15
+    public function __construct($curlResponse, $curlRequest) {
16 16
         $this->CurlResponse = $curlResponse;
17 17
         if ($this->checkErrors($curlRequest)) {
18 18
             $this->extractResponse($curlRequest);
@@ -20,18 +20,18 @@  discard block
 block discarded – undo
20 20
         }
21 21
     }
22 22
 
23
-    protected function setStatus($curlRequest){
24
-        $this->status = curl_getinfo($curlRequest,CURLINFO_HTTP_CODE);
23
+    protected function setStatus($curlRequest) {
24
+        $this->status = curl_getinfo($curlRequest, CURLINFO_HTTP_CODE);
25 25
     }
26 26
 
27
-    protected function extractResponse($curlRequest){
28
-        $header_size = curl_getinfo($curlRequest,CURLINFO_HEADER_SIZE);
27
+    protected function extractResponse($curlRequest) {
28
+        $header_size = curl_getinfo($curlRequest, CURLINFO_HEADER_SIZE);
29 29
         $this->headers = substr($this->CurlResponse, 0, $header_size);
30 30
         $this->body = substr($this->CurlResponse, $header_size);
31 31
     }
32 32
 
33
-    protected function checkErrors($curlRequest){
34
-        if (curl_errno($curlRequest) !== CURLE_OK) {
33
+    protected function checkErrors($curlRequest) {
34
+        if (curl_errno($curlRequest)!==CURLE_OK) {
35 35
             $this->error = curl_error($curlRequest);
36 36
             return false;
37 37
         }
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
     /**
42 42
      * @inheritdoc
43 43
      */
44
-    public function getStatus(){
44
+    public function getStatus() {
45 45
         return $this->status;
46 46
     }
47 47
 
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
     /**
63 63
      * @inheritdoc
64 64
      */
65
-    public function getError(){
65
+    public function getError() {
66 66
         return $this->error;
67 67
     }
68 68
 
Please login to merge, or discard this patch.
src/Response/File.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
      */
18 18
     protected $destinationPath;
19 19
 
20
-    public function __construct($curlResponse, $curlRequest,$destination = null) {
20
+    public function __construct($curlResponse, $curlRequest, $destination = null) {
21 21
         parent::__construct($curlResponse, $curlRequest);
22 22
         $this->extractFileName();
23 23
         if (!empty($destination)) {
@@ -26,37 +26,37 @@  discard block
 block discarded – undo
26 26
         }
27 27
     }
28 28
 
29
-    protected function setupDestiantion($destination = null){
30
-        if (empty($destination)){
29
+    protected function setupDestiantion($destination = null) {
30
+        if (empty($destination)) {
31 31
             $destination = sys_get_temp_dir().'/SugarAPI';
32
-            if (!file_exists($destination)){
33
-                mkdir($destination,0777);
32
+            if (!file_exists($destination)) {
33
+                mkdir($destination, 0777);
34 34
             }
35 35
         }
36 36
         $this->destinationPath = $destination;
37 37
     }
38 38
 
39
-    protected function extractFileName(){
40
-        foreach (explode("\r\n",$this->headers) as $header)
39
+    protected function extractFileName() {
40
+        foreach (explode("\r\n", $this->headers) as $header)
41 41
         {
42
-            if (strpos($header,'filename')!==FALSE){
43
-                $this->fileName = substr($header,(strpos($header,"\"")+1),-1);
42
+            if (strpos($header, 'filename')!==FALSE) {
43
+                $this->fileName = substr($header, (strpos($header, "\"") + 1), -1);
44 44
             }
45 45
         }
46 46
     }
47 47
 
48
-    public function getFileName(){
48
+    public function getFileName() {
49 49
         return $this->fileName;
50 50
     }
51 51
 
52
-    protected function writeFile(){
53
-        $fileHandle = fopen($this->file(),'w+');
54
-        fwrite($fileHandle,$this->body);
52
+    protected function writeFile() {
53
+        $fileHandle = fopen($this->file(), 'w+');
54
+        fwrite($fileHandle, $this->body);
55 55
         fclose($fileHandle);
56 56
     }
57 57
 
58
-    public function file(){
59
-        return rtrim($this->destinationPath,DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$this->fileName;
58
+    public function file() {
59
+        return rtrim($this->destinationPath, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$this->fileName;
60 60
     }
61 61
 
62 62
 }
63 63
\ No newline at end of file
Please login to merge, or discard this patch.