Skip to content

[Config] Make ifFalse() consistent between value and closure based checks #59995

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2025

Conversation

arjenm
Copy link
Contributor

@arjenm arjenm commented Mar 17, 2025

Q A
Branch? 7.3
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #59325
License MIT

I noticed the Config/ExpBuilder got a nice new ifFalse in Symfony 7.3.
But I think its implementation is confusing.

The behavior for ifTrue() was:

  • If no closure is provided: if the actual value is true execute the then part
  • If a closure is provided: if it returns true execute the then part

The behavior for ifFalse() is prior to this PR is:

  • If no closure is provided: if the actual value is false execute the then part
  • If a closure is provided: if it returns true execute the then part

With this PR it becomes:

  • If no closure is provided: if the actual value is false execute the then part
  • If a closure is provided: if it returns false execute the then part

Rationale, I think people (me included) would not expect these to be both be valid or invalid with the same input:
$expr->ifTrue(self::valueIsNotValid(...))->thenInvalid()
$expr->ifFalse(self::valueIsNotValid(...))->thenInvalid()

They/I expect to have to change it to a test for valid values (rather than invalid ones):
$expr->ifFalse(self::valueIsValid(...))->thenInvalid()

@carsonbot
Copy link

Hey!

Thanks for your PR. You are targeting branch "7.3" but it seems your PR description refers to branch "7.3 for features".
Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

@arjenm arjenm force-pushed the fix/ifFalse branch 2 times, most recently from 97066e7 to bedf8ca Compare March 18, 2025 06:47
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for trying my 1st proposal. Let's adjust a bit.

@arjenm
Copy link
Contributor Author

arjenm commented Mar 20, 2025

@nicolas-grekas your suggestions look good, I applied them :)

@nicolas-grekas
Copy link
Member

Thank you @arjenm.

@nicolas-grekas nicolas-grekas merged commit 4c672ef into symfony:7.3 Mar 21, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants