[2.7] [Form] Replaced calls to array_search() by in_array() where is no need to get the index
| Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | none | License | MIT | Doc PR | none
This commit is contained in:
parent
2e7434102a
commit
c2aeeeb042
|
@ -144,7 +144,7 @@ class FormExtension extends \Twig_Extension
|
|||
public function isSelectedChoice(ChoiceView $choice, $selectedValue)
|
||||
{
|
||||
if (is_array($selectedValue)) {
|
||||
return false !== array_search($choice->value, $selectedValue, true);
|
||||
return in_array($choice->value, $selectedValue, true);
|
||||
}
|
||||
|
||||
return $choice->value === $selectedValue;
|
||||
|
|
|
@ -381,7 +381,7 @@ class ChoiceList implements ChoiceListInterface
|
|||
*/
|
||||
protected function isPreferred($choice, array $preferredChoices)
|
||||
{
|
||||
return false !== array_search($choice, $preferredChoices, true);
|
||||
return in_array($choice, $preferredChoices, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -111,7 +111,7 @@ class ChoiceType extends AbstractType
|
|||
// avoid making the type check inside the closure.
|
||||
if ($options['multiple']) {
|
||||
$view->vars['is_selected'] = function ($choice, array $values) {
|
||||
return false !== array_search($choice, $values, true);
|
||||
return in_array($choice, $values, true);
|
||||
};
|
||||
} else {
|
||||
$view->vars['is_selected'] = function ($choice, $value) {
|
||||
|
|
Reference in New Issue