8000 change array_filter for foreach · symfony/symfony@6e9fb5b · GitHub
[go: up one dir, main page]

Skip to content

Commit 6e9fb5b

Browse files
committed
change array_filter for foreach
1 parent 501bfbc commit 6e9fb5b

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

src/Symfony/Component/OptionsResolver/OptionsResolver.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -882,12 +882,7 @@ private function verifyTypes($type, $value, array &$invalidTypes)
882882
return true;
883883
}
884884

885-
$invalidValues = array_filter( // Filter out valid values, keeping invalid values in the resulting array
886-
$value,
887-
function ($value) use ($type) {
888-
return !self::isValueValidType($type, $value);
889-
}
890-
);
885+
$invalidValues = $this->getInvalidValues($value, $type);
891886

892887
if (!$invalidValues) {
893888
return true;
@@ -937,12 +932,7 @@ private function verifyArrayType($type, array $value, array &$invalidTypes)
937932
return $success;
938933
}
939934

940-
$invalid = array_filter( // Filter out valid values, keeping invalid values in the resulting array
941-
$value,
942-
function ($value) use ($type) {
943-
return !self::isValueValidType($type, $value);
944-
}
945-
);
935+
$invalid = $this->getInvalidValues($value, $type);
946936

947937
return !count($invalid);
948938
}
@@ -1118,4 +1108,22 @@ private static function isValueValidType($type, $value)
11181108
{
11191109
return (function_exists($isFunction = 'is_'.$type) && $isFunction($value)) || $value instanceof $t 8000 ype;
11201110
}
1111+
1112+
/**
1113+
* @param array $arrayValues
1114+
*
1115+
* @return array
1116+
*/
1117+
private function getInvalidValues(array $arrayValues, $type)
1118+
{
1119+
$invalidValues = array();
1120+
1121+
foreach($arrayValues as $key => $value) {
1122+
if (!self::isValueValidType($type, $value)) {
1123+
$invalidValues[$key] = $value;
1124+
}
1125+
}
1126+
1127+
return $invalidValues;
3DF2 1128+
}
11211129
}

0 commit comments

Comments
 (0)
0