8000 [2.7] [Form] Replaced calls to array_search() by in_array() where is … · symfony/symfony@c2aeeeb · GitHub
[go: up one dir, main page]

Skip to content

Commit c2aeeeb

Browse files
phansysfabpot
authored andcommitted
[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
1 parent 2e74341 commit c2aeeeb

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/Symfony/Bridge/Twig/Extension/FormExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public function humanize($text)
144144
public function isSelectedChoice(ChoiceView $choice, $selectedValue)
145145
{
146146
if (is_array($selectedValue)) {
147-
return false !== array_search($choice->value, $selectedValue, true);
147+
return in_array($choice->value, $selectedValue, true);
148148
}
149149

150150
return $choice->value === $selectedValue;

src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ protected function addChoice(array &$bucketForPreferred, array &$bucketForRemain
381381
*/
382382
protected function isPreferred($choice, array $preferredChoices)
383383
{
384-
return false !== array_search($choice, $preferredChoices, true);
384+
return in_array($choice, $preferredChoices, true);
385385
}
386386

387387
/**

src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
111111
// avoid making the type check inside the closure.
112112
if ($options['multiple']) {
113113
$view->vars['is_selected'] = function ($choice, array $values) {
114-
return false !== array_search($choice, $values, true);
114+
return in_array($choice, $values, true);
115115
};
116116
} else {
117117
$view->vars['is_selected'] = function ($choice, $value) {

0 commit comments

Comments
 (0)
0