Passed
Push — master ( 0a2888...e4ffa7 )
by Fran
10:55
created
src/base/types/traits/Api/ApiTrait.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 
40 40
     /**
41 41
      * Method that extract the Api name
42
-     * @return mixed
42
+     * @return string
43 43
      */
44 44
     public function getApi()
45 45
     {
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 
51 51
     /**
52 52
      * Method that extract the Domain name
53
-     * @return mixed
53
+     * @return string
54 54
      */
55 55
     public function getDomain()
56 56
     {
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
      *
94 94
      * @param ModelCriteria $query
95 95
      */
96
-    protected function joinTables(ModelCriteria &$query)
96
+    protected function joinTables(ModelCriteria & $query)
97 97
     {
98 98
         //TODO for specific implementations
99 99
     }
@@ -106,14 +106,14 @@  discard block
 block discarded – undo
106 106
      */
107 107
     private function findPk(ModelCriteria $query, $pk) {
108 108
         $pks = explode(Api::API_PK_SEPARATOR, urldecode($pk));
109
-        if(count($pks) == 1) {
109
+        if (count($pks) == 1) {
110 110
             return $query->findPk($pks[0]);
111
-        } else {
111
+        }else {
112 112
             $i = 0;
113
-            foreach($this->getPkDbName() as $key => $phpName) {
113
+            foreach ($this->getPkDbName() as $key => $phpName) {
114 114
                 $query->filterBy($phpName, $pks[$i]);
115 115
                 $i++;
116
-                if($i >= count($pks)) break;
116
+                if ($i >= count($pks)) break;
117 117
             }
118 118
             return $query->findOne();
119 119
         }
@@ -140,8 +140,8 @@  discard block
 block discarded – undo
140 140
         try {
141 141
             $query = $this->prepareQuery();
142 142
             $this->model = $this->findPk($query, $pk);
143
-        } catch (\Exception $e) {
144
-            Logger::log(get_class($this) . ': ' . $e->getMessage(), LOG_ERR);
143
+        }catch (\Exception $e) {
144
+            Logger::log(get_class($this).': '.$e->getMessage(), LOG_ERR);
145 145
         }
146 146
     }
147 147
 
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
     /**
163 163
      * @param ModelCriteria $query
164 164
      */
165
-    private function checkReturnFields(ModelCriteria &$query)
165
+    private function checkReturnFields(ModelCriteria & $query)
166 166
     {
167 167
         $returnFields = Request::getInstance()->getQuery(Api::API_FIELDS_RESULT_FIELD);
168 168
         if (null !== $returnFields) {
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -113,7 +113,9 @@
 block discarded – undo
113 113
             foreach($this->getPkDbName() as $key => $phpName) {
114 114
                 $query->filterBy($phpName, $pks[$i]);
115 115
                 $i++;
116
-                if($i >= count($pks)) break;
116
+                if($i >= count($pks)) {
117
+                    break;
118
+                }
117 119
             }
118 120
             return $query->findOne();
119 121
         }
Please login to merge, or discard this patch.
src/base/dto/Form.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@
 block discarded – undo
48 48
             return ($aOrder < $bOrder) ? -1 : 1;
49 49
         });
50 50
         $array['actions'] = [];
51
-        foreach($this->actions as $action) {
51
+        foreach ($this->actions as $action) {
52 52
             $array['actions'][] = $action->__toArray();
53 53
         }
54 54
         return $array;
Please login to merge, or discard this patch.
src/base/types/helpers/RequestHelper.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@
 block discarded – undo
44 44
                     header("Access-Control-Allow-Credentials: true");
45 45
                     header("Access-Control-Allow-Origin: *");
46 46
                     header("Access-Control-Allow-Methods: GET, POST, DELETE, PUT, PATCH, OPTIONS");
47
-                    header("Access-Control-Allow-Headers: " . implode(', ', self::getCorsHeaders()));
47
+                    header("Access-Control-Allow-Headers: ".implode(', ', self::getCorsHeaders()));
48 48
                 }
49 49
                 if (Request::getInstance()->getMethod() == 'OPTIONS') {
50 50
                     Logger::log('Returning OPTIONS header confirmation for CORS pre flight requests', LOG_DEBUG);
Please login to merge, or discard this patch.
src/base/types/traits/Api/ManagerTrait.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -39,8 +39,8 @@
 block discarded – undo
39 39
             "domain" => $this->getDomain(),
40 40
             "listLabel" => Api::API_LIST_NAME_FIELD,
41 41
             'modelId' => Api::API_MODEL_KEY_FIELD,
42
-            'formUrl' => preg_replace('/\/\{(.*)\}$/i', '', $this->getRoute(strtolower('admin-api-form-' . $this->getDomain() . '-' . $this->getApi()), TRUE)),
43
-            "url" => preg_replace('/\/\{(.*)\}$/i', '', $this->getRoute(strtolower($this->getDomain() . '-' . 'api-' . $this->getApi() . "-pk"), TRUE)),
42
+            'formUrl' => preg_replace('/\/\{(.*)\}$/i', '', $this->getRoute(strtolower('admin-api-form-'.$this->getDomain().'-'.$this->getApi()), TRUE)),
43
+            "url" => preg_replace('/\/\{(.*)\}$/i', '', $this->getRoute(strtolower($this->getDomain().'-'.'api-'.$this->getApi()."-pk"), TRUE)),
44 44
         ), [], '');
45 45
     }
46 46
 
Please login to merge, or discard this patch.
src/base/types/Api.php 2 patches
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
      *
115 115
      * @param ModelCriteria $query
116 116
      */
117
-    private function addOrders(ModelCriteria &$query)
117
+    private function addOrders(ModelCriteria & $query)
118 118
     {
119 119
         $orderAdded = FALSE;
120 120
         $tableMap = $this->getTableMap();
@@ -123,13 +123,13 @@  discard block
 block discarded – undo
123 123
                 $orderAdded = TRUE;
124 124
                 if ($direction === Order::ASC) {
125 125
                     $query->addAscendingOrderByColumn($column->getPhpName());
126
-                } else {
126
+                }else {
127 127
                     $query->addDescendingOrderByColumn($column->getPhpName());
128 128
                 }
129 129
             }
130 130
         }
