Passed
Push — master ( c82035...9f9933 )
by Fran
02:32
created
src/base/types/Api.php 1 patch
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -81,20 +81,20 @@  discard block
 block discarded – undo
81 81
     public function init()
82 82
     {
83 83
         parent::init();
84
-        Logger::log(static::class . ' init', LOG_DEBUG);
84
+        Logger::log(static::class.' init', LOG_DEBUG);
85 85
         $this->domain = $this->getDomain();
86 86
         $this->hydrateRequestData();
87 87
         $this->hydrateOrders();
88
-        if($this instanceof CustomApi === false) {
88
+        if ($this instanceof CustomApi === false) {
89 89
             $this->createConnection($this->getTableMap());
90 90
         }
91 91
         $this->checkFieldType();
92 92
         $this->setLoaded(true);
93
-        Logger::log(static::class . ' loaded', LOG_DEBUG);
93
+        Logger::log(static::class.' loaded', LOG_DEBUG);
94 94
     }
95 95
 
96 96
     private function checkActions($method) {
97
-        switch($method) {
97
+        switch ($method) {
98 98
             default:
99 99
             case 'modelList': $this->action = self::API_ACTION_LIST; break;
100 100
             case 'get': $this->action = self::API_ACTION_GET; break;
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
     protected function hydrateOrders()
112 112
     {
113 113
         if (count($this->query)) {
114
-            Logger::log(static::class . ' gathering query string', LOG_DEBUG);
114
+            Logger::log(static::class.' gathering query string', LOG_DEBUG);
115 115
             foreach ($this->query as $key => $value) {
116 116
                 if ($key === self::API_ORDER_FIELD) {
117 117
                     $orders = json_decode($value, true);
@@ -129,10 +129,10 @@  discard block
 block discarded – undo
129 129
      */
130 130
     protected function extractPagination()
131 131
     {
132
-        Logger::log(static::class . ' extract pagination start', LOG_DEBUG);
132
+        Logger::log(static::class.' extract pagination start', LOG_DEBUG);
133 133
         $page = array_key_exists(self::API_PAGE_FIELD, $this->query) ? $this->query[self::API_PAGE_FIELD] : 1;
134 134
         $limit = array_key_exists(self::API_LIMIT_FIELD, $this->query) ? $this->query[self::API_LIMIT_FIELD] : 100;
135
-        Logger::log(static::class . ' extract pagination end', LOG_DEBUG);
135
+        Logger::log(static::class.' extract pagination end', LOG_DEBUG);
136 136
         return array($page, (int)$limit);
137 137
     }
138 138
 
@@ -141,9 +141,9 @@  discard block
 block discarded – undo
141 141
      * @param ModelCriteria $query
142 142
      * @throws \PSFS\base\exception\ApiException
143 143
      */
144
-    private function addOrders(ModelCriteria &$query)
144
+    private function addOrders(ModelCriteria & $query)
145 145
     {
146
-        Logger::log(static::class . ' extract orders start ', LOG_DEBUG);
146
+        Logger::log(static::class.' extract orders start ', LOG_DEBUG);
147 147
         $orderAdded = FALSE;
148 148
         $tableMap = $this->getTableMap();
149 149
         foreach ($this->order->getOrders() as $field => $direction) {
@@ -151,18 +151,18 @@  discard block
 block discarded – undo
151 151
                 $orderAdded = TRUE;
152 152
                 if ($direction === Order::ASC) {
153 153
                     $query->addAscendingOrderByColumn($column->getPhpName());
154
-                } else {
154
+                }else {
155 155
                     $query->addDescendingOrderByColumn($column->getPhpName());
156 156
                 }
157 157
             }
158 158
         }
159 159
         if (!$orderAdded) {
160 160
             $pks = $this->getPkDbName();
161
-            foreach(array_keys($pks) as $key) {
161
+            foreach (array_keys($pks) as $key) {
162 162
                 $query->addAscendingOrderByColumn($key);
163 163
             }
164 164
         }
165
-        Logger::log(static::class . ' extract orders end', LOG_DEBUG);
165
+        Logger::log(static::class.' extract orders end', LOG_DEBUG);
166 166
     }
167 167
 
168 168
     /**
@@ -170,14 +170,14 @@  discard block
 block discarded – undo
170 170
      *
171 171
      * @param ModelCriteria $query
172 172
      */
173
-    protected function addFilters(ModelCriteria &$query)
173
+    protected function addFilters(ModelCriteria & $query)
174 174
     {
175 175
         if (count($this->query) > 0) {
176 176
             $tableMap = $this->getTableMap();
177 177
             foreach ($this->query as $field => $value) {
178 178
                 if (self::API_COMBO_FIELD === $field) {
179 179
                     ApiHelper::composerComboField($tableMap, $query, $this->extraColumns, $value);
180
-                } elseif(!preg_match('/^__/', $field)) {
180
+                } elseif (!preg_match('/^__/', $field)) {
181 181
                     ApiHelper::addModelField($tableMap, $query, $field, $value);
182 182
                 }
183 183
             }
@@ -198,10 +198,10 @@  discard block
 block discarded – undo
198 198
             list($page, $limit) = $this->extractPagination();
199 199
             if ($limit === -1) {
200 200
                 $this->list = $query->find($this->con);
201
-            } else {
201
+            }else {
202 202
                 $this->list = $query->paginate($page, $limit, $this->con);
203 203
             }
204
-        } catch (\Exception $e) {
204
+        }catch (\Exception $e) {
205 205
             Logger::log($e->getMessage(), LOG_ERR);
206 206
         }
207 207
     }
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
         $code = 200;
221 221
         list($return, $total, $pages) = $this->getList();
222 222
         $message = null;
223
-        if(!$total) {
223
+        if (!$total) {
224 224
             $message = t('No se han encontrado elementos para la búsqueda');
225 225
         }
226 226
 
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
         $pages = 1;
247 247
         $message = null;
248 248
         list($code, $return) = $this->getSingleResult($pk);
249
-        if($code !== 200) {
249
+        if ($code !== 200) {
250 250
             $message = t('No se ha encontrado el elemento solicitado');
251 251
         }
252 252
 
@@ -275,13 +275,13 @@  discard block
 block discarded – undo
275 275
                 $status = 200;
276 276
                 $saved = TRUE;
277 277
                 $model = $this->model->toArray($this->fieldType ?: TableMap::TYPE_PHPNAME, true, [], true);
278
-            } else {
278
+            }else {
279 279
                 $message = t('No se ha podido guardar el modelo seleccionado');
280 280
             }
281
-        } catch (\Exception $e) {
282
-            $message = t('Ha ocurrido un error intentando guardar el elemento: ') .'<br>'. $e->getMessage();
281
+        }catch (\Exception $e) {
282
+            $message = t('Ha ocurrido un error intentando guardar el elemento: ').'<br>'.$e->getMessage();
283 283
             $context = [];
284
-            if(null !== $e->getPrevious()) {
284
+            if (null !== $e->getPrevious()) {
285 285
                 $context[] = $e->getPrevious()->getMessage();
286 286
             }
287 287
             Logger::log($e->getMessage(), LOG_CRIT, $context);
@@ -317,18 +317,18 @@  discard block
 block discarded – undo
317 317
                     $updated = TRUE;
318 318
                     $status = 200;
319 319
                     $model = $this->model->toArray($this->fieldType ?: TableMap::TYPE_PHPNAME, true, [], true);
320
-                } else {
320
+                }else {
321 321
                     $message = t('Ha ocurrido un error intentando actualizar el elemento, por favor revisa los logs');
322 322
                 }
323
-            } catch (\Exception $e) {
323
+            }catch (\Exception $e) {
324 324
                 $message = t('Ha ocurrido un error intentando actualizar el elemento, por favor revisa los logs');
325 325
                 $context = [];
326
-                if(null !== $e->getPrevious()) {
326
+                if (null !== $e->getPrevious()) {
327 327
                     $context[] = $e->getPrevious()->getMessage();
328 328
                 }
329 329
                 Logger::log($e->getMessage(), LOG_CRIT, $context);
330 330
             }
331
-        } else {
331
+        }else {
332 332
             $message = t('No se ha encontrado el modelo al que se hace referencia para actualizar');
333 333
         }
334 334
 
@@ -356,15 +356,15 @@  discard block
 block discarded – undo
356 356
                 $this->con->beginTransaction();
357 357
                 $this->hydrateModel($pk);
358 358
                 if (NULL !== $this->model) {
359
-                    if(method_exists('clearAllReferences', $this->model)) {
359
+                    if (method_exists('clearAllReferences', $this->model)) {
360 360
                         $this->model->clearAllReferences(true);
361 361
                     }
362 362
                     $this->model->delete($this->con);
363 363
                     $deleted = TRUE;
364 364
                 }
365
-            } catch (\Exception $e) {
365
+            }catch (\Exception $e) {
366 366
                 $context = [];
367
-                if(null !== $e->getPrevious()) {
367
+                if (null !== $e->getPrevious()) {
368 368
                     $context[] = $e->getPrevious()->getMessage();
369 369
                 }
370 370
                 Logger::log($e->getMessage(), LOG_CRIT, $context);
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
             $this->saveBulk();
394 394
             $saved = true;
395 395
             $status = 200;
396
-        } catch(\Exception $e) {
396
+        }catch (\Exception $e) {
397 397
             Logger::log($e->getMessage(), LOG_CRIT, $this->getRequest()->getData());
398 398
             $message = t('Bulk insert rolled back');
399 399
         }
@@ -415,7 +415,7 @@  discard block
 block discarded – undo
415 415
 
416 416
         /** @var CustomerTableMap $tableMap */
417 417
         $modelPk = ApiHelper::extractPrimaryKeyColumnName($this->getTableMap());
418
-        foreach($this->list->getData() as $data) {
418
+        foreach ($this->list->getData() as $data) {
419 419
             $return[] = ApiHelper::mapArrayObject($this->getModelNamespace(), $modelPk, $this->query, $data);
420 420
         }
421 421
         return $return;
@@ -432,23 +432,23 @@  discard block
 block discarded – undo
432 432
         try {
433 433
             $this->paginate();
434 434
             if (null !== $this->list) {
435
-                if(array_key_exists(self::API_FIELDS_RESULT_FIELD, $this->query) && Config::getParam('api.field.types')) {
435
+                if (array_key_exists(self::API_FIELDS_RESULT_FIELD, $this->query) && Config::getParam('api.field.types')) {
436 436
                     $return = $this->extractDataWithFormat();
437
-                } else {
437
+                }else {
438 438
                     $return = $this->list->toArray(null, false, $this->fieldType ?: TableMap::TYPE_PHPNAME, false);
439 439
                 }
440 440
                 $total = 0;
441 441
                 $pages = 0;
442
-                if($this->list instanceof PropelModelPager) {
442
+                if ($this->list instanceof PropelModelPager) {
443 443
                     $total = $this->list->getNbResults();
444 444
                     $pages = $this->list->getLastPage();
445
-                } elseif($this->list instanceof ArrayCollection) {
445
+                } elseif ($this->list instanceof ArrayCollection) {
446 446
                     $total = count($return);
447 447
                     $pages = 1;
448 448
                 }
449 449
             }
450
-        } catch (\Exception $e) {
451
-            Logger::log(get_class($this) . ': ' . $e->getMessage(), LOG_ERR);
450
+        }catch (\Exception $e) {
451
+            Logger::log(get_class($this).': '.$e->getMessage(), LOG_ERR);
452 452
         }
453 453
 
454 454
         return array($return, $total, $pages);
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
         $return = array();
467 467
         if (NULL === $model || !method_exists($model, 'toArray')) {
468 468
             $code = 404;
469
-        } else {
469
+        }else {
470 470
             $return = $model->toArray($this->fieldType ?: TableMap::TYPE_PHPNAME, true, [], true);
471 471
         }
472 472
 
Please login to merge, or discard this patch.