Skip to content

Commit 29b5c76

Browse files
committed
Added support for PHP 8
1 parent f71d61e commit 29b5c76

File tree

4 files changed

+22
-28
lines changed

4 files changed

+22
-28
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- `Fixed` for any bug fixes.
1313
- `Security` in case of vulnerabilities
1414

15+
## [2.0.0] - 2023.01.26
16+
17+
### Added
18+
19+
- Added support for PHP 8
20+
1521
## [1.3.1] - 2021.03.13
1622

1723
### Fixed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ This project is open source and available under the [MIT License](LICENSE).
2121

2222
## Requirements
2323

24-
* PHP >= 7.1.0
24+
* PHP `^8.0`
2525

2626
## Installation
2727

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"preferred-install": "dist"
2727
},
2828
"require": {
29-
"php": ">=7.1.0"
29+
"php": "^8.0"
3030
},
3131
"autoload": {
3232
"psr-4": {

src/Arr.php

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
<?php
2-
/**
3-
* @package php-array-helpers
4-
* @link https://github.com/bayfrontmedia/php-array-helpers
5-
* @author John Robinson <[email protected]>
6-
* @copyright 2020-2021 Bayfront Media
7-
*/
82

93
namespace Bayfront\ArrayHelpers;
104

@@ -83,7 +77,7 @@ public static function undot(array $array): array
8377
* @return void
8478
*/
8579

86-
public static function set(array &$array, string $key, $value): void
80+
public static function set(array &$array, string $key, mixed $value): void
8781
{
8882

8983
$keys = explode('.', $key);
@@ -131,20 +125,14 @@ public static function has(array $array, string $key): bool
131125
*
132126
* @param array $array (Original array)
133127
* @param string $key (Key to return in "dot" notation)
134-
* @param mixed $default (Default value to return)
128+
* @param mixed|null $default (Default value to return)
135129
*
136130
* @return mixed
137131
*/
138132

139-
public static function get(array $array, string $key, $default = NULL)
133+
public static function get(array $array, string $key, mixed $default = NULL): mixed
140134
{
141135

142-
if (is_null($key)) {
143-
144-
return $array;
145-
146-
}
147-
148136
if (isset($array[$key])) {
149137

150138
return $array[$key];
@@ -206,12 +194,12 @@ public static function pluck(array $array, string $value, string $key = NULL): a
206194
* Remove a single key, or an array of keys from a given array using "dot" notation.
207195
*
208196
* @param array $array (Original array)
209-
* @param string|array $keys (Key(s) to forget in "dot" notation)
197+
* @param array|string $keys (Key(s) to forget in "dot" notation)
210198
*
211199
* @return void
212200
*/
213201

214-
public static function forget(array &$array, $keys): void
202+
public static function forget(array &$array, array|string $keys): void
215203
{
216204

217205
$original =& $array;
@@ -245,12 +233,12 @@ public static function forget(array &$array, $keys): void
245233
* Returns the original array except given key(s).
246234
*
247235
* @param array $array (Original array)
248-
* @param string|array $keys (Keys to remove)
236+
* @param array|string $keys (Keys to remove)
249237
*
250238
* @return array
251239
*/
252240

253-
public static function except(array $array, $keys): array
241+
public static function except(array $array, array|string $keys): array
254242
{
255243
return array_diff_key($array, array_flip((array)$keys));
256244
}
@@ -259,12 +247,12 @@ public static function except(array $array, $keys): array
259247
* Returns only desired key(s) from an array.
260248
*
261249
* @param array $array (Original array)
262-
* @param string|array $keys (Keys to return)
250+
* @param array|string $keys (Keys to return)
263251
*
264252
* @return array
265253
*/
266254

267-
public static function only(array $array, $keys): array
255+
public static function only(array $array, array|string $keys): array
268256
{
269257
return array_intersect_key($array, array_flip((array)$keys));
270258
}
@@ -273,12 +261,12 @@ public static function only(array $array, $keys): array
273261
* Returns array of missing keys from the original array, or an empty array if none are missing.
274262
*
275263
* @param array $array (Original array)
276-
* @param string|array $keys (Keys to check)
264+
* @param array|string $keys (Keys to check)
277265
*
278266
* @return array
279267
*/
280268

281-
public static function missing(array $array, $keys): array
269+
public static function missing(array $array, array|string $keys): array
282270
{
283271
return array_values(array_flip(array_diff_key(array_flip((array)$keys), $array)));
284272
}
@@ -287,14 +275,14 @@ public static function missing(array $array, $keys): array
287275
* Checks if keys are missing from the original array
288276
*
289277
* @param array $array (Original array)
290-
* @param string|array $keys (Keys to check)
278+
* @param array|string $keys (Keys to check)
291279
*
292280
* @return bool
293281
*/
294282

295-
public static function isMissing(array $array, $keys): bool
283+
public static function isMissing(array $array, array|string $keys): bool
296284
{
297-
return (self::missing($array, $keys)) ? true : false;
285+
return (bool)self::missing($array, $keys);
298286
}
299287

300288
/**

0 commit comments

Comments
 (0)