Skip to content

Commit feadc89

Browse files
committed
Arrays::defaults() add soft option
1 parent 52bd49b commit feadc89

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

src/Arrays.php

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ class Arrays
1515
* @param mixed[] $array
1616
* @return mixed[]
1717
*/
18-
public static function defaults(array $defaults, iterable $array): array
18+
public static function defaults(array $defaults, iterable $array, bool $soft = false): array
1919
{
2020
foreach ($array as $key => $value) {
2121
if (!array_key_exists($key, $defaults)) {
22-
throw new LogicException(
23-
sprintf('Key %s is not allowed in array', $key)
24-
);
22+
if (!$soft) {
23+
throw new LogicException(
24+
sprintf('Key %s is not allowed in array', $key)
25+
);
26+
}
27+
28+
continue;
2529
}
2630

2731
$defaults[$key] = $value;
@@ -45,22 +49,6 @@ public static function firstValue(array $array)
4549
return $array[$key];
4650
}
4751

48-
/**
49-
* @param mixed[] $array
50-
* @param string|int $column
51-
* @return mixed[]
52-
*/
53-
public static function columnAsKey(iterable $array, $column): array
54-
{
55-
$result = [];
56-
57-
foreach ($array as $values) {
58-
$result[$values[$column]] = $values;
59-
}
60-
61-
return $result;
62-
}
63-
6452
/**
6553
* @param mixed[] $previous
6654
* @param mixed[] $current

0 commit comments

Comments
 (0)