Passed
Push — master ( 1e73e2...d42f9e )
by Fran
03:19
created
src/base/types/Api.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -80,15 +80,15 @@  discard block
 block discarded – undo
80 80
     public function init()
81 81
     {
82 82
         parent::init();
83
-        Logger::log(get_called_class() . ' init', LOG_DEBUG);
83
+        Logger::log(get_called_class().' init', LOG_DEBUG);
84 84
         $this->domain = $this->getDomain();
85 85
         $this->hydrateRequestData();
86 86
         $this->hydrateOrders();
87
-        if($this instanceof CustomApi === false) {
87
+        if ($this instanceof CustomApi === false) {
88 88
             $this->createConnection($this->getTableMap());
89 89
         }
90 90
         $this->setLoaded(true);
91
-        Logger::log(get_called_class() . ' loaded', LOG_DEBUG);
91
+        Logger::log(get_called_class().' loaded', LOG_DEBUG);
92 92
     }
93 93
 
94 94
     /**
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
     protected function hydrateOrders()
98 98
     {
99 99
         if (count($this->query)) {
100
-            Logger::log(get_called_class() . ' gathering query string', LOG_DEBUG);
100
+            Logger::log(get_called_class().' gathering query string', LOG_DEBUG);
101 101
             foreach ($this->query as $key => $value) {
102 102
                 if ($key === self::API_ORDER_FIELD && is_array($value)) {
103 103
                     foreach ($value as $field => $direction) {
@@ -114,10 +114,10 @@  discard block
 block discarded – undo
114 114
      */
115 115
     protected function extractPagination()
116 116
     {
117
-        Logger::log(get_called_class() . ' extract pagination start', LOG_DEBUG);
117
+        Logger::log(get_called_class().' extract pagination start', LOG_DEBUG);
118 118
         $page = (array_key_exists(self::API_PAGE_FIELD, $this->query)) ? $this->query[self::API_PAGE_FIELD] : 1;
119 119
         $limit = (array_key_exists(self::API_LIMIT_FIELD, $this->query)) ? $this->query[self::API_LIMIT_FIELD] : 100;
120
-        Logger::log(get_called_class() . ' extract pagination end', LOG_DEBUG);
120
+        Logger::log(get_called_class().' extract pagination end', LOG_DEBUG);
121 121
         return array($page, $limit);
122 122
     }
123 123
 
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
      *
127 127
      * @param ModelCriteria $query
128 128
      */
129
-    private function addOrders(ModelCriteria &$query)
129
+    private function addOrders(ModelCriteria & $query)
130 130
     {
131
-        Logger::log(get_called_class() . ' extract orders start ', LOG_DEBUG);
131
+        Logger::log(get_called_class().' extract orders start ', LOG_DEBUG);
132 132
         $orderAdded = FALSE;
133 133
         $tableMap = $this->getTableMap();
134 134
         foreach ($this->order->getOrders() as $field => $direction) {
@@ -136,17 +136,17 @@  discard block
 block discarded – undo
136 136
                 $orderAdded = TRUE;
137 137
                 if ($direction === Order::ASC) {
138 138
                     $query->addAscendingOrderByColumn($column->getPhpName());
139
-                } else {
139
+                }else {
140 140
                     $query->addDescendingOrderByColumn($column->getPhpName());
141 141
                 }
142 142
             }
143 143
         }
144 144
         if (!$orderAdded) {
145
-            foreach($this->getPkDbName() as $pk => $phpName) {
145
+            foreach ($this->getPkDbName() as $pk => $phpName) {
146 146
                 $query->addAscendingOrderByColumn($pk);
147 147
             }
148 148
         }
149
-        Logger::log(get_called_class() . ' extract orders end', LOG_DEBUG);
149
+        Logger::log(get_called_class().' extract orders end', LOG_DEBUG);
150 150
     }
151 151
 
152 152
     /**
@@ -154,14 +154,14 @@  discard block
 block discarded – undo
154 154
      *
155 155
      * @param ModelCriteria $query
156 156
      */
157
-    protected function addFilters(ModelCriteria &$query)
157
+    protected function addFilters(ModelCriteria & $query)
158 158
     {
159 159
         if (count($this->query) > 0) {
160 160
             $tableMap = $this->getTableMap();
161 161
             foreach ($this->query as $field => $value) {
162 162
                 if (self::API_COMBO_FIELD === $field) {
163 163
                     ApiHelper::composerComboField($tableMap, $query, $this->extraColumns, $value);
164
-                } elseif(!preg_match('/^__/', $field)) {
164
+                } elseif (!preg_match('/^__/', $field)) {
165 165
                     ApiHelper::addModelField($tableMap, $query, $field, $value);
166 166
                 }
167 167
             }
@@ -182,10 +182,10 @@  discard block
 block discarded – undo
182 182
             list($page, $limit) = $this->extractPagination();
183 183
             if ($limit == -1) {
184 184
                 $this->list = $query->find($this->con);
185
-            } else {
185
+            }else {
186 186
                 $this->list = $query->paginate($page, $limit, $this->con);
187 187
             }
188
-        } catch (\Exception $e) {
188
+        }catch (\Exception $e) {
189 189
             Logger::log($e->getMessage(), LOG_ERR);
190 190
         }
191 191
     }
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
         $code = 200;
205 205
         list($return, $total, $pages) = $this->getList();
206 206
         $message = null;
207
-        if(!$total) {
207
+        if (!$total) {
208 208
             $message = _('No se han encontrado elementos para la búsqueda');
209 209
         }
210 210
 
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
         $pages = 1;
231 231
         $message = null;
232 232
         list($code, $return) = $this->getSingleResult($pk);
233
-        if($code !== 200) {
233
+        if ($code !== 200) {
234 234
             $message = _('No se ha encontrado el elemento solicitado');
235 235
         }
236 236
 
@@ -259,11 +259,11 @@  discard block
 block discarded – undo
259 259
                 $status = 200;
260 260
                 $saved = TRUE;
261 261
                 $model = $this->model->toArray();
262
-            } else {
262
+            }else {
263 263
                 $message = _('No se ha podido guardar el modelo seleccionado');
264 264
             }
265
-        } catch (\Exception $e) {
266
-            $message = _('Ha ocurrido un error intentando guardar el elemento: ') .'<br>'. $e->getMessage();
265
+        }catch (\Exception $e) {
266
+            $message = _('Ha ocurrido un error intentando guardar el elemento: ').'<br>'.$e->getMessage();
267 267
             Logger::log($e->getMessage(), LOG_ERR);
268 268
         }
269 269
 
@@ -297,14 +297,14 @@  discard block
 block discarded – undo
297 297
                     $updated = TRUE;
298 298
                     $status = 200;
299 299
                     $model = $this->model->toArray();
300
-                } else {
300
+                }else {
301 301
                     $message = _('Ha ocurrido un error intentando actualizar el elemento, por favor revisa los logs');
302 302
                 }
303
-            } catch (\Exception $e) {
303
+            }catch (\Exception $e) {
304 304
                 $message = $e->getMessage();
305 305
                 Logger::getInstance(get_class($this->model))->errorLog($e->getMessage());
306 306
             }
307
-        } else {
307
+        }else {
308 308
             $message = _('No se ha encontrado el modelo al que se hace referencia para actualizar');
309 309
         }
310 310
 
@@ -332,13 +332,13 @@  discard block
 block discarded – undo
332 332
                 $this->con->beginTransaction();
333 333
                 $this->hydrateModel($pk);
334 334
                 if (NULL !== $this->model) {
335
-                    if(method_exists('clearAllReferences', $this->model)) {
335
+                    if (method_exists('clearAllReferences', $this->model)) {
336 336
                         $this->model->clearAllReferences(true);
337 337
                     }
338 338
                     $this->model->delete($this->con);
339 339
                     $deleted = TRUE;
340 340
                 }
341
-            } catch (\Exception $e) {
341
+            }catch (\Exception $e) {
342 342
                 $message = _('Ha ocurrido un error intentando eliminar el elemento, por favor verifica que no tenga otros elementos relacionados');
343 343
                 Logger::getInstance(get_class($this->model))->errorLog($e->getMessage());
344 344
             }
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
             $this->saveBulk();
367 367
             $saved = true;
368 368
             $status = 200;
369
-        } catch(\Exception $e) {
369
+        }catch (\Exception $e) {
370 370
             Logger::log($e->getMessage(), LOG_ERR, $this->getRequest()->getData());
371 371
             $message = _('Bulk insert rolled back');
372 372
         }
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
 
389 389
         /** @var CustomerTableMap $tableMap */
390 390
         $modelPk = ApiHelper::extractPrimaryKeyColumnName($this->getTableMap());
391
-        foreach($this->list->getData() as $data) {
391
+        foreach ($this->list->getData() as $data) {
392 392
             $return[] = ApiHelper::mapArrayObject($this->getModelNamespace(), $modelPk, $this->query, $data);
393 393
         }
394 394
         return $return;
@@ -405,20 +405,20 @@  discard block
 block discarded – undo
405 405
         try {
406 406
             $this->paginate();
407 407
             if (null !== $this->list) {
408
-                if(array_key_exists(self::API_FIELDS_RESULT_FIELD, $this->query) && Config::getParam('api.field.types')) {
408
+                if (array_key_exists(self::API_FIELDS_RESULT_FIELD, $this->query) && Config::getParam('api.field.types')) {
409 409
                     $return = $this->extractDataWithFormat();
410
-                } else {
410
+                }else {
411 411
                     $return = $this->list->toArray(null, false, TableMap::TYPE_PHPNAME, false);
412 412
                 }
413 413
                 $total = 0;
414 414
                 $pages = 0;
415
-                if(null !== $this->list) {
415
+                if (null !== $this->list) {
416 416
                     $total = $this->list->getNbResults();
417 417
                     $pages = $this->list->getLastPage();
418 418
                 }
419 419
             }
420
-        } catch (\Exception $e) {
421
-            Logger::log(get_class($this) . ': ' . $e->getMessage(), LOG_ERR);
420
+        }catch (\Exception $e) {
421
+            Logger::log(get_class($this).': '.$e->getMessage(), LOG_ERR);
422 422
         }
423 423
 
424 424
         return array($return, $total, $pages);
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
         $return = array();
437 437
         if (NULL === $model || !method_exists($model, 'toArray')) {
438 438
             $code = 404;
439
-        } else {
439
+        }else {
440 440
             $return = $model->toArray();
441 441
         }
442 442
 
Please login to merge, or discard this patch.