[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:
Javier Spagnoletti 2015-01-29 23:30:47 -03:00 committed by Fabien Potencier
parent 2e7434102a
commit c2aeeeb042
3 changed files with 3 additions and 3 deletions

View File

@ -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;

View File

@ -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);
}
/**

View File

@ -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) {