Completed
Push — master ( 4e19e1...12b60c )
by Алексей
02:49
created
src/helpers.php 1 patch
Braces   +60 added lines, -30 removed lines patch added patch discarded remove patch
@@ -109,8 +109,7 @@  discard block
 block discarded – undo
109 109
             if (is_array($value))
110 110
             {
111 111
                 $results = array_merge($results, dot($value, $prepend.$key.'.'));
112
-            }
113
-            else
112
+            } else
114 113
             {
115 114
                 $results[$prepend.$key] = $value;
116 115
             }
@@ -179,7 +178,9 @@  discard block
 block discarded – undo
179 178
     {
180 179
         foreach ($array as $key => $value)
181 180
         {
182
-            if (call_user_func($callback, $key, $value)) return $value;
181
+            if (call_user_func($callback, $key, $value)) {
182
+                return $value;
183
+            }
183 184
         }
184 185
 
185 186
         return value($default);
@@ -267,9 +268,13 @@  discard block
 block discarded – undo
267 268
      */
268 269
     function array_get($array, $key, $default = null)
269 270
     {
270
-        if (is_null($key)) return $array;
271
+        if (is_null($key)) {
272
+            return $array;
273
+        }
271 274
 
272
-        if (isset($array[$key])) return $array[$key];
275
+        if (isset($array[$key])) {
276
+            return $array[$key];
277
+        }
273 278
 
274 279
         foreach (explode('.', $key) as $segment)
275 280
         {
@@ -296,9 +301,13 @@  discard block
 block discarded – undo
296 301
      */
297 302
     function array_has($array, $key)
298 303
     {
299
-        if (empty($array) || is_null($key)) return false;
304
+        if (empty($array) || is_null($key)) {
305
+            return false;
306
+        }
300 307
 
301
-        if (array_key_exists($key, $array)) return true;
308
+        if (array_key_exists($key, $array)) {
309
+            return true;
310
+        }
302 311
 
303 312
         foreach (explode('.', $key) as $segment)
304 313
         {
@@ -353,8 +362,7 @@  discard block
 block discarded – undo
353 362
             if (is_null($key))
354 363
             {
355 364
                 $results[] = $itemValue;
356
-            }
357
-            else
365
+            } else
358 366
             {
359 367
                 $itemKey = data_get($item, $key);
360 368
 
@@ -400,7 +408,9 @@  discard block
 block discarded – undo
400 408
      */
401 409
     function array_set(&$array, $key, $value)
402 410
     {
403
-        if (is_null($key)) return $array = $value;
411
+        if (is_null($key)) {
412
+            return $array = $value;
413
+        }
404 414
 
405 415
         $keys = explode('.', $key);
406 416
 
@@ -440,7 +450,9 @@  discard block
 block discarded – undo
440 450
 
441 451
         foreach ($array as $key => $value)
442 452
         {
443
-            if (call_user_func($callback, $key, $value)) $filtered[$key] = $value;
453
+            if (call_user_func($callback, $key, $value)) {
454
+                $filtered[$key] = $value;
455
+            }
444 456
         }
445 457
 
446 458
         return $filtered;
@@ -517,7 +529,9 @@  discard block
 block discarded – undo
517 529
      */
518 530
     function data_get($target, $key, $default = null)
519 531
     {
520
-        if (is_null($key)) return $target;
532
+        if (is_null($key)) {
533
+            return $target;
534
+        }
521 535
 
522 536
         foreach (explode('.', $key) as $segment)
523 537
         {
@@ -529,8 +543,7 @@  discard block
 block discarded – undo
529 543
                 }
530 544
 
531 545
                 $target = $target[$segment];
532
-            }
533
-            elseif ($target instanceof ArrayAccess)
546
+            } elseif ($target instanceof ArrayAccess)
534 547
             {
535 548
                 if ( ! isset($target[$segment]))
536 549
                 {
@@ -538,8 +551,7 @@  discard block
 block discarded – undo
538 551
                 }
539 552
 
540 553
                 $target = $target[$segment];
541
-            }
542
-            elseif (is_object($target))
554
+            } elseif (is_object($target))
543 555
             {
544 556
                 if ( ! isset($target->{$segment}))
545 557
                 {
@@ -547,8 +559,7 @@  discard block
 block discarded – undo
547 559
                 }
548 560
 
549 561
                 $target = $target->{$segment};
550
-            }
551
-            else
562
+            } else
552 563
             {
553 564
                 return value($default);
554 565
             }
@@ -585,7 +596,9 @@  discard block
 block discarded – undo
585 596
     {
586 597
         foreach ((array) $needles as $needle)
587 598
         {
588
-            if ((string) $needle === substr($haystack, -strlen($needle))) return true;
599
+            if ((string) $needle === substr($haystack, -strlen($needle))) {
600
+                return true;
601
+            }
589 602
         }
590 603
 
591 604
         return false;
@@ -632,7 +645,9 @@  discard block
 block discarded – undo
632 645
      */
633 646
     function object_get($object, $key, $default = null)
634 647
     {
635
-        if (is_null($key) || trim($key) == '') return $object;
648
+        if (is_null($key) || trim($key) == '') {
649
+            return $object;
650
+        }
636 651
 
637 652
         foreach (explode('.', $key) as $segment)
638 653
         {
@@ -709,7 +724,9 @@  discard block
 block discarded – undo
709 724
     {
710 725
         foreach ((array) $needles as $needle)
711 726
         {
712
-            if ($needle != '' && strpos($haystack, $needle) === 0) return true;
727
+            if ($needle != '' && strpos($haystack, $needle) === 0) {
728
+                return true;
729
+            }
713 730
         }
714 731
 
715 732
         return false;
@@ -729,7 +746,9 @@  discard block
 block discarded – undo
729 746
     {
730 747
         foreach ((array) $needles as $needle)
731 748
         {
732
-            if ($needle != '' && strpos($haystack, $needle) !== false) return true;
749
+            if ($needle != '' && strpos($haystack, $needle) !== false) {
750
+                return true;
751
+            }
733 752
         }
734 753
 
735 754
         return false;
@@ -764,7 +783,9 @@  discard block
 block discarded – undo
764 783
      */
765 784
     function str_is($pattern, $value)
766 785
     {
767
-        if ($pattern == $value) return true;
786
+        if ($pattern == $value) {
787
+            return true;
788
+        }
768 789
 
769 790
         $pattern = preg_quote($pattern, '#');
770 791
 
@@ -789,7 +810,9 @@  discard block
 block discarded – undo
789 810
      */
790 811
     function str_limit($value, $limit = 100, $end = '...')
791 812
     {
792
-        if (mb_strlen($value) <= $limit) return $value;
813
+        if (mb_strlen($value) <= $limit) {
814
+            return $value;
815
+        }
793 816
 
794 817
         return rtrim(mb_substr($value, 0, $limit, 'UTF-8')).$end;
795 818
     }
@@ -956,9 +979,13 @@  discard block
 block discarded – undo
956 979
      */
957 980
     function get($array, $key, $default = null)
958 981
     {
959
-        if (is_null($key)) return $array;
982
+        if (is_null($key)) {
983
+            return $array;
984
+        }
960 985
 
961
-        if (isset($array[$key])) return $array[$key];
986
+        if (isset($array[$key])) {
987
+            return $array[$key];
988
+        }
962 989
 
963 990
         foreach (explode('.', $key) as $segment)
964 991
         {
@@ -988,7 +1015,9 @@  discard block
 block discarded – undo
988 1015
      */
989 1016
     function set(&$array, $key, $value)
990 1017
     {
991
-        if (is_null($key)) return $array = $value;
1018
+        if (is_null($key)) {
1019
+            return $array = $value;
1020
+        }
992 1021
 
993 1022
         $keys = explode('.', $key);
994 1023
 
@@ -1031,8 +1060,7 @@  discard block
 block discarded – undo
1031 1060
             if (is_array($value))
1032 1061
             {
1033 1062
                 $results = array_merge($results, dot($value, $prepend.$key.'.'));
1034
-            }
1035
-            else
1063
+            } else
1036 1064
             {
1037 1065
                 $results[$prepend.$key] = $value;
1038 1066
             }
@@ -1056,7 +1084,9 @@  discard block
 block discarded – undo
1056 1084
     {
1057 1085
         foreach ($array as $key => $value)
1058 1086
         {
1059
-            if (call_user_func($callback, $key, $value)) return $value;
1087
+            if (call_user_func($callback, $key, $value)) {
1088
+                return $value;
1089
+            }
1060 1090
         }
1061 1091
 
1062 1092
         return value($default);
Please login to merge, or discard this patch.