Passed
Branch master (313f25)
by Brayan
04:26 queued 01:59
created
app/models/Users.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -123,10 +123,10 @@  discard block
 block discarded – undo
123 123
         $cookie->set('session_hash', md5(time()), $config['sessions']['user_cookie']['lifetime']);
124 124
         
125 125
         # Generar la sesión del usuario
126
-        $session->set($cookie->get('session_hash') . '__user_id',(int) $user_data['id_user']);
126
+        $session->set($cookie->get('session_hash') . '__user_id', (int) $user_data['id_user']);
127 127
 
128 128
         # Generar data encriptada para prolongar la sesión
129
-        if($config['sessions']['user_cookie']['enable']) {
129
+        if ($config['sessions']['user_cookie']['enable']) {
130 130
             # Generar id encriptado
131 131
             $encrypt = Helper\Strings::ocrend_encode($user_data['id_user'], $config['sessions']['user_cookie']['key_encrypt']);
132 132
 
@@ -145,12 +145,12 @@  discard block
 block discarded – undo
145 145
      * @return bool true: Cuando el inicio de sesión es correcto 
146 146
      *              false: Cuando el inicio de sesión no es correcto
147 147
      */
148
-    private function authentication(string $email,string $pass) : bool {
148
+    private function authentication(string $email, string $pass) : bool {
149 149
         $email = $this->db->scape($email);
150
-        $query = $this->db->select('id_user,pass','users',null, "email='$email'",1);
150
+        $query = $this->db->select('id_user,pass', 'users', null, "email='$email'", 1);
151 151
         
152 152
         # Incio de sesión con éxito
153
-        if(false !== $query && Helper\Strings::chash($query[0]['pass'],$pass)) {
153
+        if (false !== $query && Helper\Strings::chash($query[0]['pass'], $pass)) {
154 154
 
155 155
             # Restaurar intentos
156 156
             $this->restoreAttempts($email);
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
      * @return false|array con información del usuario
233 233
      */   
234 234
     public function getUserById(int $id, string $select = '*') {
235
-        return $this->db->select($select,'users',null,"id_user='$id'",1);
235
+        return $this->db->select($select, 'users', null, "id_user='$id'", 1);
236 236
     }
237 237
     
238 238
     /**
@@ -255,12 +255,12 @@  discard block
 block discarded – undo
255 255
      * @return array con datos del usuario conectado
256 256
      */
257 257
     public function getOwnerUser(string $select = '*') : array {
258
-        if(null !== $this->id_user) {    
258
+        if (null !== $this->id_user) {    
259 259
                
260
-            $user = $this->db->select($select,'users',null, "id_user='$this->id_user'",1);
260
+            $user = $this->db->select($select, 'users', null, "id_user='$this->id_user'", 1);
261 261
 
262 262
             # Si se borra al usuario desde la base de datos y sigue con la sesión activa
263
-            if(false === $user) {
263
+            if (false === $user) {
264 264
                 $this->logout();
265 265
             }
266 266
 
@@ -385,18 +385,18 @@  discard block
 block discarded – undo
385 385
             # Generar token y contraseña 
386 386
             $token = md5(time());
387 387
             $pass = uniqid();
388
-            $link = $config['build']['url'] . 'lostpass?token='.$token.'&user='.$user_data[0]['id_user'];
388
+            $link = $config['build']['url'] . 'lostpass?token=' . $token . '&user=' . $user_data[0]['id_user'];
389 389
 
390 390
             # Construir mensaje y enviar mensaje
391
-            $HTML = 'Hola <b>'. $user_data[0]['name'] .'</b>, ha solicitado recuperar su contraseña perdida, si no ha realizado esta acción no necesita hacer nada.
391
+            $HTML = 'Hola <b>' . $user_data[0]['name'] . '</b>, ha solicitado recuperar su contraseña perdida, si no ha realizado esta acción no necesita hacer nada.
392 392
 					<br />
393 393
 					<br />
394
-					Para cambiar su contraseña por <b>'. $pass .'</b> haga <a href="'. $link .'" target="_blank">clic aquí</a> o en el botón de recuperar.';
394
+					Para cambiar su contraseña por <b>'. $pass . '</b> haga <a href="' . $link . '" target="_blank">clic aquí</a> o en el botón de recuperar.';
395 395
 
396 396
             # Enviar el correo electrónico
397 397
             $dest = array();
398 398
 			$dest[$email] = $user_data[0]['name'];
399
-            $email_send = Helper\Emails::send($dest,array(
399
+            $email_send = Helper\Emails::send($dest, array(
400 400
                 # Título del mensaje
401 401
                 '{{title}}' => 'Recuperar contraseña de ' . $config['build']['name'],
402 402
                 # Url de logo
@@ -410,23 +410,23 @@  discard block
 block discarded – undo
410 410
                 # Texto del boton
411 411
                 '{{btn-name}}' => 'Recuperar Contraseña',
412 412
                 # Copyright
413
-                '{{copyright}}' => '&copy; '.date('Y') .' <a href="'.$config['build']['url'].'">'.$config['build']['name'].'</a> - Todos los derechos reservados.'
414
-              ),0);
413
+                '{{copyright}}' => '&copy; ' . date('Y') . ' <a href="' . $config['build']['url'] . '">' . $config['build']['name'] . '</a> - Todos los derechos reservados.'
414
+              ), 0);
415 415
 
416 416
             # Verificar si hubo algún problema con el envío del correo
417
-            if(false === $email_send) {
417
+            if (false === $email_send) {
418 418
                 throw new ModelsException('No se ha podido enviar el correo electrónico.');
419 419
             }
420 420
 
421 421
             # Actualizar datos 
422 422
             $id_user = $user_data[0]['id_user'];
423
-            $this->db->update('users',array(
423
+            $this->db->update('users', array(
424 424
                 'tmp_pass' => Helper\Strings::hash($pass),
425 425
                 'token' => $token
426
-            ),"id_user='$id_user'",1);
426
+            ), "id_user='$id_user'", 1);
427 427
 
428 428
             return array('success' => 1, 'message' => 'Se ha enviado un enlace a su correo electrónico.');
429
-        } catch(ModelsException $e) {
429
+        } catch (ModelsException $e) {
430 430
             return array('success' => 0, 'message' => $e->getMessage());
431 431
         }
432 432
     }
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
         global $session, $cookie;
441 441
 	    
442 442
         $session->remove($cookie->get('session_hash') . '__user_id');
443
-        foreach($cookie->all() as $name => $value) {
443
+        foreach ($cookie->all() as $name => $value) {
444 444
             $cookie->remove($name);
445 445
         }
446 446
 
Please login to merge, or discard this patch.
Ocrend/Kernel/Router/Router.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
     /**
110 110
      * Verifica las peticiones por defecto
111 111
     */
112
-    final private function checkRequests()  {
112
+    final private function checkRequests() {
113 113
         # Verificar si existe peticiones
114 114
         if (null !== $this->requestUri) {
115 115
             $this->real_request = explode('/', $this->requestUri);
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
      *
130 130
      * @throws \RuntimeException si no puede definirse la ruta
131 131
     */
132
-    final public function setRoute(string $index, string $rule = 'none')  {
132
+    final public function setRoute(string $index, string $rule = 'none') {
133 133
         # Nombres de rutas no permitidos
134 134
         if (in_array($index, ['/controller', '/method', '/id'])) {
135 135
             throw new \RuntimeException('No puede definirse ' . $index . ' como índice en la ruta.');
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
      * 
220 220
      * @return void
221 221
      */
222
-    final private function loadController()  {
222
+    final private function loadController() {
223 223
         # Definir controlador
224 224
         if (null != ($controller = $this->getController())) {
225 225
             $controller = $controller . 'Controller';
@@ -258,15 +258,15 @@  discard block
 block discarded – undo
258 258
      * 
259 259
      * @return void
260 260
      */
261
-    final public function executeController()  {
261
+    final public function executeController() {
262 262
         global $config;
263 263
 
264
-        if($config['build']['production']) {
264
+        if ($config['build']['production']) {
265 265
             try {
266 266
                 $this->loadController();
267
-            } catch(\Throwable $e) {
267
+            } catch (\Throwable $e) {
268 268
                 $this->productionError();
269
-            } catch(\Exception $e) {
269
+            } catch (\Exception $e) {
270 270
                 $this->productionError();
271 271
             }
272 272
         } else {
Please login to merge, or discard this patch.
Ocrend/Kernel/Helpers/Files.php 2 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
    * @param string $file_name: Nombre del archivo, da igual si es solo el nombre o la ruta con el nombre
86 86
    *
87 87
    * @return mixed string con la extensión, devuelve un string '' si no existe información alguna acerca de la extensión
88
-  */
88
+   */
89 89
   public static function get_file_ext(string $file_name) {
90 90
     return pathinfo($file_name, PATHINFO_EXTENSION);
91 91
   }
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
    * @param string $file_name: Nombre del archivo, da igual si es solo el nombre o la ruta con el nombre
97 97
    *
98 98
    * @return bool true si es una imagen, false si no lo es
99
-  */
99
+   */
100 100
   public static function is_image(string $file_name) : bool {
101 101
     return (bool) in_array(self::get_file_ext($file_name), ['jpg', 'png', 'jpeg', 'gif', 'JPG', 'PNG', 'JPEG', 'GIF']);
102 102
   }
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
    * @return int con el tamaño del fichero
110 110
    */
111 111
   public static function file_size(string $file) : int {
112
-  	return (int) round(filesize($file)*0.0009765625, 1);
112
+    return (int) round(filesize($file)*0.0009765625, 1);
113 113
   }
114 114
 
115 115
   /**
@@ -118,9 +118,9 @@  discard block
 block discarded – undo
118 118
    * @param string $file: path del fichero
119 119
    *
120 120
    * @return string con la fecha del fichero en el formato d-m-y h:i:s
121
-  */
121
+   */
122 122
   public static function date_file(string $file) : string {
123
-  	return date('d-m-Y h:i:s', filemtime($file));
123
+    return date('d-m-Y h:i:s', filemtime($file));
124 124
   }
125 125
 
126 126
   /**
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
    * @param string $types: tipos de archivos a buscar, por defecto '' significa todos, se puede pasar por ejemplo 'jpg'
131 131
    *
132 132
    * @return array con las rutas de todos los ficheros encontrados, un array vacío si no encontró ficheros
133
-  */
133
+   */
134 134
   public static function get_files_in_dir(string $dir, string $types = '') : array {
135 135
     $array = array();
136 136
     if (is_dir($dir)) {
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
    * @param int $permisos: Permisos del directorio a crear, por defecto es 0655
149 149
    *
150 150
    * @return bool con true si fue creado con éxito, false si el directorio ya existía o hubo algún error
151
-  */
151
+   */
152 152
   public static function create_dir(string $dir, int $permisos = 0655) : bool {
153 153
     if(is_dir($dir)) {
154 154
       return false;
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
    * @return int catidad de bytes escritos en el archivo
46 46
    */
47 47
   public static function write_file(string $dir, string $content) : int {
48
-    $f = new \SplFileObject($dir,'w');
48
+    $f = new \SplFileObject($dir, 'w');
49 49
     return (int) $f->fwrite($content);
50 50
   }
51 51
 
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
    * @return int : catidad de bytes escritos en el archivo
59 59
    */
60 60
   public static function write_in_file(string $dir, string $content) : int {
61
-    $f = new \SplFileObject($dir,'a+');
61
+    $f = new \SplFileObject($dir, 'a+');
62 62
     return (int) $f->fwrite("\n\r" . $content);
63 63
   }
64 64
 
@@ -150,11 +150,11 @@  discard block
 block discarded – undo
150 150
    * @return bool con true si fue creado con éxito, false si el directorio ya existía o hubo algún error
151 151
   */
152 152
   public static function create_dir(string $dir, int $permisos = 0655) : bool {
153
-    if(is_dir($dir)) {
153
+    if (is_dir($dir)) {
154 154
       return false;
155 155
     }
156 156
     
157
-    return (bool) mkdir($dir,$permisos,true);
157
+    return (bool) mkdir($dir, $permisos, true);
158 158
   }
159 159
 
160 160
 
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
    *
227 227
    * @return void
228 228
    */
229
-  public static function move_from_dir(string $old_dir, string $new_dir, bool $only_images = false, bool $delete_old = false)  {
229
+  public static function move_from_dir(string $old_dir, string $new_dir, bool $only_images = false, bool $delete_old = false) {
230 230
     self::create_dir($new_dir);
231 231
 
232 232
     foreach (glob($old_dir . ($only_images ? '{*.jpg,*.gif,*.png,*.gif,*.jpeg,*.JPG,*.GIF,*.PNG,*.JPEG}' : '*'), GLOB_BRACE) as $file) {
Please login to merge, or discard this patch.
Ocrend/Kernel/Helpers/Arrays.php 2 patches
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -94,12 +94,12 @@  discard block
 block discarded – undo
94 94
   }
95 95
 
96 96
   /**
97
-    * Evalúa si un arreglo es de tipo asociativo o no
98
-    *
99
-    * @param array $a: Arreglo a evaluar
100
-    *
101
-    * @return bool false si no lo es, true si lo es
102
-  */
97
+   * Evalúa si un arreglo es de tipo asociativo o no
98
+   *
99
+   * @param array $a: Arreglo a evaluar
100
+   *
101
+   * @return bool false si no lo es, true si lo es
102
+   */
103 103
   public static function is_assoc(array $a) : bool {
104 104
     if (sizeof($a) == 0) {
105 105
       return false;
@@ -109,36 +109,36 @@  discard block
 block discarded – undo
109 109
   }
110 110
 
111 111
   /**
112
-    * Evalúa si un arreglo es secuencial (de índices numéricos)
113
-    *
114
-    * @param array $a: Arreglo a evaluar
115
-    *
116
-    * @return bool false si no lo es, true si lo es
117
-  */
112
+   * Evalúa si un arreglo es secuencial (de índices numéricos)
113
+   *
114
+   * @param array $a: Arreglo a evaluar
115
+   *
116
+   * @return bool false si no lo es, true si lo es
117
+   */
118 118
   public static function is_numeric_array(array $a) : bool {
119 119
     return !self::is_assoc($a);
120 120
   }
121 121
 
122 122
   /**
123
-    * Obtiene de forma random un elemento de un arreglo
124
-    *
125
-    * @param array $a: Arreglo a evaluar
126
-    *
127
-    * @return mixed elemento random dentro del arreglo
128
-  */
123
+   * Obtiene de forma random un elemento de un arreglo
124
+   *
125
+   * @param array $a: Arreglo a evaluar
126
+   *
127
+   * @return mixed elemento random dentro del arreglo
128
+   */
129 129
   public static function array_random_element(array $a) {
130 130
     return $a[array_rand($a)];
131 131
   }
132 132
 
133 133
   /**
134
-    * Ordena una matriz de mayor a menor, o menor a mayor por el valor de un campo específico
135
-    *
136
-    * @param array $toOrderArray : Arreglo a evaluar
137
-    * @param string $field: Campo por el que se va a ordenar
138
-    * @param bool $inverse: Por defecto falso, cambia el orden
139
-    *
140
-    * @return mixed elemento random dentro del arreglo
141
-  */
134
+   * Ordena una matriz de mayor a menor, o menor a mayor por el valor de un campo específico
135
+   *
136
+   * @param array $toOrderArray : Arreglo a evaluar
137
+   * @param string $field: Campo por el que se va a ordenar
138
+   * @param bool $inverse: Por defecto falso, cambia el orden
139
+   *
140
+   * @return mixed elemento random dentro del arreglo
141
+   */
142 142
   public static function order_multi_dimensional(array $toOrderArray, string $field, bool $inverse = false) : array {
143 143
     $position = array();
144 144
     $newRow = array();
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -143,7 +143,7 @@
 block discarded – undo
143 143
     $position = array();
144 144
     $newRow = array();
145 145
     foreach ($toOrderArray as $key => $row) {
146
-      $position[$key]  = $row[$field];
146
+      $position[$key] = $row[$field];
147 147
       $newRow[$key] = $row;
148 148
     }
149 149
     $inverse ? arsort($position) : asort($position);
Please login to merge, or discard this patch.
Ocrend/Kernel/Helpers/Functions.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
    * @return bool con el resultado de la comparación
30 30
   */
31 31
   private static function check_str_to_time(int $index, array $detail, int $max) : bool {
32
-    return !array_key_exists($index,$detail) || !is_numeric($detail[$index]) || intval($detail[$index]) < $max;
32
+    return !array_key_exists($index, $detail) || !is_numeric($detail[$index]) || intval($detail[$index]) < $max;
33 33
   }
34 34
 
35 35
   /**
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
    * @return bool
41 41
   */
42 42
   private static function check_time(array $detail) : bool {
43
-    return self::check_str_to_time(0,$detail,1) || self::check_str_to_time(1,$detail,1) || intval($detail[1]) > 12 || self::check_str_to_time(2,$detail,1970);
43
+    return self::check_str_to_time(0, $detail, 1) || self::check_str_to_time(1, $detail, 1) || intval($detail[1]) > 12 || self::check_str_to_time(2, $detail, 1970);
44 44
   }
45 45
 
46 46
   /**
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
   *
52 52
   * @return void
53 53
   */
54
-  public static function redir($url = null)  {
54
+  public static function redir($url = null) {
55 55
     global $config;
56 56
     
57 57
     if (null == $url) {
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
    * @return bool con true si está vacío, false si no, un espacio en blanco cuenta como vacío
106 106
    */
107 107
   public static function emp($var) : bool {
108
-    return (null === $var || empty(trim(str_replace(' ','',$var))));
108
+    return (null === $var || empty(trim(str_replace(' ', '', $var))));
109 109
   }
110 110
 
111 111
    //------------------------------------------------
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
      * @return bool con true si están todos llenos, false si al menos uno está vacío
120 120
    */
121 121
    public static function all_full(array $array) : bool {
122
-     foreach($array as $e) {
123
-       if(self::emp($e) and $e != '0') {
122
+     foreach ($array as $e) {
123
+       if (self::emp($e) and $e != '0') {
124 124
          return false;
125 125
        }
126 126
      }
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
   */
135 135
   public static function e() : bool  {
136 136
     for ($i = 0, $nargs = func_num_args(); $i < $nargs; $i++) {
137
-      if(self::emp(func_get_arg($i)) && func_get_arg($i) != '0') {
137
+      if (self::emp(func_get_arg($i)) && func_get_arg($i) != '0') {
138 138
         return true;
139 139
       }
140 140
     }
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
    * @return string con la fecha en formato humano (y en español)
153 153
   */
154 154
   public static function fecha(string $format, int $time = 0) : string  {
155
-    $date = date($format,$time == 0 ? time() : $time);
155
+    $date = date($format, $time == 0 ? time() : $time);
156 156
     $cambios = array(
157 157
          'Monday'=> 'Lunes',
158 158
          'Tuesday'=> 'Martes',
@@ -199,9 +199,9 @@  discard block
 block discarded – undo
199 199
 
200 200
     # Revisar protocolo
201 201
     $https = 'http://';
202
-    if($config['router']['ssl']) {
202
+    if ($config['router']['ssl']) {
203 203
       # Revisar el protocolo
204
-      if(true == $http->server->get('HTTPS')
204
+      if (true == $http->server->get('HTTPS')
205 205
         || $http->server->get('HTTPS') == 'on' 
206 206
         || $http->server->get('HTTPS') == 1) {
207 207
         $https = 'https://';
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 
211 211
     # Revisar el path
212 212
     $path = $config['router']['path'];
213
-    if('/' != substr($path, -1)) {
213
+    if ('/' != substr($path, -1)) {
214 214
       $path .= '/';
215 215
     }
216 216
 
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
    * @return string con el número del día
234 234
   */
235 235
   public static function last_day_month(int $mes, int $anio) : string {
236
-    return date('d', (mktime(0,0,0,$mes + 1, 1, $anio) - 1));
236
+    return date('d', (mktime(0, 0, 0, $mes + 1, 1, $anio) - 1));
237 237
   }
238 238
   
239 239
   /**
@@ -256,10 +256,10 @@  discard block
 block discarded – undo
256 256
    * @return int|null con el timestamp
257 257
    */
258 258
   public static function str_to_time($fecha, string $hora = '00:00:00') {
259
-    $detail = explode('/',$fecha ?? '');
259
+    $detail = explode('/', $fecha ?? '');
260 260
 
261 261
     // Formato de día incorrecto, mes y año incorrectos
262
-    if(self::check_time($detail)) {
262
+    if (self::check_time($detail)) {
263 263
       return null;
264 264
     }
265 265
 
@@ -301,21 +301,21 @@  discard block
 block discarded – undo
301 301
          'Sat' => intval($hoy[0]) - 5,
302 302
          'Sun' => intval($hoy[0]) - 6
303 303
        ),
304
-       4 => '01/'. self::cero_izq($hoy[1]) .'/' . $hoy[2],
304
+       4 => '01/' . self::cero_izq($hoy[1]) . '/' . $hoy[2],
305 305
        5 => '01/01/' . $hoy[2]
306 306
     );
307 307
 
308
-    if($desde == 3) {
308
+    if ($desde == 3) {
309 309
       # Dia actual
310 310
       $dia = $fecha[3][$hoy[3]];
311 311
 
312 312
       # Mes anterior y posiblemente, año también.
313
-      if($dia == 0) {
313
+      if ($dia == 0) {
314 314
         # Restante de la fecha
315
-        $real_fecha = self::last_day_month($hoy[1],$hoy[2]) .'/'. self::cero_izq($hoy[1] - 1) .'/';
315
+        $real_fecha = self::last_day_month($hoy[1], $hoy[2]) . '/' . self::cero_izq($hoy[1] - 1) . '/';
316 316
 
317 317
         # Verificamos si estamos en enero
318
-        if($hoy[1] == 1) {
318
+        if ($hoy[1] == 1) {
319 319
           return  $real_fecha . ($hoy[2] - 1);
320 320
         }
321 321
         
@@ -323,8 +323,8 @@  discard block
 block discarded – undo
323 323
         return $real_fecha . $hoy[2];
324 324
       }
325 325
       
326
-      return self::cero_izq($dia) .'/'. self::cero_izq($hoy[1]) .'/' . $hoy[2];
327
-    } else if(array_key_exists($desde,$fecha)) {
326
+      return self::cero_izq($dia) . '/' . self::cero_izq($hoy[1]) . '/' . $hoy[2];
327
+    } else if (array_key_exists($desde, $fecha)) {
328 328
       return $fecha[$desde];
329 329
     }
330 330
 
Please login to merge, or discard this patch.