Skip to content

Commit 9fed64e

Browse files
committed
increase the minimum version to PHP 7.4
1 parent 2a266a0 commit 9fed64e

File tree

10 files changed

+329
-323
lines changed

10 files changed

+329
-323
lines changed

composer.json

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
11
{
2-
"name": "madesimple/php-arrays",
3-
"description": "Helper functions for manipulating arrays",
4-
"type": "library",
5-
"license": "MIT",
6-
"authors": [
7-
{
8-
"name": "Peter Scopes",
9-
"email": "[email protected]"
10-
}
11-
],
12-
"require": {
13-
"php": ">=7.1"
14-
},
15-
"autoload": {
16-
"psr-4": {
17-
"MadeSimple\\Arrays\\": "src/"
18-
}
19-
},
20-
"require-dev": {
21-
"phpunit/phpunit": "^9.5"
22-
},
23-
"autoload-dev": {
24-
"psr-4": {
25-
"MadeSimple\\Arrays\\Test\\": "tests/"
26-
}
27-
},
28-
"config": {
29-
"sort-packages": true
30-
},
31-
"scripts": {
32-
"test": "vendor/bin/phpunit"
33-
},
34-
"scripts-descriptions": {
35-
"test": "Run unit and integration tests"
2+
"name": "madesimple/php-arrays",
3+
"description": "Helper functions for manipulating arrays",
4+
"type": "library",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Peter Scopes",
9+
"email": "[email protected]"
3610
}
11+
],
12+
"require": {
13+
"php": ">=7.4",
14+
"ext-json": "*"
15+
},
16+
"autoload": {
17+
"psr-4": {
18+
"MadeSimple\\Arrays\\": "src/"
19+
}
20+
},
21+
"require-dev": {
22+
"phpunit/phpunit": "^9.5"
23+
},
24+
"autoload-dev": {
25+
"psr-4": {
26+
"MadeSimple\\Arrays\\Test\\": "tests/"
27+
}
28+
},
29+
"config": {
30+
"sort-packages": true
31+
},
32+
"scripts": {
33+
"test": "vendor/bin/phpunit"
34+
},
35+
"scripts-descriptions": {
36+
"test": "Run unit and integration tests"
37+
}
3738
}

