Completed
Push — master ( c47543...620fe6 )
by Agel_Nash
05:06
created
src/utils.functions.php 1 patch
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! function_exists('supports_ansi_colors')) {
2
+if (!function_exists('supports_ansi_colors')) {
3 3
     /**
4 4
      * Функция позволяет узнать, поддерживает ли консоль цвета и другое форматирование.
5 5
      * @see: https://gostash.it/ru/stashes/1601-podderzivaet-li-konsol-cveta
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
     }
19 19
 }
20 20
 
21
-if (! function_exists('check_email')) {
21
+if (!function_exists('check_email')) {
22 22
     /**
23 23
      * Проверка строки с email на наличие ошибок
24 24
      * Если e-mail валидный, то в ответ будет получено false
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
     {
35 35
         if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
36 36
             list(, $domain) = explode("@", $email, 2);
37
-            if (! $dns || ($dns && checkdnsrr($domain, "MX") && checkdnsrr($domain, "A"))) {
37
+            if (!$dns || ($dns && checkdnsrr($domain, "MX") && checkdnsrr($domain, "A"))) {
38 38
                 $error = false;
39 39
             } else {
40 40
                 $error = 'dns';
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
     }
48 48
 }
49 49
 
50
-if (! function_exists('generate_password')) {
50
+if (!function_exists('generate_password')) {
51 51
     /**
52 52
      * Генерация пароля
53 53
      *
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
     }
100 100
 }
101 101
 
102
-if (! function_exists('get_gravatar')) {
102
+if (!function_exists('get_gravatar')) {
103 103
     /**
104 104
      * Получение ссылки на аватарку с gravatar
105 105
      *
@@ -109,13 +109,13 @@  discard block
 block discarded – undo
109 109
      */
110 110
     function get_gravatar($email, $size = 32)
111 111
     {
112
-        $url = '//www.gravatar.com/avatar/' . md5(is_scalar($email) ? $email : '') . '?s=' . (int)abs($size);
112
+        $url = '//www.gravatar.com/avatar/' . md5(is_scalar($email) ? $email : '') . '?s=' . (int) abs($size);
113 113
 
114 114
         return $url;
115 115
     }
116 116
 }
117 117
 
118
-if (! function_exists('share_vk')) {
118
+if (!function_exists('share_vk')) {
119 119
     /**
120 120
      * Получение ссылки поделиться для "Вконтакте"
121 121
      *
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
     }
130 130
 }
131 131
 
132
-if (! function_exists('share_ok')) {
132
+if (!function_exists('share_ok')) {
133 133
     /**
134 134
      * Получение ссылки поделиться для "Одноклассников"
135 135
      *
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
     }
146 146
 }
147 147
 
148
-if (! function_exists('share_google')) {
148
+if (!function_exists('share_google')) {
149 149
     /**
150 150
      * Получение ссылки поделиться для "Google+"
151 151
      *
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
     }
159 159
 }
160 160
 
161
-if (! function_exists('share_facebook')) {
161
+if (!function_exists('share_facebook')) {
162 162
     /**
163 163
      * Получение ссылки поделиться для "Facebook"
164 164
      *
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
     }
175 175
 }
176 176
 
177
-if (! function_exists('share_twitter')) {
177
+if (!function_exists('share_twitter')) {
178 178
     /**
179 179
      * Получение ссылки поделиться для "Twitter"
180 180
      *
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
     }
189 189
 }
190 190
 
191
-if (! function_exists('share_mail')) {
191
+if (!function_exists('share_mail')) {
192 192
     /**
193 193
      * Получение ссылки поделиться для "Mail.ru"
194 194
      *
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
     }
203 203
 }
204 204
 
205
-if (! function_exists('share_linkedin')) {
205
+if (!function_exists('share_linkedin')) {
206 206
     /**
207 207
      * Получение ссылки поделиться для "LinkedIN"
208 208
      *
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
     }
217 217
 }
218 218
 
219
-if (! function_exists('qr_code')) {
219
+if (!function_exists('qr_code')) {
220 220
     /**
221 221
      * Генерация QR-кода для строки
222 222
      *
@@ -226,14 +226,14 @@  discard block
 block discarded – undo
226 226
      */
227 227
     function qr_code($str, $size = 230)
228 228
     {
229
-        $size = (int)$size;
229
+        $size = (int) $size;
230 230
         $size = implode("x", [$size, $size]);
231 231
 
232 232
         return '//chart.apis.google.com/chart?cht=qr&chs=' . $size . '&chl=' . (is_scalar($str) ? urlencode($str) : '');
233 233
     }
234 234
 }
235 235
 
236
-if (! function_exists('get_user_ip')) {
236
+if (!function_exists('get_user_ip')) {
237 237
     /**
238 238
      * Получение реального ip текущего пользователя
239 239
      *
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
      */
245 245
     function get_user_ip($out = '127.0.0.1')
246 246
     {
247
-        $_getEnv = function ($data) {
247
+        $_getEnv = function($data) {
248 248
             switch (true) {
249 249
                 case (isset($_SERVER[$data])):
250 250
                     $out = $_SERVER[$data];
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
             case ($tmp = $_getEnv('HTTP_X_FORWARDED_FOR')):
290 290
                 $out = $tmp;
291 291
                 break;
292
-            case (! empty($_SERVER['REMOTE_ADDR'])):
292
+            case (!empty($_SERVER['REMOTE_ADDR'])):
293 293
                 $out = $_SERVER['REMOTE_ADDR'];
294 294
                 break;
295 295
         }
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
     }
300 300
 }
301 301
 
302
-if (! function_exists('whois_query')) {
302
+if (!function_exists('whois_query')) {
303 303
     /**
304 304
      * Получение whois информации о домене
305 305
      * @see http://www.jonasjohn.de/snippets/php/whois-query.htm
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
             "nl"   => "whois.domain-registry.nl"
370 370
         ];
371 371
 
372
-        if (! isset($servers[$ext])) {
372
+        if (!isset($servers[$ext])) {
373 373
             throw new ErrorException('No matching nic server found!');
374 374
         }
375 375
 
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
         // connect to whois server:
381 381
         if ($conn = fsockopen($nic_server, 43)) {
382 382
             fputs($conn, $domain . "\r\n");
383
-            while (! feof($conn)) {
383
+            while (!feof($conn)) {
384 384
                 $output .= fgets($conn, 128);
385 385
             }
386 386
             fclose($conn);
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
     }
393 393
 }
394 394
 
395
-if (! function_exists('copyright')) {
395
+if (!function_exists('copyright')) {
396 396
     /**
397 397
      * Геренатор года для подстановки в копирайты
398 398
      *
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
     }
409 409
 }
410 410
 
411
-if (! function_exists('mime_file')) {
411
+if (!function_exists('mime_file')) {
412 412
     /**
413 413
      * Получение MIME типа файла
414 414
      *
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
     }
457 457
 }
458 458
 
459
-if (! function_exists('image_size')) {
459
+if (!function_exists('image_size')) {
460 460
     /**
461 461
      * Определение размеров картинки
462 462
      *
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
     }
490 490
 }
491 491
 
492
-if (! function_exists('plural')) {
492
+if (!function_exists('plural')) {
493 493
     /**
494 494
      * Определение падежа слова в зависимости от числового значения
495 495
      *
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
     function plural($number, array $titles = [])
501 501
     {
502 502
         $cases = [2, 0, 1, 1, 1, 2];
503
-        $number = abs((int)$number);
503
+        $number = abs((int) $number);
504 504
         $position = ($number % 100 > 4 && $number % 100 < 20) ? 2 : $cases[($number % 10 < 5) ? $number % 10 : 5];
505 505
         $out = isset($titles[$position]) ? $titles[$position] : '';
506 506
 
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
     }
509 509
 }
510 510
 
511
-if (! function_exists('validate_date')) {
511
+if (!function_exists('validate_date')) {
512 512
     /**
513 513
      * Проверка валидности даты
514 514
      *
@@ -533,14 +533,14 @@  discard block
 block discarded – undo
533 533
             $datetime2 = \DateTime::createFromFormat($fromFormat, $date);
534 534
             if ($datetime2 instanceof \DateTime) {
535 535
                 $interval = $datetime1->diff($datetime2);
536
-                $validTime = is_callable($validator) ? (bool)$validator($datetime2, $interval) : true;
536
+                $validTime = is_callable($validator) ? (bool) $validator($datetime2, $interval) : true;
537 537
             }
538 538
         }
539 539
 
540 540
         return $validTime ? $datetime2->format($toFormat) : null;
541 541
     }
542 542
 }
543
-if (! function_exists('format_bytes')) {
543
+if (!function_exists('format_bytes')) {
544 544
     /**
545 545
      * Преобразование из байт в другие порядки (кило, мега, гига) с добавлением префикса
546 546
      *
@@ -551,7 +551,7 @@  discard block
 block discarded – undo
551 551
      */
552 552
     function format_bytes($bytes, $precision = 2, $suffixes = ['Байт', 'Кбайт', 'Мбайт', 'Гбайт', 'Тбайт'])
553 553
     {
554
-        $bytes = (float)$bytes;
554
+        $bytes = (float) $bytes;
555 555
         if (empty($bytes)) {
556 556
             return 0;
557 557
         }
@@ -560,12 +560,12 @@  discard block
 block discarded – undo
560 560
         return trim(
561 561
             round(pow(1024, $base - floor($base)), $precision) .
562 562
             ' ' .
563
-            get_key($suffixes, (int)$base, '', 'is_scalar')
563
+            get_key($suffixes, (int) $base, '', 'is_scalar')
564 564
         );
565 565
     }
566 566
 }
567 567
 
568
-if (! function_exists('format_microtime')) {
568
+if (!function_exists('format_microtime')) {
569 569
     /**
570 570
      * Форматирование microtime времени
571 571
      * @param string $time microtime время
@@ -573,10 +573,10 @@  discard block
 block discarded – undo
573 573
      */
574 574
     function format_microtime($time, $len = 4)
575 575
     {
576
-        return sprintf("%." . (int)$len . "f", $time);
576
+        return sprintf("%." . (int) $len . "f", $time);
577 577
     }
578 578
 }
579
-if (! function_exists('ip_in_range')) {
579
+if (!function_exists('ip_in_range')) {
580 580
     /**
581 581
      * Входит ли указанный IP в заданный диапазон
582 582
      *
@@ -591,7 +591,7 @@  discard block
 block discarded – undo
591 591
     }
592 592
 }
593 593
 
594
-if (! function_exists('make_csv')) {
594
+if (!function_exists('make_csv')) {
595 595
     /**
596 596
      * Формирование правильной CSV строки
597 597
      *
Please login to merge, or discard this patch.