Skip to content
This repository was archived by the owner on Jun 11, 2020. It is now read-only.

Commit 312e59f

Browse files
committed
format all codes
1 parent 5eed96e commit 312e59f

File tree

2 files changed

+51
-53
lines changed

2 files changed

+51
-53
lines changed

src/ArrayHelper.php

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static function toIterator($array): \Traversable
5656
/**
5757
* array data to object
5858
* @param array|\Traversable $array
59-
* @param string $class
59+
* @param string $class
6060
* @return mixed
6161
*/
6262
public static function toObject($array, $class = \stdClass::class)
@@ -78,8 +78,8 @@ public static function toObject($array, $class = \stdClass::class)
7878

7979
/**
8080
* Get Multi - 获取多个, 可以设置默认值
81-
* @param array $data array data
82-
* @param array $needKeys
81+
* @param array $data array data
82+
* @param array $needKeys
8383
* $needKeys = [
8484
* 'name',
8585
* 'password',
@@ -125,7 +125,7 @@ public static function gets(array &$data, array $needKeys = [], $unsetKey = fals
125125
/**
126126
* 递归合并两个多维数组,后面的值将会递归覆盖原来的值
127127
* @param array|null $src
128-
* @param array $new
128+
* @param array $new
129129
* @return array
130130
*/
131131
public static function merge($src, array $new): array
@@ -210,7 +210,7 @@ public static function valueTrim(array $data)
210210
/**
211211
* 不区分大小写检测数据键名是否存在
212212
* @param int|string $key
213-
* @param array $arr
213+
* @param array $arr
214214
* @return bool
215215
*/
216216
public static function keyExists($key, array $arr): bool
@@ -239,13 +239,13 @@ public static function valueToUpper(array $arr): array
239239
/**
240240
* 将数组中的值全部转为大写或小写
241241
* @param array $arr
242-
* @param int $toUpper 1 值大写 0 值小写
242+
* @param int $toUpper 1 值大写 0 值小写
243243
* @return array
244244
*/
245245
public static function changeValueCase($arr, $toUpper = 1): array
246246
{
247247
$function = $toUpper ? 'strtoupper' : 'strtolower';
248-
$newArr = array(); //格式化后的数组
248+
$newArr = []; //格式化后的数组
249249

250250
foreach ($arr as $k => $v) {
251251
if (\is_array($v)) {
@@ -263,7 +263,7 @@ public static function changeValueCase($arr, $toUpper = 1): array
263263
* ******* 检查 一个或多个值是否全部存在数组中 *******
264264
* 有一个不存在即返回 false
265265
* @param string|array $check
266-
* @param array $sampleArr 只能检查一维数组
266+
* @param array $sampleArr 只能检查一维数组
267267
* 注: 不分类型, 区分大小写 2 == '2' ‘a' != 'A'
268268
* @return bool
269269
*/
@@ -272,7 +272,7 @@ public static function valueExistsAll($check, array $sampleArr): bool
272272
// 以逗号分隔的会被拆开,组成数组
273273
if (\is_string($check)) {
274274
$check = trim($check, ', ');
275-
$check = strpos($check, ',') !== false ? explode(',', $check) : array($check);
275+
$check = strpos($check, ',') !== false ? explode(',', $check) : [$check];
276276
}
277277

278278
return !array_diff((array)$check, $sampleArr);
@@ -282,15 +282,15 @@ public static function valueExistsAll($check, array $sampleArr): bool
282282
* ******* 检查 一个或多个值是否存在数组中 *******
283283
* 有一个存在就返回 true 都不存在 return false
284284
* @param string|array $check
285-
* @param array $sampleArr 只能检查一维数组
285+
* @param array $sampleArr 只能检查一维数组
286286
* @return bool
287287
*/
288288
public static function valueExistsOne($check, array $sampleArr): bool
289289
{
290290
// 以逗号分隔的会被拆开,组成数组
291291
if (\is_string($check)) {
292292
$check = trim($check, ', ');
293-
$check = strpos($check, ',') !== false ? explode(',', $check) : array($check);
293+
$check = strpos($check, ',') !== false ? explode(',', $check) : [$check];
294294
}
295295

296296
return (bool)array_intersect((array)$check, $sampleArr);
@@ -300,8 +300,8 @@ public static function valueExistsOne($check, array $sampleArr): bool
300300
* ******* 不区分大小写,检查 一个或多个值是否 全存在数组中 *******
301301
* 有一个不存在即返回 false
302302
* @param string|array $need
303-
* @param array $arr 只能检查一维数组
304-
* @param bool $type 是否同时验证类型
303+
* @param array $arr 只能检查一维数组
304+
* @param bool $type 是否同时验证类型
305305
* @return bool | string 不存在的会返回 检查到的 字段,判断时 请使用 ArrHelper::existsAll($need,$arr)===true 来验证是否全存在
306306
*/
307307
public static function existsAll($need, $arr, $type = false)
@@ -334,8 +334,8 @@ public static function existsAll($need, $arr, $type = false)
334334
* ******* 不区分大小写,检查 一个或多个值是否存在数组中 *******
335335
* 有一个存在就返回 true 都不存在 return false
336336
* @param string|array $need
337-
* @param array $arr 只能检查一维数组
338-
* @param bool $type 是否同时验证类型
337+
* @param array $arr 只能检查一维数组
338+
* @param bool $type 是否同时验证类型
339339
* @return bool
340340
*/
341341
public static function existsOne($need, $arr, $type = false): bool
@@ -372,7 +372,7 @@ public static function existsOne($need, $arr, $type = false): bool
372372
* 'key1' => 'value1',
373373
* 'key2-test' => 'value2',
374374
* ]
375-
* @param bool $expectInt
375+
* @param bool $expectInt
376376
* @return int
377377
*/
378378
public static function getKeyMaxWidth(array $data, $expectInt = true): int
@@ -395,9 +395,9 @@ public static function getKeyMaxWidth(array $data, $expectInt = true): int
395395
* Get data from array or object by path.
396396
* Example: `DataCollector::getByPath($array, 'foo.bar.yoo')` equals to $array['foo']['bar']['yoo'].
397397
* @param array|\ArrayAccess $data An array or object to get value.
398-
* @param mixed $path The key path.
399-
* @param mixed $default
400-
* @param string $separator Separator of paths.
398+
* @param mixed $path The key path.
399+
* @param mixed $default
400+
* @param string $separator Separator of paths.
401401
* @return mixed Found value, null if not exists.
402402
*/
403403
public static function getByPath($data, string $path, $default = null, string $separator = '.')
@@ -433,9 +433,9 @@ public static function getByPath($data, string $path, $default = null, string $s
433433
/**
434434
* setByPath
435435
* @param array|\ArrayAccess &$data
436-
* @param string $path
437-
* @param mixed $value
438-
* @param string $separator
436+
* @param string $path
437+
* @param mixed $value
438+
* @param string $separator
439439
*/
440440
public static function setByPath(&$data, string $path, $value, string $separator = '.')
441441
{
@@ -460,7 +460,7 @@ public static function setByPath(&$data, string $path, $value, string $separator
460460
} else {
461461
// If a node is value but path is not go to the end, we replace this value as a new store.
462462
// Then next node can insert new value to this store.
463-
$dataTmp = array();
463+
$dataTmp = [];
464464
}
465465
}
466466

@@ -522,7 +522,7 @@ public static function divide($array): array
522522

523523
/**
524524
* Flatten a multi-dimensional associative array with dots.
525-
* @param array $array
525+
* @param array $array
526526
* @param string $prepend
527527
* @return array
528528
*/
@@ -543,7 +543,7 @@ public static function dot($array, $prepend = ''): array
543543

544544
/**
545545
* Get all of the given array except for a specified array of items.
546-
* @param array $array
546+
* @param array $array
547547
* @param array|string $keys
548548
* @return array
549549
*/
@@ -557,7 +557,7 @@ public static function except($array, $keys): array
557557
/**
558558
* Determine if the given key exists in the provided array.
559559
* @param \ArrayAccess|array $array
560-
* @param string|int $key
560+
* @param string|int $key
561561
* @return bool
562562
*/
563563
public static function exists($array, $key): bool
@@ -571,9 +571,9 @@ public static function exists($array, $key): bool
571571

572572
/**
573573
* Add an element to an array using "dot" notation if it doesn't exist.
574-
* @param array $array
574+
* @param array $array
575575
* @param string $key
576-
* @param mixed $value
576+
* @param mixed $value
577577
* @return array
578578
*/
579579
public static function add($array, $key, $value): array
@@ -588,8 +588,8 @@ public static function add($array, $key, $value): array
588588
/**
589589
* Get an item from an array using "dot" notation.
590590
* @param \ArrayAccess|array $array
591-
* @param string $key
592-
* @param mixed $default
591+
* @param string $key
592+
* @param mixed $default
593593
* @return mixed
594594
*/
595595
public static function get($array, $key, $default = null)
@@ -620,9 +620,9 @@ public static function get($array, $key, $default = null)
620620
/**
621621
* Set an array item to a given value using "dot" notation.
622622
* If no key is given to the method, the entire array will be replaced.
623-
* @param array $array
623+
* @param array $array
624624
* @param string $key
625-
* @param mixed $value
625+
* @param mixed $value
626626
* @return array
627627
*/
628628
public static function set(&$array, $key, $value): array
@@ -653,7 +653,7 @@ public static function set(&$array, $key, $value): array
653653
/**
654654
* Flatten a multi-dimensional array into a single level.
655655
* @param array $array
656-
* @param int $depth
656+
* @param int $depth
657657
* @return array
658658
*/
659659
public static function flatten($array, $depth = INF): array
@@ -675,7 +675,7 @@ public static function flatten($array, $depth = INF): array
675675

676676
/**
677677
* Remove one or many array items from a given array using "dot" notation.
678-
* @param array $array
678+
* @param array $array
679679
* @param array|string $keys
680680
* @return void
681681
*/
@@ -718,7 +718,7 @@ public static function forget(&$array, $keys)
718718
/**
719719
* Check if an item or items exist in an array using "dot" notation.
720720
* @param \ArrayAccess|array $array
721-
* @param string|array $keys
721+
* @param string|array $keys
722722
* @return bool
723723
*/
724724
public static function has($array, $keys): bool
@@ -778,8 +778,8 @@ public static function prepend($array, $value, $key = null): array
778778
/**
779779
* remove the $key of the $arr, and return value.
780780
* @param string $key
781-
* @param array $arr
782-
* @param mixed $default
781+
* @param array $arr
782+
* @param mixed $default
783783
* @return mixed
784784
*/
785785
public static function remove(&$arr, $key, $default = null)
@@ -796,9 +796,9 @@ public static function remove(&$arr, $key, $default = null)
796796

797797
/**
798798
* Get a value from the array, and remove it.
799-
* @param array $array
799+
* @param array $array
800800
* @param string $key
801-
* @param mixed $default
801+
* @param mixed $default
802802
* @return mixed
803803
*/
804804
public static function pull(&$array, $key, $default = null)
@@ -812,7 +812,7 @@ public static function pull(&$array, $key, $default = null)
812812

813813
/**
814814
* Get a subset of the items from the given array.
815-
* @param array $array
815+
* @param array $array
816816
* @param array|string $keys
817817
* @return array
818818
*/
@@ -835,7 +835,7 @@ public static function shuffle($array): array
835835

836836
/**
837837
* Filter the array using the given callback.
838-
* @param array $array
838+
* @param array $array
839839
* @param callable $callback
840840
* @return array
841841
*/
@@ -860,13 +860,13 @@ public static function wrap($value): array
860860

861861
/**
862862
* array 递归 转换成 字符串
863-
* @param array $array [大于1200字符 strlen($string)>1200
864-
* @param int $length
863+
* @param array $array [大于1200字符 strlen($string)>1200
864+
* @param int $length
865865
* @param array|int $cycles [至多循环六次 $num >= 6
866-
* @param bool $showKey
867-
* @param bool $addMark
868-
* @param string $separator
869-
* @param string $string
866+
* @param bool $showKey
867+
* @param bool $addMark
868+
* @param string $separator
869+
* @param string $string
870870
* @return string
871871
*/
872872
public static function toString(
@@ -877,8 +877,7 @@ public static function toString(
877877
$addMark = false,
878878
$separator = ', ',
879879
$string = ''
880-
): string
881-
{
880+
): string {
882881
if (!\is_array($array) || empty($array)) {
883882
return '';
884883
}
@@ -923,14 +922,13 @@ public static function toStringNoKey(
923922
$showKey = false,
924923
$addMark = true,
925924
$separator = ', '
926-
): string
927-
{
925+
): string {
928926
return static::toString($array, $length, $cycles, $showKey, $addMark, $separator);
929927
}
930928

931929
/**
932930
* @param array $array
933-
* @param int $length
931+
* @param int $length
934932
* @return mixed|null|string|string[]
935933
*/
936934
public static function toFormatString($array, $length = 400)

src/FixedArray.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function __isset(string $key)
6060

6161
/**
6262
* @param string $key
63-
* @param mixed $value
63+
* @param mixed $value
6464
*/
6565
public function __set(string $key, $value)
6666
{

0 commit comments

Comments
 (0)