Passed
Branch master (591975)
by Brayan
02:03
created
Ocrend/Kernel/Models/Models.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
  * @author Brayan Narváez <[email protected]>
21 21
  */
22 22
 
23
-abstract class Models  {
23
+abstract class Models {
24 24
 
25 25
     /**
26 26
       * Tiene siempre el id pasado por la ruta, en caso de no haber ninguno, será cero.
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
         global $session, $config;
54 54
         
55 55
         # Id captado por la ruta
56
-        if(null != $router) {
56
+        if (null != $router) {
57 57
             $this->id = $router->getId(true);
58 58
             $this->id = null == $this->id ? 0 : $this->id; 
59 59
         }
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
         $this->functions = new Functions();
63 63
 
64 64
         # Verificar sesión del usuario
65
-        if(null !== $session->get('user_id') && $session->get('unique_session') == $config['sessions']['unique']) {
65
+        if (null !== $session->get('user_id') && $session->get('unique_session') == $config['sessions']['unique']) {
66 66
            $this->id_user = $session->get('user_id');
67 67
         }
68 68
     }
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
       * @throws ModelsException
78 78
       */
79 79
     protected function setId($id, string $default_msg = 'No puedede asignarse el id.') {
80
-        if(null == $id || !is_numeric($id) || $id <= 0) {
80
+        if (null == $id || !is_numeric($id) || $id <= 0) {
81 81
             throw new ModelsException($default_msg);
82 82
         }
83 83
 
Please login to merge, or discard this patch.
Ocrend/Kernel/Helpers/Strings.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
     } elseif ($diff->m == 1) {
42 42
         $text = '1 mes';
43 43
     } elseif ($diff->d > 7) {
44
-        $text = ceil($diff->d / 7) . ' semanas';
44
+        $text = ceil($diff->d/7) . ' semanas';
45 45
     } elseif ($diff->d == 7) {
46 46
         $text = '1 semana';
47 47
     } elseif ($diff->d > 1) {
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
     * @return string Hash, con la forma $2a$10$87b2b603324793cc37f8dOPFTnHRY0lviq5filK5cN4aMCQDJcC9G
87 87
   */
88 88
   final public static function hash(string $p) : string {
89
-    return crypt($p, '$2a$10$' . substr(sha1(mt_rand()),0,22));
89
+    return crypt($p, '$2a$10$' . substr(sha1(mt_rand()), 0, 22));
90 90
   }
91 91
   //------------------------------------------------
92 92
   /**
@@ -99,9 +99,9 @@  discard block
 block discarded – undo
99 99
     *
100 100
   */
101 101
   final public static function date_difference(string $ini, string $fin) : int {
102
-    $ini_i = explode('-',str_replace('/','-',$ini));
103
-    $fin_i = explode('-',str_replace('/','-',$fin));
104
-    return (int) floor((mktime(0, 0, 0, $fin_i[1], $fin_i[0], $fin_i[2]) - mktime(0, 0, 0, $ini_i[1], $ini_i[0], $ini_i[2])) / 86400);
102
+    $ini_i = explode('-', str_replace('/', '-', $ini));
103
+    $fin_i = explode('-', str_replace('/', '-', $fin));
104
+    return (int) floor((mktime(0, 0, 0, $fin_i[1], $fin_i[0], $fin_i[2]) - mktime(0, 0, 0, $ini_i[1], $ini_i[0], $ini_i[2]))/86400);
105 105
   }
106 106
   //------------------------------------------------
107 107
   /**
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
     *
114 114
   */
115 115
   final public static function calculate_age(string $cumple) : int {
116
-    $age = explode('.', (string) (self::date_difference($cumple,date('d-m-Y',time())) / 365));
116
+    $age = explode('.', (string) (self::date_difference($cumple, date('d-m-Y', time()))/365));
117 117
     return (int) $age[0];
118 118
   }
119 119
   //------------------------------------------------
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
     *
125 125
   */
126 126
   final public static function days_of_month() : int {
127
-    return cal_days_in_month(CAL_GREGORIAN, (int) date('m',time()), (int) date('Y',time()));
127
+    return cal_days_in_month(CAL_GREGORIAN, (int) date('m', time()), (int) date('Y', time()));
128 128
   }
129 129
   //------------------------------------------------
130 130
   /**
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
     * @return string del texto sin espacios
147 147
   */
148 148
   final public static function remove_spaces(string $s) : string {
149
-    return trim(str_replace(' ','',$s));
149
+    return trim(str_replace(' ', '', $s));
150 150
   }
151 151
   //------------------------------------------------
152 152
   /**
@@ -191,9 +191,9 @@  discard block
 block discarded – undo
191 191
   */
192 192
   final public static function url_amigable(string $url) : string {
193 193
     $url = strtolower($url);
194
-    $url = str_replace (['á', 'é', 'í', 'ó', 'ú', 'ñ'],['a', 'e', 'i', 'o', 'u', 'n'], $url);
195
-    $url = str_replace([' ', '&', '\r\n', '\n', '+', '%'],'-',$url);
196
-    return preg_replace (['/[^a-z0-9\-<>]/', '/[\-]+/', '/<[^>]*>/'],['', '-', ''], $url);
194
+    $url = str_replace(['á', 'é', 'í', 'ó', 'ú', 'ñ'], ['a', 'e', 'i', 'o', 'u', 'n'], $url);
195
+    $url = str_replace([' ', '&', '\r\n', '\n', '+', '%'], '-', $url);
196
+    return preg_replace(['/[^a-z0-9\-<>]/', '/[\-]+/', '/<[^>]*>/'], ['', '-', ''], $url);
197 197
   }
198 198
   //------------------------------------------------
199 199
   /**
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
         '<span style="font-size: $1px">$2</span>',
247 247
         '<span style="font-family: $1">$2</span>'
248 248
     );
249
-    return nl2br(preg_replace($BBcode,$HTML,$string));
249
+    return nl2br(preg_replace($BBcode, $HTML, $string));
250 250
   }
251 251
   //------------------------------------------------
252 252
   /**
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
     * @return int Cantidad de palabras
295 295
   */
296 296
   final public static function count_words(string $s) : int {
297
-    return (int) str_word_count($s,0);
297
+    return (int) str_word_count($s, 0);
298 298
   }
299 299
   //------------------------------------------------
300 300
   /**
Please login to merge, or discard this patch.
Ocrend/Kernel/Helpers/Functions.php 1 patch
Spacing   +38 added lines, -38 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
   final private 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
    //------------------------------------------------
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
   final public function redir($url = null) {
46 46
     global $config;
47 47
     
48
-    if(null == $url) {
48
+    if (null == $url) {
49 49
       $url = $config['site']['url'];
50 50
     }
51 51
     
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
     * @return float con el porcentaje correspondiente
65 65
   */
66 66
   final public function percent(float $por, float $n) : float {
67
-    return $n * ($por / 100);
67
+    return $n*($por/100);
68 68
   }
69 69
 
70 70
   //------------------------------------------------
@@ -77,8 +77,8 @@  discard block
 block discarded – undo
77 77
     * @return string del tamaño $size convertido a la unidad más adecuada
78 78
   */
79 79
   final public function convert(int $size) : string {
80
-      $unit = array('bytes','kb','mb','gb','tb','pb');
81
-      return round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
80
+      $unit = array('bytes', 'kb', 'mb', 'gb', 'tb', 'pb');
81
+      return round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . ' ' . $unit[$i];
82 82
   }
83 83
 
84 84
   //------------------------------------------------
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
      * @return bool con true si está vacío, false si no, un espacio en blanco cuenta como vacío
105 105
    */
106 106
    final public function emp($var) : bool {
107
-     return (isset($var) && empty(trim(str_replace(' ','',$var))));
107
+     return (isset($var) && empty(trim(str_replace(' ', '', $var))));
108 108
    }
109 109
 
110 110
    //------------------------------------------------
@@ -118,8 +118,8 @@  discard block
 block discarded – undo
118 118
      * @return bool con true si están todos llenos, false si al menos uno está vacío
119 119
    */
120 120
    final public function all_full(array $array) : bool {
121
-     foreach($array as $e) {
122
-       if($this->emp($e) and $e != '0') {
121
+     foreach ($array as $e) {
122
+       if ($this->emp($e) and $e != '0') {
123 123
          return false;
124 124
        }
125 125
      }
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
    */
136 136
     final public function e() : bool  {
137 137
       for ($i = 0, $nargs = func_num_args(); $i < $nargs; $i++) {
138
-        if(null === func_get_arg($i) || ($this->emp(func_get_arg($i)) && func_get_arg($i) != '0')) {
138
+        if (null === func_get_arg($i) || ($this->emp(func_get_arg($i)) && func_get_arg($i) != '0')) {
139 139
           return true;
140 140
         }
141 141
       }
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
       * @return string con la fecha en formato humano (y en español)
154 154
     */
155 155
     final public function fecha(string $format, int $time = 0) : string  {
156
-       $date = date($format,$time == 0 ? time() : $time);
156
+       $date = date($format, $time == 0 ? time() : $time);
157 157
        $cambios = array(
158 158
          'Monday'=> 'Lunes',
159 159
          'Tuesday'=> 'Martes',
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
          'Apr'=> 'Abr',
187 187
          'Dec'=> 'Dic'
188 188
        );
189
-       return str_replace(array_keys($cambios),array_values($cambios),$date);
189
+       return str_replace(array_keys($cambios), array_values($cambios), $date);
190 190
      }
191 191
 
192 192
    //------------------------------------------------
@@ -206,13 +206,13 @@  discard block
 block discarded – undo
206 206
     # Revisar protocolo
207 207
     $base = $config['site']['router']['protocol'] . '://';
208 208
 
209
-    if(strtolower($www) == 'www') {
209
+    if (strtolower($www) == 'www') {
210 210
       $base .= 'www.' . $config['site']['router']['path'];
211 211
     } else {
212 212
       $base .= $config['site']['router']['path'];
213 213
     }
214 214
   
215
-    return '<base href="'.$base.'" />';
215
+    return '<base href="' . $base . '" />';
216 216
   }
217 217
   
218 218
   //------------------------------------------------
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
    * @return string con el número del día
227 227
   */
228 228
   final public function last_day_month(int $mes, int $anio) : string {
229
-    return date('d', (mktime(0,0,0,$mes + 1, 1, $anio) - 1));
229
+    return date('d', (mktime(0, 0, 0, $mes + 1, 1, $anio) - 1));
230 230
   }
231 231
 
232 232
   //------------------------------------------------
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
    * @return string cifra con cero a la izquirda
240 240
   */
241 241
   final public function cero_izq(int $num) : string {
242
-    if($num < 10) {
242
+    if ($num < 10) {
243 243
       return '0' . $num;
244 244
     }
245 245
 
@@ -257,24 +257,24 @@  discard block
 block discarded – undo
257 257
     * @return int|null con el timestamp
258 258
   */
259 259
   final public function str_to_time($fecha, string $hora = '00:00:00') {
260
-    if(null == $fecha) {
260
+    if (null == $fecha) {
261 261
       return null;
262 262
     }
263 263
     
264
-    $detail = explode('/',$fecha);
264
+    $detail = explode('/', $fecha);
265 265
 
266 266
     // Formato de día incorrecto
267
-    if($this->check_str_to_time(0,$detail,1)) {
267
+    if ($this->check_str_to_time(0, $detail, 1)) {
268 268
       return null;
269 269
     }
270 270
 
271 271
     // Formato de mes incorrecto
272
-    if($this->check_str_to_time(1,$detail,1) || intval($detail[1]) > 12) {
272
+    if ($this->check_str_to_time(1, $detail, 1) || intval($detail[1]) > 12) {
273 273
       return null;
274 274
     }
275 275
 
276 276
     // Formato del año
277
-    if($this->check_str_to_time(2,$detail,1970)) {
277
+    if ($this->check_str_to_time(2, $detail, 1970)) {
278 278
       return null;
279 279
     }
280 280
 
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
     $year = intval($detail[2]);
285 285
 
286 286
     // Veriricar dia según mes
287
-    if($day > $this->last_day_month($month,$year)) {
287
+    if ($day > $this->last_day_month($month, $year)) {
288 288
       return null;
289 289
     }
290 290
 
@@ -302,11 +302,11 @@  discard block
 block discarded – undo
302 302
   */
303 303
   final public function desde_date(int $desde) {
304 304
      # Obtener esta fecha
305
-     $hoy = date('d/m/Y/D',time());
306
-     $hoy = explode('/',$hoy);
305
+     $hoy = date('d/m/Y/D', time());
306
+     $hoy = explode('/', $hoy);
307 307
 
308 308
 
309
-    switch($desde) {
309
+    switch ($desde) {
310 310
       # Hoy
311 311
       case 1:
312 312
         return date('d/m/Y', time());
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
       # Semana
319 319
       case 3:
320 320
         # Día de la semana actual
321
-        switch($hoy[3]) {
321
+        switch ($hoy[3]) {
322 322
           case 'Mon':
323 323
             $dia = $hoy[0];
324 324
           break;
@@ -343,21 +343,21 @@  discard block
 block discarded – undo
343 343
         }
344 344
 
345 345
         # Mes anterior y posiblemente, año también.
346
-        if($dia == 0) {
346
+        if ($dia == 0) {
347 347
           # Verificamos si estamos en enero
348
-          if($hoy[1] == 1) {
349
-            return $this->last_day_month($hoy[1],$hoy[2]) .'/'. $this->cero_izq($hoy[1] - 1) .'/' . ($hoy[2] - 1);
348
+          if ($hoy[1] == 1) {
349
+            return $this->last_day_month($hoy[1], $hoy[2]) . '/' . $this->cero_izq($hoy[1] - 1) . '/' . ($hoy[2] - 1);
350 350
           }
351 351
           
352 352
           # Si no es enero, es el año actual
353
-          return $this->last_day_month($hoy[1],$hoy[2]) .'/'. $this->cero_izq($hoy[1] - 1) .'/' . $hoy[2];
353
+          return $this->last_day_month($hoy[1], $hoy[2]) . '/' . $this->cero_izq($hoy[1] - 1) . '/' . $hoy[2];
354 354
         }
355 355
         
356
-        return $this->cero_izq($dia) .'/'. $this->cero_izq($hoy[1]) .'/' . $hoy[2];
356
+        return $this->cero_izq($dia) . '/' . $this->cero_izq($hoy[1]) . '/' . $hoy[2];
357 357
 
358 358
       # Mes
359 359
       case 4:
360
-        return '01/'. $this->cero_izq($hoy[1]) .'/' . $hoy[2];
360
+        return '01/' . $this->cero_izq($hoy[1]) . '/' . $hoy[2];
361 361
        
362 362
       # Año
363 363
       case 5:
@@ -396,13 +396,13 @@  discard block
 block discarded – undo
396 396
        new \Twig_Function('e_dynamic', array($this, 'e')),
397 397
        new \Twig_Function('all_full', array($this, 'all_full')),
398 398
        new \Twig_Function('fecha', array($this, 'fecha')),
399
-       new \Twig_Function('base_assets',array($this, 'base_assets')),
400
-       new \Twig_Function('timestamp',array($this, 'timestamp')),
401
-       new \Twig_Function('desde_date',array($this, 'desde_date')),
402
-       new \Twig_Function('cero_izq',array($this, 'cero_izq')),
403
-       new \Twig_Function('last_day_month',array($this, 'last_day_month')),
404
-       new \Twig_Function('str_to_time',array($this, 'str_to_time')),
405
-       new \Twig_Function('desde_date',array($this, 'desde_date'))
399
+       new \Twig_Function('base_assets', array($this, 'base_assets')),
400
+       new \Twig_Function('timestamp', array($this, 'timestamp')),
401
+       new \Twig_Function('desde_date', array($this, 'desde_date')),
402
+       new \Twig_Function('cero_izq', array($this, 'cero_izq')),
403
+       new \Twig_Function('last_day_month', array($this, 'last_day_month')),
404
+       new \Twig_Function('str_to_time', array($this, 'str_to_time')),
405
+       new \Twig_Function('desde_date', array($this, 'desde_date'))
406 406
      );
407 407
    }
408 408
 
Please login to merge, or discard this patch.
Ocrend/Kernel/Helpers/Files.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
     * @return int catidad de bytes escritos en el archivo
49 49
   */
50 50
   final public static function write_file(string $dir, string $content) : int {
51
-    $f = new \SplFileObject($dir,'w');
51
+    $f = new \SplFileObject($dir, 'w');
52 52
     return (int) $f->fwrite($content);
53 53
   }
54 54
 
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
     * @return bool true si borró el fichero, false si no (porque no existía)
63 63
   */
64 64
   final public static function delete_file(string $route) : bool {
65
-    if(file_exists($route)) {
65
+    if (file_exists($route)) {
66 66
       unlink($route);
67 67
 
68 68
       return true;
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
     * @return bool true si es una imagen, false si no lo es
95 95
   */
96 96
   final public static function is_image(string $file_name) : bool {
97
-    return (bool) in_array(self::get_file_ext($file_name),['jpg','png','jpeg','gif','JPG','PNG','JPEG','GIF']);
97
+    return (bool) in_array(self::get_file_ext($file_name), ['jpg', 'png', 'jpeg', 'gif', 'JPG', 'PNG', 'JPEG', 'GIF']);
98 98
   }
99 99
 
100 100
   //------------------------------------------------
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
   */
136 136
   final public static function get_files_in_dir(string $dir, string $types = '') : array {
137 137
     $array = array();
138
-    if(is_dir($dir)) {
138
+    if (is_dir($dir)) {
139 139
       foreach (glob($dir . '*' . $types) as $file) {
140 140
         $array[] = $file;
141 141
       }
@@ -154,11 +154,11 @@  discard block
 block discarded – undo
154 154
     * @return bool con true si fue creado con éxito, false si el directorio ya existía o hubo algún error
155 155
   */
156 156
   final public static function create_dir(string $dir, int $permisos = 0755) : bool {
157
-    if(is_dir($dir)) {
157
+    if (is_dir($dir)) {
158 158
       return false;
159 159
     }
160 160
     
161
-    return (bool) mkdir($dir,$permisos,true);
161
+    return (bool) mkdir($dir, $permisos, true);
162 162
   }
163 163
 
164 164
   //------------------------------------------------
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
   final public static function rm_dir(string $dir) {
176 176
 
177 177
     # Evitar una desgracia
178
-    if(in_array($dir,[
178
+    if (in_array($dir, [
179 179
       'Ocrend/',
180 180
       'Ocrend/Kernel/',
181 181
       'Ocrend/vendor/',
@@ -188,10 +188,10 @@  discard block
 block discarded – undo
188 188
       throw new \RuntimeException('No puede eliminar la ruta ' . $dir . ' ya que es crítica.');
189 189
     }
190 190
 
191
-    foreach(glob($dir . "/*") as $archivos_carpeta)   { 
192
-        if (is_dir($archivos_carpeta))   {
191
+    foreach (glob($dir . "/*") as $archivos_carpeta) { 
192
+        if (is_dir($archivos_carpeta)) {
193 193
             self::rm_dir($archivos_carpeta);
194
-        } else  {
194
+        } else {
195 195
             unlink($archivos_carpeta);
196 196
         }
197 197
     }
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
     * @return int cantidad de  imágenes
211 211
   */
212 212
   final public static function images_in_dir(string $dir) : int {
213
-    return sizeof(glob($dir . '{*.jpg,*.gif,*.png,*.gif,*.jpeg,*.JPG,*.GIF,*.PNG,*.JPEG}',GLOB_BRACE));
213
+    return sizeof(glob($dir . '{*.jpg,*.gif,*.png,*.gif,*.jpeg,*.JPG,*.GIF,*.PNG,*.JPEG}', GLOB_BRACE));
214 214
   }
215 215
 
216 216
   //------------------------------------------------
@@ -230,16 +230,16 @@  discard block
 block discarded – undo
230 230
 
231 231
     self::create_dir($new_dir);
232 232
 
233
-    foreach(glob($old_dir . ($only_images ? '{*.jpg,*.gif,*.png,*.gif,*.jpeg,*.JPG,*.GIF,*.PNG,*.JPEG}' : '*'),GLOB_BRACE) as $file) {
234
-      if(file_exists($file)) {
233
+    foreach (glob($old_dir . ($only_images ? '{*.jpg,*.gif,*.png,*.gif,*.jpeg,*.JPG,*.GIF,*.PNG,*.JPEG}' : '*'), GLOB_BRACE) as $file) {
234
+      if (file_exists($file)) {
235 235
           unlink($file);
236 236
       }
237 237
       
238
-      $name = explode('/',$file);
238
+      $name = explode('/', $file);
239 239
       $name = end($name);
240
-      copy($file,$new_dir . $name);
240
+      copy($file, $new_dir . $name);
241 241
 
242
-      if($delete_old) {
242
+      if ($delete_old) {
243 243
         unlink($file);
244 244
       }
245 245
     }
Please login to merge, or discard this patch.