Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayUtils::checkIssetKeys : Modify method with not strict comparaison #21

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
CHANGELOG for 1.x
===================
## v1.2.1 - (2024-03-27)
### Fix

- `ArrayUtils::checkIssetKeys` : Modify method with not strict comparaison

## v1.2.0 - (2024-03-27)
### Added
- Common Entity Interface and Trait such as the `ProcessInterface` which we will use to monitor cron, api and file generation.
Expand Down
11 changes: 9 additions & 2 deletions src/Utils/ArrayUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,21 @@ public static function flattenArrayValues(array $input, string $separator = ',')
}

/**
* Check if all keys are in array
* Check if all keys are set in array
* It's not a strict comparaison, all array values may not be in keys
*
* @param array $array array to compare
* @param array $keys keys to check
*/
public static function checkIssetKeys(array $array, array $keys): bool
{
return empty(array_diff(array_keys($array), $keys));
foreach ($keys as $key) {
if (!isset($array[$key])) {
return false;
}
}

return true;
}

/**
Expand Down
7 changes: 3 additions & 4 deletions tests/Utils/ArrayUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,9 @@ public function checkIssetKeysProvider(): array
// $keys
[0, 1, 5],
],
'last missing' => [
'one missing' => [
// expected
false,
true,
// array
[
0 => "000",
Expand All @@ -369,14 +369,13 @@ public function checkIssetKeysProvider(): array
// $keys
[0, 1],
],
'first missing' => [
'key is not present' => [
// expected
false,
// array
[
'dummy' => "dummy",
'foo' => "foo",
'bar' => "bar",
],
// $keys
['foo', 'bar'],
Expand Down