src/Arr.php

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Arr
1818
*
1919
* @return bool
2020
*/
21-
public static function accessible($value)
21+
public static function accessible($value): bool
2222
{
2323
return is_array($value) || $value instanceof ArrayAccess;
2424
}
@@ -30,7 +30,7 @@ public static function accessible($value)
3030
*
3131
* @return bool
3232
*/
33-
public static function isAssoc(array $array)
33+
public static function isAssoc(array $array): bool
3434
{
3535
$keys = array_keys($array);
3636

@@ -44,7 +44,7 @@ public static function isAssoc(array $array)
4444
*
4545
* @return array [array, array]
4646
*/
47-
public static function divide($array)
47+
public static function divide($array): array
4848
{
4949
if ($array instanceof ArrayAble) {
5050
$array = $array->toArray();
@@ -56,23 +56,23 @@ public static function divide($array)
5656
* Flatten a multi-dimensional array into a single level.
5757
*
5858
* @param Arrayable|array $array
59-
* @param int $depth
59+
* @param int $depth
6060
*
6161
* @return array
6262
*/
63-
public static function flatten($array, $depth = INF)
63+
public static function flatten($array, $depth = INF): array
6464
{
6565
if ($array instanceof ArrayAble) {
6666
$array = $array->toArray();
6767
}
6868
return array_reduce($array, function ($result, $item) use ($depth) {
6969
if (!is_array($item)) {
7070
return array_merge($result, [$item]);
71-
} else if($depth === 1) {
71+
}
72+
if ($depth === 1) {
7273
return array_merge($result, array_values($item));
73-
} else {
74-
return array_merge($result, static::flatten($item, $depth - 1));
7574
}
75+
return array_merge($result, static::flatten($item, $depth - 1));
7676
}, []);
7777
}
7878

@@ -82,7 +82,7 @@ public static function flatten($array, $depth = INF)
8282
* @param ArrayAble|array $array
8383
* @return array
8484
*/
85-
public static function collapse($array)
85+
public static function collapse($array): array
8686
{
8787
if ($array instanceof ArrayAble) {
8888
$array = $array->toArray();
@@ -93,44 +93,44 @@ public static function collapse($array)
9393
/**
9494
* Get a subset of the items from $array that only contains $keys.
9595
*
96-
* @param Arrayable|array $array
96+
* @param Arrayable|array $array
9797
* @param int|string|array $keys
9898
*
9999
* @return array
100100
*/
101-
public static function only($array, $keys)
101+
public static function only($array, $keys): array
102102
{
103103
if ($array instanceof ArrayAble) {
104104
$array = $array->toArray();
105105
}
106-
return array_intersect_key($array, array_flip((array) $keys));
106+
return array_intersect_key($array, array_flip((array)$keys));
107107
}
108108

109109
/**
110110
* Get a subset of the items from $array that contains all keys except $keys.
111111
*
112-
* @param ArrayAble|array $array
112+
* @param ArrayAble|array $array
113113
* @param int|string|array $keys
114114
*
115115
* @return array
116116
*/
117-
public static function except($array, $keys)
117+
public static function except($array, $keys): array
118118
{
119119
if ($array instanceof ArrayAble) {
120120
$array = $array->toArray();
121121
}
122-
return array_diff_key($array, array_flip((array) $keys));
122+
return array_diff_key($array, array_flip((array)$keys));
123123
}
124124

125125
/**
126126
* Get a subset of items from $array that pass $callback test.
127127
*
128128
* @param ArrayAble|array $array
129-
* @param callable $callback
129+
* @param callable $callback
130130
*
131131
* @return array
132132
*/
133-
public static function filter($array, callable $callback)
133+
public static function filter($array, callable $callback): array
134134
{
135135
if ($array instanceof ArrayAble) {
136136
$array = $array->toArray();
@@ -141,12 +141,12 @@ public static function filter($array, callable $callback)
141141
/**
142142
* Get a subset of unique items from $array.
143143
*
144-
* @param ArrayAble|array $array
145-
* @param int $flag
144+
* @param ArrayAble|array $array
145+
* @param int $flag
146146
*
147147
* @return array
148148
*/
149-
public static function unique($array, $flag = SORT_STRING)
149+
public static function unique($array, int $flag = SORT_STRING): array
150150
{
151151
if ($array instanceof ArrayAble) {
152152
$array = $array->toArray();
@@ -158,17 +158,17 @@ public static function unique($array, $flag = SORT_STRING)
158158
* Get the values from a single column in $array.
159159
* An array of columns can be provided to chain call column.
160160
*
161-
* @param array $array
161+
* @param null|array $array
162162
* @param string|array $columns
163-
* @param string $indexKey Only applied to the last column
163+
* @param int|null|string $indexKey Only applied to the last column
164164
* @return array
165165
* @see \array_column()
166166
*/
167-
public static function column(array $array = null, $columns, $indexKey = null)
167+
public static function column(?array $array, $columns, $indexKey = null): array
168168
{
169-
$array = (array) $array;
170-
$columns = (array) $columns;
171-
$last = array_pop($columns);
169+
$array = (array)$array;
170+
$columns = (array)$columns;
171+
$last = array_pop($columns);
172172
foreach ($columns as $column) {
173173
$array = array_column($array, $column);
174174
}
@@ -180,15 +180,15 @@ public static function column(array $array = null, $columns, $indexKey = null)
180180
* If an element in `$columns` is `null` then collapse the `$array`
181181
* An array of columns can be provided to chain call column.
182182
*
183-
* @param array $array
183+
* @param null|array $array
184184
* @param string|array $columns
185185
* @return array
186186
* @see \array_column()
187187
*/
188-
public static function pluck(array $array = null, $columns)
188+
public static function pluck(?array $array, $columns): array
189189
{
190-
$array = (array) $array;
191-
$columns = (array) $columns;
190+
$array = (array)$array;
191+
$columns = (array)$columns;
192192
foreach ($columns as $column) {
193193
if ($column !== null) {
194194
$array = array_column($array, $column);
@@ -201,11 +201,11 @@ public static function pluck(array $array = null, $columns)
201201

202202
/**
203203
* @param ArrayAccess|array $array
204-
* @param string|int $key
204+
* @param string|int $key
205205
*
206206
* @return bool
207207
*/
208-
public static function exists($array, $key)
208+
public static function exists($array, $key): bool
209209
{
210210
if ($array instanceof ArrayAccess) {
211211
return $array->offsetExists($key);
@@ -219,12 +219,12 @@ public static function exists($array, $key)
219219
* If $needle is a callable then return the first key where the callable
220220
* returns true.
221221
*
222-
* @param array $haystack
223-
* @param mixed|callable $needle
224-
* @param bool $strict
222+
* @param array $haystack
223+
* @param mixed|callable $needle
224+
* @param bool $strict
225225
* @return false|int|string
226226
*/
227-
public static function searchKey(array $haystack, $needle, $strict = false)
227+
public static function searchKey(array $haystack, $needle, bool $strict = false)
228228
{
229229
if (is_callable($needle)) {
230230
foreach ($haystack as $key => $item) {
@@ -234,8 +234,7 @@ public static function searchKey(array $haystack, $needle, $strict = false)
234234
}
235235
}
236236
return false;
237-
}
238-
else {
237+
} else {
239238
return array_search($needle, $haystack, $strict);
240239
}
241240
}
@@ -245,12 +244,12 @@ public static function searchKey(array $haystack, $needle, $strict = false)
245244
* If $needle is a callable then return the first element where the callable
246245
* returns true.
247246
*
248-
* @param array $haystack
249-
* @param mixed|callable $needle
250-
* @param bool $strict
247+
* @param array $haystack
248+
* @param mixed|callable $needle
249+
* @param bool $strict
251250
* @return false|int|string
252251
*/
253-
public static function search(array $haystack, $needle, $strict = false)
252+
public static function search(array $haystack, $needle, bool $strict = false)
254253
{
255254
if (is_callable($needle)) {
256255
foreach ($haystack as $key => $item) {
@@ -260,8 +259,7 @@ public static function search(array $haystack, $needle, $strict = false)
260259
}
261260
}
262261
return null;
263-
}
264-
else {
262+
} else {
265263
$key = array_search($needle, $haystack, $strict);
266264
return $key !== false ? $haystack[$key] : null;
267265
}
@@ -272,16 +270,16 @@ public static function search(array $haystack, $needle, $strict = false)
272270
* with value $value.
273271
* An array of properties can be provided to perform deeper finds.
274272
*
275-
* @param array $array
273+
* @param array $array
276274
* @param string|array $property
277-
* @param mixed $value
278-
* @param bool $strict
275+
* @param mixed $value
276+
* @param bool $strict
279277
* @return mixed|null
280278
*/
281-
public static function locate($array, $property, $value, $strict = false)
279+
public static function locate($array, $property, $value, bool $strict = false)
282280
{
283-
$array = $array ?? [];
284-
$columns = (array) $property;
281+
$array = $array ?? [];
282+
$columns = (array)$property;
285283
$property = array_pop($columns);
286284
if (!empty($columns)) {
287285
$array = static::column($array, $columns);

0 commit comments

Comments
 (0)