Passed
Push — main ( 7ac621...ceb98d )
by Dylan
02:22
created
src/models/Model.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -35,19 +35,19 @@  discard block
 block discarded – undo
35 35
                     // Model or Object
36 36
                     if (!array_key_exists('field_name', $value)) {
37 37
                         $this->$field = ObjectFactory::make($client, $value);
38
-                    } else {
38
+                    }else {
39 39
                         // Has One Relation - Deprecated
40 40
                         $name = $value['field_name'];
41 41
                         $this->$name    = $value['field_value'];
42 42
                         $this->$field   = ObjectFactory::make($client, $value['object_data']);
43 43
                     }
44
-                } else {
44
+                }else {
45 45
                     // HasMany / ManyMany Relation
46 46
                     $list = [];
47 47
                     foreach ($value as $item) {
48 48
                         if (ArrayLib::is_associative($item)) {
49 49
                             $list[] = ObjectFactory::make($client, $item);
50
-                        } else {
50
+                        }else {
51 51
                             $list[] = $item;
52 52
                         }
53 53
                     }
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
                 $data[$key] = [];
75 75
                 /** @var self $item */
76 76
                 foreach ($value as $item) $data[$key][] = $item->toArray(true);
77
-            } else $data[$key] = $value;
77
+            }else $data[$key] = $value;
78 78
         }
79 79
 
80 80
         return $data;
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
             if ($model === static::class) return new $service($this->getClient());
99 99
         }
100 100
 
101
-        throw new ErrorException("Could not determine which service to use for " . static::class);
101
+        throw new ErrorException("Could not determine which service to use for ".static::class);
102 102
     }
103 103
 
104 104
     /**
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
         if ($this->exists()) {
113 113
             if (!method_exists($service, 'update')) return $this;
114 114
             return $service->update($this->ID, $this->toArray());
115
-        } else {
115
+        }else {
116 116
             if (!method_exists($service, 'create')) return $this;
117 117
             return $service->create($this->toArray());
118 118
         }
Please login to merge, or discard this patch.
Braces   +21 added lines, -8 removed lines patch added patch discarded remove patch
@@ -64,17 +64,24 @@  discard block
 block discarded – undo
64 64
      */
65 65
     public function toArray(bool $flatten = false): array
