Completed
Push — master ( e6cd79...15515b )
by Mike
02:12
created
src/Request/Abstracts/AbstractRequest.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 
5 5
 use SugarAPI\SDK\Request\Interfaces\RequestInterface;
6 6
 
7
-abstract class AbstractRequest implements RequestInterface{
7
+abstract class AbstractRequest implements RequestInterface {
8 8
 
9 9
     /**
10 10
      * The HTTP Request Type
@@ -67,14 +67,14 @@  discard block
 block discarded – undo
67 67
      */
68 68
     protected $type;
69 69
 
70
-    public function __construct($url = null){
70
+    public function __construct($url = null) {
71 71
         $this->start();
72
-        if (!empty($url)){
72
+        if (!empty($url)) {
73 73
             $this->setURL($url);
74 74
         }
75 75
         $this->setType();
76
-        foreach(static::$_DEFAULT_OPTIONS as $option => $value){
77
-            $this->setOption($option,$value);
76
+        foreach (static::$_DEFAULT_OPTIONS as $option => $value) {
77
+            $this->setOption($option, $value);
78 78
         }
79 79
     }
80 80
 
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
      */
84 84
     public function setURL($url) {
85 85
         $this->url = $url;
86
-        $this->setOption(CURLOPT_URL,$this->url);
86
+        $this->setOption(CURLOPT_URL, $this->url);
87 87
         return $this;
88 88
     }
89 89
 
@@ -165,22 +165,22 @@  discard block
 block discarded – undo
165 165
     /**
166 166
      * @inheritdoc
167 167
      */
168
-    public function getResponse(){
168
+    public function getResponse() {
169 169
        return $this->CurlResponse;
170 170
     }
171 171
 
172 172
     /**
173 173
      * Set the Type on the Request
174 174
      */
175
-    protected function setType(){
175
+    protected function setType() {
176 176
         $this->type = static::$_TYPE;
177 177
     }
178 178
 
179 179
     /**
180 180
      * @inheritdoc
181 181
      */
182
-    public function reset(){
183
-        if (is_object($this->CurlRequest)){
182
+    public function reset() {
183
+        if (is_object($this->CurlRequest)) {
184 184
             $this->close();
185 185
         }
186 186
         $this->start();
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
     /**
199 199
      * @inheritdoc
200 200
      */
201
-    public function close(){
201
+    public function close() {
202 202
         curl_close($this->CurlRequest);
203 203
         unset($this->CurlRequest);
204 204
         return $this;
Please login to merge, or discard this patch.
src/Request/POST.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 
5 5
 use SugarAPI\SDK\Request\Abstracts\AbstractRequest;
6 6
 
7
-class POST extends AbstractRequest{
7
+class POST extends AbstractRequest {
8 8
 
9 9
     protected static $_TYPE = 'POST';
10 10
 
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
      *
14 14
      * Set the Curl POST Option to True
15 15
      */
16
-    protected function setType(){
16
+    protected function setType() {
17 17
         parent::setType();
18 18
         $this->setOption(CURLOPT_POST, 1);
19 19
     }
Please login to merge, or discard this patch.
src/Request/DELETE.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 
5 5
 use SugarAPI\SDK\Request\Abstracts\AbstractRequest;
6 6
 
7
-class DELETE extends AbstractRequest{
7
+class DELETE extends AbstractRequest {
8 8
 
9 9
     protected static $_TYPE = 'DELETE';
10 10
 
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
      *
14 14
      * Set the Curl Custom Request Option to DELETE
15 15
      */
16
-    protected function setType(){
16
+    protected function setType() {
17 17
         parent::setType();
18 18
         $this->setOption(CURLOPT_CUSTOMREQUEST, "DELETE");
19 19
     }
Please login to merge, or discard this patch.
src/Request/PUT.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 
5 5
 use SugarAPI\SDK\Request\Abstracts\AbstractRequest;
6 6
 
7
-class PUT extends AbstractRequest{
7
+class PUT extends AbstractRequest {
8 8
 
9 9
     protected static $_TYPE = 'PUT';
10 10
 
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
      *
14 14
      * Set the Curl Custom Request Option to PUT
15 15
      */
16
-    protected function setType(){
16
+    protected function setType() {
17 17
         parent::setType();
18 18
         $this->setOption(CURLOPT_CUSTOMREQUEST, "PUT");
19 19
     }
Please login to merge, or discard this patch.
src/Request/Interfaces/RequestInterface.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
      * @param $value - Header Value
24 24
      * @return SugarAPI\SDK\Request Object
25 25
      */
26
-    public function addHeader($name,$value);
26
+    public function addHeader($name, $value);
27 27
 
28 28
     /**
29 29
      * Sets the Headers on the Curl Request object, called during Sending. Appends to Request Headers property
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
      * @param $value - Curl Option Value
51 51
      * @return SugarAPI\SDK\Request Object
52 52
      */
53
-    public function setOption($option,$value);
53
+    public function setOption($option, $value);
54 54
 
55 55
     /**
56 56
      * Set the URL on the Request Object
Please login to merge, or discard this patch.
examples/Login.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@
 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
-$SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Ent/7621/',array('username' => 'admin','password'=>'asdf'));
5
+$SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Ent/7621/', array('username' => 'admin', 'password'=>'asdf'));
6 6
 $SugarAPI->login();
7 7
 print_r($SugarAPI->getToken());
8 8
\ No newline at end of file
Please login to merge, or discard this patch.
src/SugarAPI.php 1 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.
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/PUT/JSONEntryPoint.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@
 block discarded – undo
9 9
     /**
10 10
      * @inheritdoc
11 11
      */
12
-    protected function setupRequest(){
12
+    protected function setupRequest() {
13 13
         $this->Request = new GET();
14 14
     }
15 15
 
Please login to merge, or discard this patch.