Skip to content
Draft
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions src/ArrayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@
return $key($array, $default);
}

if (is_array($array) && (is_int($key) || is_string($key))) {
return array_key_exists($key, $array) ? $array[$key] : $default;
}

if (is_array($key)) {
if (empty($key)) {
return $default;
Expand Down Expand Up @@ -754,7 +758,7 @@
foreach ($array as $element) {
if (!is_array($element) && !is_object($element)) {
throw new InvalidArgumentException(
'index() can not get value from ' . gettype($element) .

Check warning on line 761 in src/ArrayHelper.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "ConcatOperandRemoval": @@ @@ /** @var mixed $element */ foreach ($array as $element) { if (!is_array($element) && !is_object($element)) { - throw new InvalidArgumentException('index() can not get value from ' . gettype($element) . '. The $array should be either multidimensional array or an array of objects.'); + throw new InvalidArgumentException('index() can not get value from ' . gettype($element)); } $lastArray =& $result; foreach ($groups as $group) {

Check warning on line 761 in src/ArrayHelper.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "Concat": @@ @@ /** @var mixed $element */ foreach ($array as $element) { if (!is_array($element) && !is_object($element)) { - throw new InvalidArgumentException('index() can not get value from ' . gettype($element) . '. The $array should be either multidimensional array or an array of objects.'); + throw new InvalidArgumentException('index() can not get value from ' . '. The $array should be either multidimensional array or an array of objects.' . gettype($element)); } $lastArray =& $result; foreach ($groups as $group) {

Check warning on line 761 in src/ArrayHelper.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "ConcatOperandRemoval": @@ @@ /** @var mixed $element */ foreach ($array as $element) { if (!is_array($element) && !is_object($element)) { - throw new InvalidArgumentException('index() can not get value from ' . gettype($element) . '. The $array should be either multidimensional array or an array of objects.'); + throw new InvalidArgumentException('index() can not get value from ' . '. The $array should be either multidimensional array or an array of objects.'); } $lastArray =& $result; foreach ($groups as $group) {

Check warning on line 761 in src/ArrayHelper.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "ConcatOperandRemoval": @@ @@ /** @var mixed $element */ foreach ($array as $element) { if (!is_array($element) && !is_object($element)) { - throw new InvalidArgumentException('index() can not get value from ' . gettype($element) . '. The $array should be either multidimensional array or an array of objects.'); + throw new InvalidArgumentException(gettype($element) . '. The $array should be either multidimensional array or an array of objects.'); } $lastArray =& $result; foreach ($groups as $group) {

Check warning on line 761 in src/ArrayHelper.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "Concat": @@ @@ /** @var mixed $element */ foreach ($array as $element) { if (!is_array($element) && !is_object($element)) { - throw new InvalidArgumentException('index() can not get value from ' . gettype($element) . '. The $array should be either multidimensional array or an array of objects.'); + throw new InvalidArgumentException(gettype($element) . 'index() can not get value from ' . '. The $array should be either multidimensional array or an array of objects.'); } $lastArray =& $result; foreach ($groups as $group) {
'. The $array should be either multidimensional array or an array of objects.'
);
}
Expand Down Expand Up @@ -946,7 +950,7 @@
*
* @return bool Whether the array contains the specified key.
*/
public static function keyExists(array $array, array|float|int|string $key, bool $caseSensitive = true): bool

Check warning on line 953 in src/ArrayHelper.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "TrueValue": @@ @@ * * @return bool Whether the array contains the specified key. */ - public static function keyExists(array $array, array|float|int|string $key, bool $caseSensitive = true): bool + public static function keyExists(array $array, array|float|int|string $key, bool $caseSensitive = false): bool { if (is_array($key)) { if (empty($key)) {
{
if (is_array($key)) {
if (empty($key)) {
Expand Down Expand Up @@ -1025,7 +1029,7 @@
public static function pathExists(
array $array,
array|float|int|string $path,
bool $caseSensitive = true,

Check warning on line 1032 in src/ArrayHelper.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "TrueValue": @@ @@ * * @psalm-param ArrayPath $path */ - public static function pathExists(array $array, array|float|int|string $path, bool $caseSensitive = true, string $delimiter = '.'): bool + public static function pathExists(array $array, array|float|int|string $path, bool $caseSensitive = false, string $delimiter = '.'): bool { return self::keyExists($array, self::parseMixedPath($path, $delimiter), $caseSensitive); }
string $delimiter = '.'
): bool {
return self::keyExists($array, self::parseMixedPath($path, $delimiter), $caseSensitive);
Expand Down Expand Up @@ -1054,7 +1058,7 @@
$data = iterator_to_array($data);
}

$encoding ??= ini_get('default_charset') ?: 'UTF-8';

Check warning on line 1061 in src/ArrayHelper.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "AssignCoalesce": @@ @@ if (!is_array($data)) { $data = iterator_to_array($data); } - $encoding ??= ini_get('default_charset') ?: 'UTF-8'; + $encoding = ini_get('default_charset') ?: 'UTF-8'; $flags = ENT_QUOTES | ENT_SUBSTITUTE; return $valuesOnly ? self::htmlEncodeValues($data, $flags, $encoding) : self::htmlEncodeKeysAndValues($data, $flags, $encoding); }
$flags = ENT_QUOTES | ENT_SUBSTITUTE;

return $valuesOnly
Expand Down Expand Up @@ -1358,7 +1362,7 @@
$numNestedKeys = count($keys) - 1;
foreach ($keys as $i => $key) {
if (!is_array($excludeNode) || !array_key_exists($key, $excludeNode)) {
continue 2; // Jump to the next filter.

Check warning on line 1365 in src/ArrayHelper.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "Continue_": @@ @@ $numNestedKeys = count($keys) - 1; foreach ($keys as $i => $key) { if (!is_array($excludeNode) || !array_key_exists($key, $excludeNode)) { - continue 2; + break; // Jump to the next filter. } if ($i < $numNestedKeys) {

Check warning on line 1365 in src/ArrayHelper.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "DecrementInteger": @@ @@ $numNestedKeys = count($keys) - 1; foreach ($keys as $i => $key) { if (!is_array($excludeNode) || !array_key_exists($key, $excludeNode)) { - continue 2; + continue 1; // Jump to the next filter. } if ($i < $numNestedKeys) {
}

if ($i < $numNestedKeys) {
Expand Down