131 131
         if (!$orderAdded) {
132
-            foreach($this->getPkDbName() as $pk => $phpName) {
132
+            foreach ($this->getPkDbName() as $pk => $phpName) {
133 133
                 $query->addAscendingOrderByColumn($pk);
134 134
             }
135 135
         }
@@ -140,14 +140,14 @@  discard block
 block discarded – undo
140 140
      *
141 141
      * @param ModelCriteria $query
142 142
      */
143
-    private function addFilters(ModelCriteria &$query)
143
+    private function addFilters(ModelCriteria & $query)
144 144
     {
145 145
         if (count($this->query) > 0) {
146 146
             $tableMap = $this->getTableMap();
147 147
             foreach ($this->query as $field => $value) {
148 148
                 if (self::API_COMBO_FIELD === $field) {
149 149
                     ApiHelper::composerComboField($tableMap, $query, $this->extraColumns, $value);
150
-                } elseif(!preg_match('/^__/', $field)) {
150
+                } elseif (!preg_match('/^__/', $field)) {
151 151
                     ApiHelper::addModelField($tableMap, $query, $field, $value);
152 152
                 }
153 153
             }
@@ -168,10 +168,10 @@  discard block
 block discarded – undo
168 168
             list($page, $limit) = $this->extractPagination();
169 169
             if ($limit == -1) {
170 170
                 $this->list = $query->find($this->con);
171
-            } else {
171
+            }else {
172 172
                 $this->list = $query->paginate($page, $limit, $this->con);
173 173
             }
174
-        } catch (\Exception $e) {
174
+        }catch (\Exception $e) {
175 175
             Logger::log($e->getMessage(), LOG_ERR);
176 176
         }
177 177
     }
@@ -237,8 +237,8 @@  discard block
 block discarded – undo
237 237
                 $saved = TRUE;
238 238
                 $model = $this->model->toArray();
239 239
             }
240
-        } catch (\Exception $e) {
241
-            $model = _('Ha ocurrido un error intentando guardar el elemento: ') . $e->getMessage();
240
+        }catch (\Exception $e) {
241
+            $model = _('Ha ocurrido un error intentando guardar el elemento: ').$e->getMessage();
242 242
             Logger::log($e->getMessage(), LOG_ERR);
243 243
         }
244 244
 
@@ -271,14 +271,14 @@  discard block
 block discarded – undo
271 271
                     $updated = TRUE;
272 272
                     $status = 200;
273 273
                     $model = $this->model->toArray();
274
-                } else {
274
+                }else {
275 275
                     $model = _('Ha ocurrido un error intentando actualizar el elemento, por favor revisa los logs');
276 276
                 }
277
-            } catch (\Exception $e) {
277
+            }catch (\Exception $e) {
278 278
                 $model = $e->getMessage();
279 279
                 Logger::getInstance(get_class($this->model))->errorLog($e->getMessage());
280 280
             }
281
-        } else {
281
+        }else {
282 282
             $model = _('Ha ocurrido un error intentando actualizar el elemento, por favor revisa los logs');
283 283
         }
284 284
 
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
                     $this->model->delete($this->con);
309 309
                     $deleted = TRUE;
310 310
                 }
311
-            } catch (\Exception $e) {
311
+            }catch (\Exception $e) {
312 312
                 $message = _('Ha ocurrido un error intentando eliminar el elemento, por favor verifica que no tenga otros elementos relacionados');
313 313
                 Logger::getInstance(get_class($this->model))->errorLog($e->getMessage());
314 314
             }
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
                 $total = $this->list->getNbResults();
343 343
                 $pages = $this->list->getLastPage();
344 344
             }
345
-        } catch (\Exception $e) {
345
+        }catch (\Exception $e) {
346 346
             Logger::getInstance(get_class($this))->errorLog($e->getMessage());
347 347
         }
348 348
 
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
         $return = array();
362 362
         if (NULL === $model || !method_exists($model, 'toArray')) {
363 363
             $code = 404;
364
-        } else {
364
+        }else {
365 365
             $return = $model->toArray();
366 366
         }
367 367
 
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -3,7 +3,6 @@
 block discarded – undo
3 3
 
4 4
 use Propel\Runtime\ActiveQuery\ModelCriteria;
5 5
 use Propel\Runtime\Map\TableMap;
6
-use PSFS\base\config\Config;
7 6
 use PSFS\base\dto\JsonResponse;
8 7
 use PSFS\base\dto\Order;
9 8
 use PSFS\base\Logger;
Please login to merge, or discard this patch.
src/base/types/traits/Api/ConnectionTrait.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,6 @@
 block discarded – undo
6 6
 use Propel\Runtime\Propel;
7 7
 use PSFS\base\config\Config;
8 8
 use PSFS\base\Logger;
9
-use PSFS\base\types\traits\DebugTrait;
10 9
 
11 10
 /**
12 11
  * Trait ConnectionTrait
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
     protected function createConnection(TableMap $tableMap)
27 27
     {
28 28
         $this->con = Propel::getConnection($tableMap::DATABASE_NAME);
29
-        if(method_exists($this->con, 'useDebug')) {
29
+        if (method_exists($this->con, 'useDebug')) {
30 30
             Logger::log('Enabling debug queries mode', LOG_INFO);
31 31
             $this->con->useDebug(Config::getParam('debug'));
32 32
         }
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
         if (null !== $this->con && $this->con->inTransaction()) {
44 44
             if ($status === 200) {
45 45
                 $this->con->commit();
46
-            } else {
46
+            }else {
47 47
                 $this->con->rollBack();
48 48
             }
49 49
         }
Please login to merge, or discard this patch.
src/base/types/traits/Api/MutationTrait.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -58,21 +58,21 @@  discard block
 block discarded – undo
58 58
         if (count($pks) == 1) {
59 59
             $pks = array_keys($pks);
60 60
             return [
61
-                $tableMap::TABLE_NAME . '.' . $pks[0] => Api::API_MODEL_KEY_FIELD
61
+                $tableMap::TABLE_NAME.'.'.$pks[0] => Api::API_MODEL_KEY_FIELD
62 62
             ];
63 63
         } elseif (count($pks) > 1) {
64 64
             $apiPks = [];
65 65
             $principal = '';
66 66
             $sep = 'CONCAT(';
67 67
             foreach ($pks as $pk) {
68
-                $apiPks[$tableMap::TABLE_NAME . '.' . $pk->getName()] = $pk->getPhpName();
69
-                $principal .= $sep . $tableMap::TABLE_NAME . '.' . $pk->getName();
70
-                $sep = ', "' . Api::API_PK_SEPARATOR . '", ';
68
+                $apiPks[$tableMap::TABLE_NAME.'.'.$pk->getName()] = $pk->getPhpName();
69
+                $principal .= $sep.$tableMap::TABLE_NAME.'.'.$pk->getName();
70
+                $sep = ', "'.Api::API_PK_SEPARATOR.'", ';
71 71
             }
72 72
             $principal .= ')';
73 73
             $apiPks[$principal] = Api::API_MODEL_KEY_FIELD;
74 74
             return $apiPks;
75
-        } else {
75
+        }else {
76 76
             throw new ApiException(_('El modelo de la API no está debidamente mapeado, no hay Primary Key o es compuesta'));
77 77
         }
78 78
     }
@@ -95,10 +95,10 @@  discard block
 block discarded – undo
95 95
         $pks = '';
96 96
         $sep = '';
97 97
         foreach ($tableMap->getPrimaryKeys() as $pk) {
98
-            $pks .= $sep . $pk->getFullyQualifiedName();
98
+            $pks .= $sep.$pk->getFullyQualifiedName();
99 99
             $sep = ', "|", ';
100 100
         }
101
-        $this->extraColumns['CONCAT("' . $tableMap->getPhpName() . ' #", ' . $pks . ')'] = Api::API_LIST_NAME_FIELD;
101
+        $this->extraColumns['CONCAT("'.$tableMap->getPhpName().' #", '.$pks.')'] = Api::API_LIST_NAME_FIELD;
102 102
     }
103 103
 
104 104
     /**
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
             }
121 121
             if (null !== $column) {
122 122
                 $this->extraColumns[$column->getFullyQualifiedName()] = Api::API_LIST_NAME_FIELD;
123
-            } else {
123
+            }else {
124 124
                 $this->addClassListName($tableMap);
125 125
             }
126 126
         }
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
      * @param ModelCriteria $query
133 133
      * @param string $action
134 134
      */
135
-    private function addExtraColumns(ModelCriteria &$query, $action)
135
+    private function addExtraColumns(ModelCriteria & $query, $action)
136 136
     {
137 137
         if (Api::API_ACTION_LIST === $action) {
138 138
             $this->addDefaultListField();
@@ -160,21 +160,21 @@  discard block
 block discarded – undo
160 160
     /**
161 161
      * @param ModelCriteria $query
162 162
      */
163
-    protected function checkI18n(ModelCriteria &$query)
163
+    protected function checkI18n(ModelCriteria & $query)
164 164
     {
165 165
         $model = $this->getModelNamespace();
166
-        $modelI18n = $model . 'I18n';
166
+        $modelI18n = $model.'I18n';
167 167
         if (method_exists($query, 'useI18nQuery')) {
168 168
             $default_language = explode('_', Config::getParam('default.language', 'es_ES'));
169 169
             $query->useI18nQuery(Request::header('X-API-LANG', $default_language[0]));
170
-            $modelI18nTableMapClass = str_replace('\\Models\\', '\\Models\\Map\\', $modelI18n) . 'TableMap';
170
+            $modelI18nTableMapClass = str_replace('\\Models\\', '\\Models\\Map\\', $modelI18n).'TableMap';
171 171
             /** @var TableMap $modelI18nTableMap */
172 172
             $modelI18nTableMap = $modelI18nTableMapClass::getTableMap();
173
-            foreach($modelI18nTableMap->getColumns() as $columnMap) {
174
-                if(!$columnMap->isPrimaryKey()) {
175
-                    $query->withColumn($modelI18nTableMapClass::TABLE_NAME . '.' . $columnMap->getName(), $columnMap->getPhpName());
176
-                } elseif(!$columnMap->isForeignKey()) {
177
-                    $query->withColumn('IFNULL(' . $modelI18nTableMapClass::TABLE_NAME . '.' . $columnMap->getName() . ', "'.Request::header('X-API-LANG', 'es').'")', $columnMap->getPhpName());
173
+            foreach ($modelI18nTableMap->getColumns() as $columnMap) {
174
+                if (!$columnMap->isPrimaryKey()) {
175
+                    $query->withColumn($modelI18nTableMapClass::TABLE_NAME.'.'.$columnMap->getName(), $columnMap->getPhpName());
176
+                } elseif (!$columnMap->isForeignKey()) {
177
+                    $query->withColumn('IFNULL('.$modelI18nTableMapClass::TABLE_NAME.'.'.$columnMap->getName().', "'.Request::header('X-API-LANG', 'es').'")', $columnMap->getPhpName());
178 178
                 }
179 179
             }
180 180
         }
@@ -184,23 +184,23 @@  discard block
 block discarded – undo
184 184
      * @param ActiveRecordInterface $model
185 185
      * @param array $data
186 186
      */
187
-    protected function hydrateModelFromRequest(ActiveRecordInterface &$model, array $data = []) {
187
+    protected function hydrateModelFromRequest(ActiveRecordInterface & $model, array $data = []) {
188 188
         $model->fromArray($data);
189 189
         $tableMap = $this->getTableMap();
190 190
         try {
191
-            $relateI18n = $tableMap->getRelation($tableMap->getPhpName() . 'I18n');
192
-            if(null !== $relateI18n) {
191
+            $relateI18n = $tableMap->getRelation($tableMap->getPhpName().'I18n');
192
+            if (null !== $relateI18n) {
193 193
                 $i18NTableMap = $relateI18n->getLocalTable();
194
-                foreach($i18NTableMap->getColumns() as $columnMap) {
195
-                    $method = 'set' . $columnMap->getPhpName();
196
-                    if(!($columnMap->isPrimaryKey() && $columnMap->isForeignKey())
194
+                foreach ($i18NTableMap->getColumns() as $columnMap) {
195
+                    $method = 'set'.$columnMap->getPhpName();
196
+                    if (!($columnMap->isPrimaryKey() && $columnMap->isForeignKey())
197 197
                         &&array_key_exists($columnMap->getPhpName(), $data)
198 198
                         && method_exists($model, $method)) {
199 199
                         $model->$method($data[$columnMap->getPhpName()]);
200 200
                     }
201 201
                 }
202 202
             }
203
-        } catch(\Exception $e) {
203
+        }catch (\Exception $e) {
204 204
             Logger::log($e->getMessage(), LOG_WARNING);
205 205
         }
206 206
     }
Please login to merge, or discard this patch.
src/base/Security.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
             session_start();
73 73
         }
74 74
         // Fix for phpunits
75
-        if(!isset($_SESSION)) {
75
+        if (!isset($_SESSION)) {
76 76
             $_SESSION = [];
77 77
         }
78 78
     }
@@ -132,12 +132,12 @@  discard block
 block discarded – undo
132 132
     {
133 133
         $saved = true;
134 134
         try {
135
-            $admins = Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', Cache::JSONGZ, true) ?: [];
136
-            $admins[$user['username']]['hash'] = sha1($user['username'] . $user['password']);
135
+            $admins = Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', Cache::JSONGZ, true) ?: [];
136
+            $admins[$user['username']]['hash'] = sha1($user['username'].$user['password']);
137 137
             $admins[$user['username']]['profile'] = $user['profile'];
138 138
 
139
-            Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', $admins, Cache::JSONGZ, true);
140
-        } catch(\Exception $e) {
139
+            Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', $admins, Cache::JSONGZ, true);
140
+        }catch (\Exception $e) {
141 141
             Logger::log($e->getMessage(), LOG_ERR);
142 142
             $saved = false;
143 143
         }
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
      */
175 175
     public function getAdmins()
176 176
     {
177
-        return Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', Cache::JSONGZ, true);
177
+        return Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', Cache::JSONGZ, true);
178 178
     }
179 179
 
180 180
     /**
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
                 }
203 203
                 if (!empty($user) && !empty($admins[$user])) {
204 204
                     $auth = $admins[$user]['hash'];
205
-                    $this->authorized = ($auth == sha1($user . $pass));
205
+                    $this->authorized = ($auth == sha1($user.$pass));
206 206
                     if ($this->authorized) {
207 207
                         $this->admin = array(
208 208
                             'alias' => $user,
Please login to merge, or discard this patch.