Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Console] SymonfyStyle - Check value isset to avoid PHP notice#34114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:3.4fromleevigraham:patch-2
Feb 3, 2020

Conversation

@leevigraham
Copy link
Contributor

QA
Branch?4.3
Bug fix?yes
New feature?no
Deprecations?no
TicketsFix#34093
LicenseMIT
Doc PRn/a

This PR addresses the issue when a default value is not a valid choice. Currently this would throw a notice which outputs to the console.

This fix is a similar implementation to theQuestionHelper:https://github.com/symfony/symfony/blob/4.4/src/Symfony/Component/Console/Helper/QuestionHelper.php#L63

Example console command and output can be found in the issue:#34093

@leevigrahamleevigraham changed the title[Console] SymonfyStyle - Check value isset to avoid PHP notice[Console] Fix #34093 - SymonfyStyle - Check value isset to avoid PHP noticeOct 25, 2019
@nicolas-grekasnicolas-grekas changed the title[Console] Fix #34093 - SymonfyStyle - Check value isset to avoid PHP notice[Console] SymonfyStyle - Check value isset to avoid PHP noticeOct 25, 2019
@nicolas-grekasnicolas-grekas added this to the4.3 milestoneOct 25, 2019
@chalasrchalasr modified the milestones:4.3,3.4Oct 27, 2019
@chalasr
Copy link
Member

Can you please rebase against 3.4 and add a test to prevent regressions?

@leevigraham
Copy link
ContributorAuthor

@chalasr Yep… I thought I would throw in a quick PR to get some feedback.

@xabbuh
Copy link
Member

I am not really sure how this could happen. Could you please add a test that illustrates why this is necessary?

@Nek-
Copy link
Contributor

@xabbuh did you see#34093 ?

@xabbuh
Copy link
Member

I think we need to clarify that the$default argument must be one of the choices. I am not sure that returning it as is when the choice does not exist is a good approach, but IMO we should throw an exception instead.

ogizanagi, derrabus, and apfelbox reacted with thumbs up emoji

@chalasr
Copy link
Member

I thought this was about supporting using the choice key instead of the value as default, read too fast.
I agree with@xabbuh here, the default must be a valid choice. IIRC it's already enforced by the ChoiceQuestion's default validator, let's prevent the notice with a proper exception.

@leevigraham
Copy link
ContributorAuthor

leevigraham commentedOct 31, 2019
edited
Loading

Thanks for the feedback@xabbuh

I am not really sure how this could happen. Could you please add a test that illustrates why this is necessary?

I ran into this issue when I was trying to figure out how to confirm option inputs during the interact function see:#34093

In the original example the flow should probably be that if the user enters an option skip the question but if I did that when I use the value I would need to throw anInvalidArgument Exception in theexecute method.

I think we need to clarify that the $default argument must be one of the choices.

That doesn't seem to be enforced in theQuestionHelperhttps://github.com/symfony/symfony/blob/4.4/src/Symfony/Component/Console/Helper/QuestionHelper.php#L63

I am not sure that returning it as is when the choice does not exist is a good approach, but IMO we should throw an exception instead.

If the user is prevented an invalid default and quickly presses enter the console shows an Invalid value error and prompts the user to select a valid value.

@nicolas-grekas
Copy link
Member

I think we need to clarify that the $default argument must be one of the choices.

It looks like nothing requires it inQuestionHelper, so I don't see the need for this enforcement.
Anyway, this would need a test case.@leevigraham can you add one please?

leevigraham reacted with thumbs up emoji

@leevigraham
Copy link
ContributorAuthor

It looks like nothing requires it inQuestionHelper

Yep that was my thinking. The implementation mirrors theQuestionHelper. I'll add test cases today or over the weekend.

@nicolas-grekas
Copy link
Member

friendly ping@leevigraham

@fabpot
Copy link
Member

Thank you@leevigraham.

fabpot added a commit that referenced this pull requestFeb 3, 2020
…tice (leevigraham)This PR was merged into the 3.4 branch.Discussion----------[Console] SymonfyStyle - Check value isset to avoid PHP notice| Q             | A| ------------- | ---| Branch?       | 4.3| Bug fix?      | yes| New feature?  | no| Deprecations? | no| Tickets       |Fix#34093| License       | MIT| Doc PR        | n/aThis PR addresses the issue when a default value is not a valid choice. Currently this would throw a notice which outputs to the console.This fix is a similar implementation to the `QuestionHelper`:https://github.com/symfony/symfony/blob/4.4/src/Symfony/Component/Console/Helper/QuestionHelper.php#L63Example console command and output can be found in the issue:#34093Commits-------c9072c7 Check value isset to avoid PHP notice
@fabpotfabpot merged commitc9072c7 intosymfony:3.4Feb 3, 2020
@leevigraham
Copy link
ContributorAuthor

@fabpot@nicolas-grekas Thanks for merging… I was overseas on holidays for a few months.

This was referencedFeb 29, 2020
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

3.4

Development

Successfully merging this pull request may close these issues.

7 participants

@leevigraham@chalasr@xabbuh@Nek-@nicolas-grekas@fabpot@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp