Passed
Push — master ( f02e32...416db0 )
by Fran
03:19
created
src/base/types/Api.php 2 patches
Unused Use Statements   -4 removed lines patch added patch discarded remove patch
@@ -4,10 +4,8 @@  discard block
 block discarded – undo
4 4
 use CORE\Models\Customer;
5 5
 use CORE\Models\Map\CustomerTableMap;
6 6
 use Propel\Runtime\ActiveQuery\ModelCriteria;
7
-use Propel\Runtime\ActiveRecord\ActiveRecordInterface;
8 7
 use Propel\Runtime\DataFetcher\ArrayDataFetcher;
9 8
 use Propel\Runtime\Formatter\ObjectFormatter;
10
-use Propel\Runtime\Map\ColumnMap;
11 9
 use Propel\Runtime\Map\TableMap;
12 10
 use Propel\Runtime\Propel;
13 11
 use PSFS\base\config\Config;
@@ -15,10 +13,8 @@  discard block
 block discarded – undo
15 13
 use PSFS\base\dto\Order;
16 14
 use PSFS\base\Logger;
17 15
 use PSFS\base\Request;
18
-use PSFS\base\Security;
19 16
 use PSFS\base\Singleton;
20 17
 use PSFS\base\types\helpers\ApiHelper;
21
-use PSFS\base\types\helpers\Inspector;
22 18
 use PSFS\base\types\traits\Api\ManagerTrait;
23 19
 
24 20
 /**
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 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) {
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
         }
@@ -390,27 +390,27 @@  discard block
 block discarded – undo
390 390
         /** @var CustomerTableMap $tableMap */
391 391
         $tableMap = $this->getTableMap();
392 392
         $modelPk = null;
393
-        foreach($tableMap->getPrimaryKeys() as $pk) {
393
+        foreach ($tableMap->getPrimaryKeys() as $pk) {
394 394
             $modelPk = $pk;
395 395
             break;
396 396
         }
397
-        foreach($this->list->getResults() as &$arrObj) {
397
+        foreach ($this->list->getResults() as &$arrObj) {
398 398
             $arrObj[$modelPk->getPhpName()] = $arrObj[self::API_MODEL_KEY_FIELD];
399 399
             $dataFetcher = new ArrayDataFetcher($arrObj);
400 400
             $formatter->setDataFetcher($dataFetcher);
401 401
             /** @var Customer $obj */
402 402
             $obj = $formatter->getAllObjectsFromRow($arrObj);
403 403
             $result = [];
404
-            foreach($arrObj as $key => $value) {
405
-                if(self::API_MODEL_KEY_FIELD === $key) {
404
+            foreach ($arrObj as $key => $value) {
405
+                if (self::API_MODEL_KEY_FIELD === $key) {
406 406
                     $result[$key] = (integer)$value;
407 407
                 } elseif (null !== $obj->getByName($key)) {
408 408
                     $result[$key] = $obj->getByName($key);
409
-                } else {
409
+                }else {
410 410
                     $result[$key] = $value;
411 411
                 }
412 412
             }
413
-            if(!preg_match('/' . $modelPk->getPhpName() . '/i', $this->query[self::API_FIELDS_RESULT_FIELD])) {
413
+            if (!preg_match('/'.$modelPk->getPhpName().'/i', $this->query[self::API_FIELDS_RESULT_FIELD])) {
414 414
                 unset($result[$modelPk->getPhpName()]);
415 415
             }
416 416
             $return[] = $result;
@@ -429,16 +429,16 @@  discard block
 block discarded – undo
429 429
         try {
430 430
             $this->paginate();
431 431
             if (null !== $this->list) {
432
-                if(array_key_exists(self::API_FIELDS_RESULT_FIELD, $this->query) && Config::getParam('api.field.types')) {
432
+                if (array_key_exists(self::API_FIELDS_RESULT_FIELD, $this->query) && Config::getParam('api.field.types')) {
433 433
                     $return = $this->extractDataWithFormat();
434
-                } else {
434
+                }else {
435 435
                     $return = $this->list->toArray(null, false, TableMap::TYPE_PHPNAME, false);
436 436
                 }
437 437
                 $total = $this->list->getNbResults();
438 438
                 $pages = $this->list->getLastPage();
439 439
             }
440
-        } catch (\Exception $e) {
441
-            Logger::log(get_class($this) . ': ' . $e->getMessage(), LOG_ERR);
440
+        }catch (\Exception $e) {
441
+            Logger::log(get_class($this).': '.$e->getMessage(), LOG_ERR);
442 442
         }
443 443
 
444 444
         return array($return, $total, $pages);
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
         $return = array();
457 457
         if (NULL === $model || !method_exists($model, 'toArray')) {
458 458
             $code = 404;
459
-        } else {
459
+        }else {
460 460
             $return = $model->toArray();
461 461
         }
462 462
 
Please login to merge, or discard this patch.