@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @param string $msg |
91 | 91 | * @param array $context |
92 | 92 | * |
93 | - * @return bool |
|
93 | + * @return boolean|null |
|
94 | 94 | */ |
95 | 95 | public function debugLog($msg = '', array $context = []) |
96 | 96 | { |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
101 | - * @param $msg |
|
101 | + * @param string $msg |
|
102 | 102 | * @param array $context |
103 | 103 | * |
104 | 104 | * @return bool |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
112 | - * @param $msg |
|
112 | + * @param string $msg |
|
113 | 113 | * @param array $context |
114 | 114 | * |
115 | 115 | * @return bool |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
126 | - * @param $msg |
|
126 | + * @param string $msg |
|
127 | 127 | * @param array $context |
128 | 128 | * @return bool |
129 | 129 | */ |
@@ -16,8 +16,8 @@ discard block |
||
16 | 16 | |
17 | 17 | |
18 | 18 | if (!defined('LOG_DIR')) { |
19 | - GeneratorHelper::createDir(BASE_DIR . DIRECTORY_SEPARATOR . 'logs'); |
|
20 | - define('LOG_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'logs'); |
|
19 | + GeneratorHelper::createDir(BASE_DIR.DIRECTORY_SEPARATOR.'logs'); |
|
20 | + define('LOG_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'logs'); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | /** |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | $config = Config::getInstance(); |
56 | 56 | $args = func_get_args(); |
57 | 57 | list($logger, $debug, $path) = $this->setup($config, $args); |
58 | - $this->stream = fopen($path . DIRECTORY_SEPARATOR . date('Ymd') . '.log', 'a+'); |
|
58 | + $this->stream = fopen($path.DIRECTORY_SEPARATOR.date('Ymd').'.log', 'a+'); |
|
59 | 59 | $this->addPushLogger($logger, $debug, $config); |
60 | 60 | $this->log_level = Config::getParam('log.level', 'info'); |
61 | 61 | } |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | */ |
117 | 117 | public function criticalLog($msg, array $context = []) |
118 | 118 | { |
119 | - if(Config::getParam('log.slack.hook')) { |
|
119 | + if (Config::getParam('log.slack.hook')) { |
|
120 | 120 | SlackHelper::getInstance()->trace($msg, '', '', $context); |
121 | 121 | } |
122 | 122 | return $this->logger->addCritical($msg, $this->addMinimalContext($context)); |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | private function createLoggerPath(Config $config) |
213 | 213 | { |
214 | 214 | $logger = $this->setLoggerName($config); |
215 | - $path = LOG_DIR . DIRECTORY_SEPARATOR . $logger . DIRECTORY_SEPARATOR . date('Y') . DIRECTORY_SEPARATOR . date('m'); |
|
215 | + $path = LOG_DIR.DIRECTORY_SEPARATOR.$logger.DIRECTORY_SEPARATOR.date('Y').DIRECTORY_SEPARATOR.date('m'); |
|
216 | 216 | GeneratorHelper::createDir($path); |
217 | 217 | |
218 | 218 | return $path; |
@@ -225,10 +225,10 @@ discard block |
||
225 | 225 | */ |
226 | 226 | public static function log($msg, $type = LOG_DEBUG, array $context = null) |
227 | 227 | { |
228 | - if(null === $context) { |
|
228 | + if (null === $context) { |
|
229 | 229 | $context = []; |
230 | 230 | } |
231 | - if(Config::getParam('profiling.enable')) { |
|
231 | + if (Config::getParam('profiling.enable')) { |
|
232 | 232 | Inspector::stats($msg); |
233 | 233 | } |
234 | 234 | switch ($type) { |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | { |
280 | 280 | $context['uri'] = null !== $_SERVER && array_key_exists('REQUEST_URI', $_SERVER) ? $_SERVER['REQUEST_URI'] : 'Unknow'; |
281 | 281 | $context['method'] = null !== $_SERVER && array_key_exists('REQUEST_METHOD', $_SERVER) ? $_SERVER['REQUEST_METHOD'] : 'Unknow'; |
282 | - if(null !== $_SERVER && array_key_exists('HTTP_X_PSFS_UID', $_SERVER)) { |
|
282 | + if (null !== $_SERVER && array_key_exists('HTTP_X_PSFS_UID', $_SERVER)) { |
|
283 | 283 | $context['uid'] = $_SERVER['HTTP_X_PSFS_UID']; |
284 | 284 | } |
285 | 285 | return $context; |
@@ -3,8 +3,6 @@ |
||
3 | 3 | |
4 | 4 | use PSFS\base\config\Config; |
5 | 5 | use PSFS\base\Logger; |
6 | -use PSFS\base\Request; |
|
7 | -use PSFS\base\Router; |
|
8 | 6 | use PSFS\base\types\helpers\SlackHelper; |
9 | 7 | |
10 | 8 | /** |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | $use /= 1024; |
39 | 39 | break; |
40 | 40 | case "MBytes": |
41 | - $use /= (1024 * 1024); |
|
41 | + $use /= (1024*1024); |
|
42 | 42 | break; |
43 | 43 | case "Bytes": |
44 | 44 | default: |
@@ -62,34 +62,34 @@ discard block |
||
62 | 62 | protected function bindWarningAsExceptions() |
63 | 63 | { |
64 | 64 | Logger::log('Added handlers for errors'); |
65 | - if(Config::getParam('debug')) { |
|
65 | + if (Config::getParam('debug')) { |
|
66 | 66 | Logger::log('Setting error_reporting as E_ALL'); |
67 | 67 | ini_set('error_reporting', E_ALL); |
68 | 68 | ini_set('display_errors', 1); |
69 | 69 | } |
70 | 70 | //Warning & Notice handler |
71 | - set_error_handler(function ($errno, $errstr, $errfile, $errline) { |
|
71 | + set_error_handler(function($errno, $errstr, $errfile, $errline) { |
|
72 | 72 | Logger::log($errstr, LOG_CRIT, ['file' => $errfile, 'line' => $errline, 'errno' => $errno]); |
73 | 73 | return true; |
74 | 74 | }, E_ALL | E_STRICT | E_DEPRECATED | E_USER_DEPRECATED | E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR); |
75 | 75 | |
76 | - register_shutdown_function(function () { |
|
76 | + register_shutdown_function(function() { |
|
77 | 77 | $error = error_get_last() or json_last_error() or preg_last_error() or \DateTime::getLastErrors(); |
78 | - if( $error !== NULL) { |
|
78 | + if ($error !== NULL) { |
|
79 | 79 | $errno = $error["type"]; |
80 | 80 | $errfile = $error["file"]; |
81 | 81 | $errline = $error["line"]; |
82 | 82 | $errstr = $error["message"]; |
83 | 83 | Logger::log($errstr, LOG_CRIT, ['file' => $errfile, 'line' => $errline, 'errno' => $errno]); |
84 | - if(null !== Config::getParam('log.slack.hook')) { |
|
84 | + if (null !== Config::getParam('log.slack.hook')) { |
|
85 | 85 | SlackHelper::getInstance()->trace($errstr, $errfile, $errline, $error); |
86 | 86 | } |
87 | 87 | } |
88 | 88 | |
89 | - if(self::getTs() > 10 && null !== Config::getParam('log.slack.hook')) { |
|
89 | + if (self::getTs() > 10 && null !== Config::getParam('log.slack.hook')) { |
|
90 | 90 | SlackHelper::getInstance()->trace('Slow service endpoint', '', '', [ |
91 | - 'time' => round(self::getTs(), 3) . ' secs', |
|
92 | - 'memory' => round(self::getMem('MBytes'), 3) . ' Mb', |
|
91 | + 'time' => round(self::getTs(), 3).' secs', |
|
92 | + 'memory' => round(self::getMem('MBytes'), 3).' Mb', |
|
93 | 93 | ]); |
94 | 94 | } |
95 | 95 | return false; |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | Logger::log('Initializing stats (mem + ts)'); |
105 | 105 | if (null !== $_SERVER && array_key_exists('REQUEST_TIME_FLOAT', $_SERVER)) { |
106 | 106 | $this->ts = (float)$_SERVER['REQUEST_TIME_FLOAT']; |
107 | - } else { |
|
107 | + }else { |
|
108 | 108 | $this->ts = PSFS_START_TS; |
109 | 109 | } |
110 | 110 | $this->mem = PSFS_START_MEM; |
@@ -43,7 +43,7 @@ |
||
43 | 43 | $this->success = $result; |
44 | 44 | $this->total = $total ?: (is_array($data) ? count($data) : 0); |
45 | 45 | $this->pages = $pages; |
46 | - if(null !== $message) { |
|
46 | + if (null !== $message) { |
|
47 | 47 | $this->message = $message; |
48 | 48 | } |
49 | 49 | } |
@@ -74,15 +74,15 @@ discard block |
||
74 | 74 | public function init() |
75 | 75 | { |
76 | 76 | parent::init(); |
77 | - Logger::log(get_called_class() . ' init', LOG_DEBUG); |
|
77 | + Logger::log(get_called_class().' init', LOG_DEBUG); |
|
78 | 78 | $this->domain = $this->getDomain(); |
79 | 79 | $this->hydrateRequestData(); |
80 | 80 | $this->hydrateOrders(); |
81 | - if($this instanceof CustomApi === false) { |
|
81 | + if ($this instanceof CustomApi === false) { |
|
82 | 82 | $this->createConnection($this->getTableMap()); |
83 | 83 | } |
84 | 84 | $this->setLoaded(true); |
85 | - Logger::log(get_called_class() . ' loaded', LOG_DEBUG); |
|
85 | + Logger::log(get_called_class().' loaded', LOG_DEBUG); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | protected function hydrateOrders() |
92 | 92 | { |
93 | 93 | if (count($this->query)) { |
94 | - Logger::log(get_called_class() . ' gathering query string', LOG_DEBUG); |
|
94 | + Logger::log(get_called_class().' gathering query string', LOG_DEBUG); |
|
95 | 95 | foreach ($this->query as $key => $value) { |
96 | 96 | if ($key === self::API_ORDER_FIELD && is_array($value)) { |
97 | 97 | foreach ($value as $field => $direction) { |
@@ -108,10 +108,10 @@ discard block |
||
108 | 108 | */ |
109 | 109 | protected function extractPagination() |
110 | 110 | { |
111 | - Logger::log(get_called_class() . ' extract pagination start', LOG_DEBUG); |
|
111 | + Logger::log(get_called_class().' extract pagination start', LOG_DEBUG); |
|
112 | 112 | $page = (array_key_exists(self::API_PAGE_FIELD, $this->query)) ? $this->query[self::API_PAGE_FIELD] : 1; |
113 | 113 | $limit = (array_key_exists(self::API_LIMIT_FIELD, $this->query)) ? $this->query[self::API_LIMIT_FIELD] : 100; |
114 | - Logger::log(get_called_class() . ' extract pagination end', LOG_DEBUG); |
|
114 | + Logger::log(get_called_class().' extract pagination end', LOG_DEBUG); |
|
115 | 115 | return array($page, $limit); |
116 | 116 | } |
117 | 117 | |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | */ |
123 | 123 | private function addOrders(ModelCriteria &$query) |
124 | 124 | { |
125 | - Logger::log(get_called_class() . ' extract orders start ', LOG_DEBUG); |
|
125 | + Logger::log(get_called_class().' extract orders start ', LOG_DEBUG); |
|
126 | 126 | $orderAdded = FALSE; |
127 | 127 | $tableMap = $this->getTableMap(); |
128 | 128 | foreach ($this->order->getOrders() as $field => $direction) { |
@@ -130,17 +130,17 @@ discard block |
||
130 | 130 | $orderAdded = TRUE; |
131 | 131 | if ($direction === Order::ASC) { |
132 | 132 | $query->addAscendingOrderByColumn($column->getPhpName()); |
133 | - } else { |
|
133 | + }else { |
|
134 | 134 | $query->addDescendingOrderByColumn($column->getPhpName()); |
135 | 135 | } |
136 | 136 | } |
137 | 137 | } |
138 | 138 | if (!$orderAdded) { |
139 | - foreach($this->getPkDbName() as $pk => $phpName) { |
|
139 | + foreach ($this->getPkDbName() as $pk => $phpName) { |
|
140 | 140 | $query->addAscendingOrderByColumn($pk); |
141 | 141 | } |
142 | 142 | } |
143 | - Logger::log(get_called_class() . ' extract orders end', LOG_DEBUG); |
|
143 | + Logger::log(get_called_class().' extract orders end', LOG_DEBUG); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | foreach ($this->query as $field => $value) { |
156 | 156 | if (self::API_COMBO_FIELD === $field) { |
157 | 157 | ApiHelper::composerComboField($tableMap, $query, $this->extraColumns, $value); |
158 | - } elseif(!preg_match('/^__/', $field)) { |
|
158 | + } elseif (!preg_match('/^__/', $field)) { |
|
159 | 159 | ApiHelper::addModelField($tableMap, $query, $field, $value); |
160 | 160 | } |
161 | 161 | } |
@@ -176,10 +176,10 @@ discard block |
||
176 | 176 | list($page, $limit) = $this->extractPagination(); |
177 | 177 | if ($limit == -1) { |
178 | 178 | $this->list = $query->find($this->con); |
179 | - } else { |
|
179 | + }else { |
|
180 | 180 | $this->list = $query->paginate($page, $limit, $this->con); |
181 | 181 | } |
182 | - } catch (\Exception $e) { |
|
182 | + }catch (\Exception $e) { |
|
183 | 183 | Logger::log($e->getMessage(), LOG_ERR); |
184 | 184 | } |
185 | 185 | } |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | $code = 200; |
199 | 199 | list($return, $total, $pages) = $this->getList(); |
200 | 200 | $message = null; |
201 | - if(!$total) { |
|
201 | + if (!$total) { |
|
202 | 202 | $message = i18n::_('No se han encontrado elementos para la búsqueda'); |
203 | 203 | } |
204 | 204 | |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | $pages = 1; |
225 | 225 | $message = null; |
226 | 226 | list($code, $return) = $this->getSingleResult($pk); |
227 | - if($code !== 200) { |
|
227 | + if ($code !== 200) { |
|
228 | 228 | $message = i18n::_('No se ha encontrado el elemento solicitado'); |
229 | 229 | } |
230 | 230 | |
@@ -253,13 +253,13 @@ discard block |
||
253 | 253 | $status = 200; |
254 | 254 | $saved = TRUE; |
255 | 255 | $model = $this->model->toArray(); |
256 | - } else { |
|
256 | + }else { |
|
257 | 257 | $message = i18n::_('No se ha podido guardar el modelo seleccionado'); |
258 | 258 | } |
259 | - } catch (\Exception $e) { |
|
260 | - $message = i18n::_('Ha ocurrido un error intentando guardar el elemento: ') .'<br>'. $e->getMessage(); |
|
259 | + }catch (\Exception $e) { |
|
260 | + $message = i18n::_('Ha ocurrido un error intentando guardar el elemento: ').'<br>'.$e->getMessage(); |
|
261 | 261 | $context = []; |
262 | - if(null !== $e->getPrevious()) { |
|
262 | + if (null !== $e->getPrevious()) { |
|
263 | 263 | $context[] = $e->getPrevious()->getMessage(); |
264 | 264 | } |
265 | 265 | Logger::log($e->getMessage(), LOG_CRIT, $context); |
@@ -295,18 +295,18 @@ discard block |
||
295 | 295 | $updated = TRUE; |
296 | 296 | $status = 200; |
297 | 297 | $model = $this->model->toArray(); |
298 | - } else { |
|
298 | + }else { |
|
299 | 299 | $message = i18n::_('Ha ocurrido un error intentando actualizar el elemento, por favor revisa los logs'); |
300 | 300 | } |
301 | - } catch (\Exception $e) { |
|
301 | + }catch (\Exception $e) { |
|
302 | 302 | $message = i18n::_('Ha ocurrido un error intentando actualizar el elemento, por favor revisa los logs'); |
303 | 303 | $context = []; |
304 | - if(null !== $e->getPrevious()) { |
|
304 | + if (null !== $e->getPrevious()) { |
|
305 | 305 | $context[] = $e->getPrevious()->getMessage(); |
306 | 306 | } |
307 | 307 | Logger::log($e->getMessage(), LOG_CRIT, $context); |
308 | 308 | } |
309 | - } else { |
|
309 | + }else { |
|
310 | 310 | $message = i18n::_('No se ha encontrado el modelo al que se hace referencia para actualizar'); |
311 | 311 | } |
312 | 312 | |
@@ -334,15 +334,15 @@ discard block |
||
334 | 334 | $this->con->beginTransaction(); |
335 | 335 | $this->hydrateModel($pk); |
336 | 336 | if (NULL !== $this->model) { |
337 | - if(method_exists('clearAllReferences', $this->model)) { |
|
337 | + if (method_exists('clearAllReferences', $this->model)) { |
|
338 | 338 | $this->model->clearAllReferences(true); |
339 | 339 | } |
340 | 340 | $this->model->delete($this->con); |
341 | 341 | $deleted = TRUE; |
342 | 342 | } |
343 | - } catch (\Exception $e) { |
|
343 | + }catch (\Exception $e) { |
|
344 | 344 | $context = []; |
345 | - if(null !== $e->getPrevious()) { |
|
345 | + if (null !== $e->getPrevious()) { |
|
346 | 346 | $context[] = $e->getPrevious()->getMessage(); |
347 | 347 | } |
348 | 348 | Logger::log($e->getMessage(), LOG_CRIT, $context); |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | $this->saveBulk(); |
373 | 373 | $saved = true; |
374 | 374 | $status = 200; |
375 | - } catch(\Exception $e) { |
|
375 | + }catch (\Exception $e) { |
|
376 | 376 | Logger::log($e->getMessage(), LOG_CRIT, $this->getRequest()->getData()); |
377 | 377 | $message = i18n::_('Bulk insert rolled back'); |
378 | 378 | } |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | |
395 | 395 | /** @var CustomerTableMap $tableMap */ |
396 | 396 | $modelPk = ApiHelper::extractPrimaryKeyColumnName($this->getTableMap()); |
397 | - foreach($this->list->getData() as $data) { |
|
397 | + foreach ($this->list->getData() as $data) { |
|
398 | 398 | $return[] = ApiHelper::mapArrayObject($this->getModelNamespace(), $modelPk, $this->query, $data); |
399 | 399 | } |
400 | 400 | return $return; |
@@ -411,20 +411,20 @@ discard block |
||
411 | 411 | try { |
412 | 412 | $this->paginate(); |
413 | 413 | if (null !== $this->list) { |
414 | - if(array_key_exists(self::API_FIELDS_RESULT_FIELD, $this->query) && Config::getParam('api.field.types')) { |
|
414 | + if (array_key_exists(self::API_FIELDS_RESULT_FIELD, $this->query) && Config::getParam('api.field.types')) { |
|
415 | 415 | $return = $this->extractDataWithFormat(); |
416 | - } else { |
|
416 | + }else { |
|
417 | 417 | $return = $this->list->toArray(null, false, TableMap::TYPE_PHPNAME, false); |
418 | 418 | } |
419 | 419 | $total = 0; |
420 | 420 | $pages = 0; |
421 | - if($this->list instanceof PropelModelPager) { |
|
421 | + if ($this->list instanceof PropelModelPager) { |
|
422 | 422 | $total = $this->list->getNbResults(); |
423 | 423 | $pages = $this->list->getLastPage(); |
424 | 424 | } |
425 | 425 | } |
426 | - } catch (\Exception $e) { |
|
427 | - Logger::log(get_class($this) . ': ' . $e->getMessage(), LOG_ERR); |
|
426 | + }catch (\Exception $e) { |
|
427 | + Logger::log(get_class($this).': '.$e->getMessage(), LOG_ERR); |
|
428 | 428 | } |
429 | 429 | |
430 | 430 | return array($return, $total, $pages); |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | $return = array(); |
443 | 443 | if (NULL === $model || !method_exists($model, 'toArray')) { |
444 | 444 | $code = 404; |
445 | - } else { |
|
445 | + }else { |
|
446 | 446 | $return = $model->toArray(); |
447 | 447 | } |
448 | 448 |
@@ -28,7 +28,7 @@ |
||
28 | 28 | 'text' => 'PSFS Error notifier', |
29 | 29 | 'attachments' => [ |
30 | 30 | [ |
31 | - "text" => $file . (strlen($line) ? ' [' . $line . ']' : ''), |
|
31 | + "text" => $file.(strlen($line) ? ' ['.$line.']' : ''), |
|
32 | 32 | "color" => "danger", |
33 | 33 | "title" => $message, |
34 | 34 | 'fallback' => 'PSFS Error notifier', |