Skip to content

Commit 118602a

Browse files
committed
minor symfony#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 symfony#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
2 parents 2e74341 + c2aeeeb commit 118602a

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)