Completed
Push — master ( dd35d7...142840 )
by Agel_Nash
02:43
created
assets/lib/APIHelpers.class.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
      * @license    GNU General Public License (GPL), http://www.gnu.org/copyleft/gpl.html
81 81
      * @param string $email проверяемый email
82 82
      * @param boolean $dns проверять ли DNS записи
83
-     * @return boolean Результат проверки почтового ящика
83
+     * @return false|string Результат проверки почтового ящика
84 84
      * @author Anton Shevchuk
85 85
      */
86 86
     public static function emailValidate($email, $dns = true)
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
     }
156 156
 
157 157
     /**
158
-     * @param $data
158
+     * @param string $data
159 159
      * @return bool|false|string
160 160
      */
161 161
     private static function _getEnv($data)
Please login to merge, or discard this patch.
Braces   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -3,16 +3,16 @@  discard block
 block discarded – undo
3 3
 /**
4 4
  * Class APIhelpers
5 5
  */
6
-class APIhelpers
7
-{
6
+class APIhelpers
7
+{
8 8
     /**
9 9
      * Преобразует первый символ в нижний регистр
10 10
      * @param $str
11 11
      * @param string $encoding - кодировка, по-умолчанию UTF-8
12 12
      * @return string
13 13
      */
14
-    public static function mb_lcfirst($str, $encoding = 'UTF-8')
15
-    {
14
+    public static function mb_lcfirst($str, $encoding = 'UTF-8')
15
+    {
16 16
         return mb_strtolower(mb_substr($str, 0, 1, $encoding), $encoding) . mb_substr($str, 1, mb_strlen($str),
17 17
             $encoding);
18 18
     }
@@ -23,8 +23,8 @@  discard block
 block discarded – undo
23 23
      * @param string $encoding - кодировка, по-умолчанию UTF-8
24 24
      * @return string
25 25
      */
26
-    public static function mb_ucfirst($str, $encoding = 'UTF-8')
27
-    {
26
+    public static function mb_ucfirst($str, $encoding = 'UTF-8')
27
+    {
28 28
         $str = mb_ereg_replace('^[\ ]+', '', $str);
29 29
         $str = mb_strtoupper(mb_substr($str, 0, 1, $encoding), $encoding) . mb_substr($str, 1, mb_strlen($str),
30 30
                 $encoding);
@@ -43,13 +43,13 @@  discard block
 block discarded – undo
43 43
      * @param string $encoding кодировка
44 44
      * @return string
45 45
      */
46
-    public static function mb_trim_word($html, $len, $encoding = 'UTF-8')
47
-    {
46
+    public static function mb_trim_word($html, $len, $encoding = 'UTF-8')
47
+    {
48 48
         $text = trim(preg_replace('|\s+|', ' ', strip_tags($html)));
49 49
         $text = mb_substr($text, 0, $len + 1, $encoding);
50
-        if (mb_substr($text, -1, null, $encoding) == ' ') {
50
+        if (mb_substr($text, -1, null, $encoding) == ' ') {
51 51
             $out = trim($text);
52
-        } else {
52
+        } else {
53 53
             $out = mb_substr($text, 0, mb_strripos($text, ' ', null, $encoding), $encoding);
54 54
         }
55 55
 
@@ -62,10 +62,10 @@  discard block
 block discarded – undo
62 62
      * @param mixed $default null
63 63
      * @return mixed
64 64
      */
65
-    public static function getkey($data, $key, $default = null)
66
-    {
65
+    public static function getkey($data, $key, $default = null)
66
+    {
67 67
         $out = $default;
68
-        if (is_array($data) && (is_int($key) || is_string($key)) && $key !== '' && array_key_exists($key, $data)) {
68
+        if (is_array($data) && (is_int($key) || is_string($key)) && $key !== '' && array_key_exists($key, $data)) {
69 69
             $out = $data[$key];
70 70
         }
71 71
 
@@ -83,16 +83,16 @@  discard block
 block discarded – undo
83 83
      * @return boolean Результат проверки почтового ящика
84 84
      * @author Anton Shevchuk
85 85
      */
86
-    public static function emailValidate($email, $dns = true)
87
-    {
88
-        if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
86
+    public static function emailValidate($email, $dns = true)
87
+    {
88
+        if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
89 89
             list(, $domain) = explode("@", $email, 2);
90
-            if (!$dns || ($dns && checkdnsrr($domain, "MX") && checkdnsrr($domain, "A"))) {
90
+            if (!$dns || ($dns && checkdnsrr($domain, "MX") && checkdnsrr($domain, "A"))) {
91 91
                 $error = false;
92
-            } else {
92
+            } else {
93 93
                 $error = 'dns';
94 94
             }
95
-        } else {
95
+        } else {
96 96
             $error = 'format';
97 97
         }
98 98
 
@@ -125,16 +125,16 @@  discard block
 block discarded – undo
125 125
      * $this->genPass(20,"."); //AMV,>&?J)v55,(^g}Z06
126 126
      * $this->genPass(20,"aaa0aaa.A"); //rtvKja5xb0\KpdiRR1if
127 127
      */
128
-    public static function genPass($len, $data = '')
129
-    {
130
-        if ($data == '') {
128
+    public static function genPass($len, $data = '')
129
+    {
130
+        if ($data == '') {
131 131
             $data = 'Aa0.';
132 132
         }
133 133
         $opt = strlen($data);
134 134
         $pass = array();
135 135
 
136
-        for ($i = $len; $i > 0; $i--) {
137
-            switch ($data[rand(0, ($opt - 1))]) {
136
+        for ($i = $len; $i > 0; $i--) {
137
+            switch ($data[rand(0, ($opt - 1))]) {
138 138
                 case 'A':
139 139
                     $tmp = rand(65, 90);
140 140
                     break;
@@ -158,9 +158,9 @@  discard block
 block discarded – undo
158 158
      * @param $data
159 159
      * @return bool|false|string
160 160
      */
161
-    private static function _getEnv($data)
162
-    {
163
-        switch (true) {
161
+    private static function _getEnv($data)
162
+    {
163
+        switch (true) {
164 164
             case (isset($_SERVER[$data])):
165 165
                 $out = $_SERVER[$data];
166 166
                 break;
@@ -193,10 +193,10 @@  discard block
 block discarded – undo
193 193
      *
194 194
      * @see http://stackoverflow.com/questions/5036443/php-how-to-block-proxies-from-my-site
195 195
      */
196
-    public static function getUserIP($default = '127.0.0.1')
197
-    {
196
+    public static function getUserIP($default = '127.0.0.1')
197
+    {
198 198
         //Порядок условий зависит от приоритетов
199
-        switch (true) {
199
+        switch (true) {
200 200
             case ($tmp = self::_getEnv('HTTP_COMING_FROM')):
201 201
                 $out = $tmp;
202 202
                 break;
@@ -250,8 +250,8 @@  discard block
 block discarded – undo
250 250
             '`'   => '`',
251 251
             '%60' => '`'
252 252
         )
253
-    ) {
254
-        switch (true) {
253
+    ) {
254
+        switch (true) {
255 255
             case is_scalar($data):
256 256
                 $out = str_replace(
257 257
                     array_keys($chars),
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
                 break;
262 262
             case is_array($data):
263 263
                 $out = $data;
264
-                foreach ($out as $key => &$val) {
264
+                foreach ($out as $key => &$val) {
265 265
                     $val = self::sanitarTag($val, $charset, $chars);
266 266
                 }
267 267
                 break;
@@ -277,8 +277,8 @@  discard block
 block discarded – undo
277 277
      * @param string $charset
278 278
      * @return string
279 279
      */
280
-    public static function e($text, $charset = 'UTF-8')
281
-    {
280
+    public static function e($text, $charset = 'UTF-8')
281
+    {
282 282
         return is_scalar($text) ? htmlspecialchars($text, ENT_QUOTES, $charset, false) : '';
283 283
     }
284 284
 
@@ -293,17 +293,17 @@  discard block
 block discarded – undo
293 293
      * @param array $mixArray Примесь символов, которые так же могут использоваться в строке
294 294
      * @return bool
295 295
      */
296
-    public static function checkString($value, $minLen = 1, $alph = array(), $mixArray = array())
297
-    {
296
+    public static function checkString($value, $minLen = 1, $alph = array(), $mixArray = array())
297
+    {
298 298
         $flag = true;
299 299
         $len = mb_strlen($value, 'UTF-8');
300 300
         $value = trim($value);
301
-        if (mb_strlen($value, 'UTF-8') == $len) {
301
+        if (mb_strlen($value, 'UTF-8') == $len) {
302 302
             $data = is_array($mixArray) ? $mixArray : array();
303 303
             $alph = is_array($alph) ? array_unique($alph) : array();
304
-            foreach ($alph as $item) {
304
+            foreach ($alph as $item) {
305 305
                 $item = strtolower($item);
306
-                switch ($item) {
306
+                switch ($item) {
307 307
                     case 'rus':
308 308
                         $data = array_merge($data, array(
309 309
                             'А',
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
                         break;
344 344
                     case 'num':
345 345
                         $tmp = range('0', '9');
346
-                        foreach ($tmp as $t) {
346
+                        foreach ($tmp as $t) {
347 347
                             $data[] = (string)$t;
348 348
                         }
349 349
                         break;
@@ -352,15 +352,15 @@  discard block
 block discarded – undo
352 352
                         break;
353 353
                 }
354 354
             }
355
-            for ($i = 0; $i < $len; $i++) {
355
+            for ($i = 0; $i < $len; $i++) {
356 356
                 $chr = mb_strtoupper(mb_substr($value, $i, 1, 'UTF-8'), 'UTF-8');
357
-                if (!in_array($chr, $data, true)) {
357
+                if (!in_array($chr, $data, true)) {
358 358
                     $flag = false;
359 359
                     break;
360 360
                 }
361 361
             }
362 362
             $flag = ($flag && $len >= $minLen);
363
-        } else {
363
+        } else {
364 364
             $flag = false;
365 365
         }
366 366
 
@@ -377,18 +377,18 @@  discard block
 block discarded – undo
377 377
      * @param string $sep разделитель ключей при склейке многомерных массивов
378 378
      * @return array массив с переименованными ключами
379 379
      */
380
-    public static function renameKeyArr($data, $prefix = '', $suffix = '', $addPS = '.', $sep = '.')
381
-    {
380
+    public static function renameKeyArr($data, $prefix = '', $suffix = '', $addPS = '.', $sep = '.')
381
+    {
382 382
         $out = array();
383
-        if ($prefix == '' && $suffix == '') {
383
+        if ($prefix == '' && $suffix == '') {
384 384
             $out = $data;
385
-        } else {
385
+        } else {
386 386
             $InsertPrefix = ($prefix != '') ? ($prefix . $addPS) : '';
387 387
             $InsertSuffix = ($suffix != '') ? ($addPS . $suffix) : '';
388
-            foreach ($data as $key => $item) {
388
+            foreach ($data as $key => $item) {
389 389
                 $key = $InsertPrefix . $key;
390 390
                 $val = null;
391
-                switch (true) {
391
+                switch (true) {
392 392
                     case is_scalar($item):
393 393
                         $val = $item;
394 394
                         break;
Please login to merge, or discard this patch.