Skip to content

Commit c3da862

Browse files
dmitrijivanenkonicolas-grekas
authored andcommitted
[Console] Optimize mostRecentlyEnteredValue() method
1 parent c77af87 commit c3da862

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Helper/QuestionHelper.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,13 @@ private function mostRecentlyEnteredValue(string $entered): string
379379
return $entered;
380380
}
381381

382-
$choices = explode(',', $entered);
383-
if ('' !== $lastChoice = trim($choices[\count($choices) - 1])) {
384-
return $lastChoice;
382+
if (false === $lastCommaPos = strrpos($entered, ',')) {
383+
return $entered;
385384
}
386385

387-
return $entered;
386+
$lastChoice = trim(substr($entered, $lastCommaPos + 1));
387+
388+
return '' !== $lastChoice ? $lastChoice : $entered;
388389
}
389390

390391
/**

0 commit comments

Comments
 (0)