66 66
     {
67
-        if (!$flatten) return iterator_to_array($this->getIterator());
67
+        if (!$flatten) {
68
+            return iterator_to_array($this->getIterator());
69
+        }
68 70
 
69 71
         $data = [];
70 72
 
71 73
         foreach ($this->getIterator() as $key => $value) {
72
-            if ($value instanceof self)         $data[$key] = $value->toArray(true);
73
-            else if ($value instanceof ListResource) {
74
+            if ($value instanceof self) {
75
+                $data[$key] = $value->toArray(true);
76
+            } else if ($value instanceof ListResource) {
74 77
                 $data[$key] = [];
75 78
                 /** @var self $item */
76
-                foreach ($value as $item) $data[$key][] = $item->toArray(true);
77
-            } else $data[$key] = $value;
79
+                foreach ($value as $item) {
80
+                    $data[$key][] = $item->toArray(true);
81
+                }
82
+            } else {
83
+                $data[$key] = $value;
84
+            }
78 85
         }
79 86
 
80 87
         return $data;
@@ -95,7 +102,9 @@  discard block
 block discarded – undo
95 102
     public function getService(): ApiService
96 103
     {
97 104
         foreach (ClassMap::SERVICE_MODEL as $service => $model) {
98
-            if ($model === static::class) return new $service($this->getClient());
105
+            if ($model === static::class) {
106
+                return new $service($this->getClient());
107
+            }
99 108
         }
100 109
 
101 110
         throw new ErrorException("Could not determine which service to use for " . static::class);
@@ -110,10 +119,14 @@  discard block
 block discarded – undo
110 119
         $service = $this->getService();
111 120
 
112 121
         if ($this->exists()) {
113
-            if (!method_exists($service, 'update')) return $this;
122
+            if (!method_exists($service, 'update')) {
123
+                return $this;
124
+            }
114 125
             return $service->update($this->ID, $this->toArray());
115 126
         } else {
116
-            if (!method_exists($service, 'create')) return $this;
127
+            if (!method_exists($service, 'create')) {
128
+                return $this;
129
+            }
117 130
             return $service->create($this->toArray());
118 131
         }
119 132
     }
Please login to merge, or discard this patch.
src/utils/Curl.php 1 patch
Braces   +27 added lines, -9 removed lines patch added patch discarded remove patch
@@ -39,8 +39,12 @@  discard block
 block discarded – undo
39 39
     public function __construct(string $url, array $data = [], array $headers = [])
40 40
     {
41 41
         $this->setURL($url);
42
-        foreach ($data as $name => $value)      $this->addDataParam($name, $value);
43
-        foreach ($headers as $name => $value)   $this->addHeader($name, $value);
42
+        foreach ($data as $name => $value) {
43
+            $this->addDataParam($name, $value);
44
+        }
45
+        foreach ($headers as $name => $value) {
46
+            $this->addHeader($name, $value);
47
+        }
44 48
     }
45 49
 
46 50
     /**
@@ -99,7 +103,9 @@  discard block
 block discarded – undo
99 103
 
100 104
     public function removeDataParam(string $name): Curl
101 105
     {
102
-        if (array_key_exists($name, $this->_data)) unset($this->_data[$name]);
106
+        if (array_key_exists($name, $this->_data)) {
107
+            unset($this->_data[$name]);
108
+        }
103 109
         return $this;
104 110
     }
105 111
 
@@ -128,7 +134,9 @@  discard block
 block discarded – undo
128 134
      */
129 135
     public function removeHeader(string $name): Curl
130 136
     {
131
-        if (array_key_exists($name, $this->_headers)) unset($this->_headers[$name]);
137
+        if (array_key_exists($name, $this->_headers)) {
138
+            unset($this->_headers[$name]);
139
+        }
132 140
         return $this;
133 141
     }
134 142
 
@@ -173,13 +181,17 @@  discard block
 block discarded – undo
173 181
         $request_uri    = $this->getURL();
174 182
 
175 183
         //  Headers
176
-        foreach ($this->getHeaders() as $k => $v) $send_headers[] = "{$k}: {$v}";
184
+        foreach ($this->getHeaders() as $k => $v) {
185
+            $send_headers[] = "{$k}: {$v}";
186
+        }
177 187
 
178 188
         // Request Data
179 189
         switch ($this->getMethod()) {
180 190
             case 'GET':
181 191
             case 'DELETE':
182
-                foreach ($this->getDataParams() as $name => $value) $request_uri = URL::setGetVar($name, $value, $request_uri);
192
+                foreach ($this->getDataParams() as $name => $value) {
193
+                    $request_uri = URL::setGetVar($name, $value, $request_uri);
194
+                }
183 195
                 break;
184 196
 
185 197
             case 'POST':
@@ -210,7 +222,9 @@  discard block
 block discarded – undo
210 222
         curl_setopt($ch, CURLINFO_HEADER_OUT, true);
211 223
         curl_setopt($ch, CURLOPT_AUTOREFERER, true);
212 224
 
213
-        if (!empty($send_headers))  curl_setopt($ch, CURLOPT_HTTPHEADER, $send_headers);
225
+        if (!empty($send_headers)) {
226
+            curl_setopt($ch, CURLOPT_HTTPHEADER, $send_headers);
227
+        }
214 228
         if (!is_null($post_data))   {
215 229
             curl_setopt($ch, CURLOPT_POST, 1);
216 230
             curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
@@ -219,10 +233,14 @@  discard block
 block discarded – undo
219 233
         $result     = curl_exec($ch);
220 234
         $http_code  = curl_getinfo($ch, CURLINFO_HTTP_CODE);
221 235
 
222
-        if ($http_code === 401 && $retry_on_401) return $this->curl(false);
236
+        if ($http_code === 401 && $retry_on_401) {
237
+            return $this->curl(false);
238
+        }
223 239
 
224 240
         $response = new CurlResponse((int) $http_code, (string) $result);
225
-        if ($this->_enable_cache && isset($cache_key)) self::$_cache[$cache_key] = $response;
241
+        if ($this->_enable_cache && isset($cache_key)) {
242
+            self::$_cache[$cache_key] = $response;
243
+        }
226 244
 
227 245
         return $response;
228 246
     }
Please login to merge, or discard this patch.