minor #13553 [2.7] [Form] Replaced calls to array_search() by in_array() (phansys)

This PR was submitted for the 2.7 branch but it was merged into the 2.3 branch instead (closes #13553).

Discussion
----------

[2.7] [Form] Replaced calls to array_search() by in_array()

[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

It's a semantic improvement mostly, for readability (no performance impact).

Commits
-------

c2aeeeb [2.7] [Form] Replaced calls to array_search() by in_array() where is no need to get the index
This commit is contained in:
Fabien Potencier 2015-02-05 07:23:01 +01:00
commit 118602a961
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) {