Skip to content

[Config] Add ifFalse() #59325

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
Jan 2, 2025
Merged

[Config] Add ifFalse() #59325

merged 1 commit into from
Jan 2, 2025

Conversation

OskarStark
Copy link
Contributor

Q A
Branch? 7.3
Bug fix? no
New feature? yes
Deprecations? no
Issues --
License MIT

Spottet while working on

It is much easier to use like IMHO:

->ifTrue(fn ($v) => false === $v)

@carsonbot carsonbot added this to the 7.3 milestone Dec 29, 2024
@carsonbot carsonbot changed the title Add ifFalse() [Config] Add ifFalse() Dec 29, 2024
Copy link
Member

@welcoMattic welcoMattic left a comment

Choose a reason for hiding this comment

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

Lil typo in commit message 🫣
Thanks @OskarStark!

@OskarStark
Copy link
Contributor Author

Lil typo in commit message 🫣

Fixed, thanks

@fabpot
Copy link
Member

fabpot commented Dec 30, 2024

Some broken tests looks related (8.2 low-deps for instance).

@OskarStark OskarStark force-pushed the feature/ifFalse branch 3 times, most recently from 072fec2 to 17125b9 Compare January 2, 2025 10:00
@OskarStark
Copy link
Contributor Author

Some broken tests looks related (8.2 low-deps for instance).

Indeed, fixed and rebased, thanks

@fabpot
Copy link
Member

fabpot commented Jan 2, 2025

Thank you @OskarStark.

@fabpot fabpot merged commit 348781c into symfony:7.3 Jan 2, 2025
9 checks passed
@OskarStark OskarStark deleted the feature/ifFalse branch January 2, 2025 11:56
OskarStark added a commit to OskarStark/symfony that referenced this pull request Jan 2, 2025
nicolas-grekas added a commit that referenced this pull request Mar 21, 2025
…sure based checks (arjenm)

This PR was squashed before being merged into the 7.3 branch.

Discussion
----------

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

| 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()`

Commits
-------

335bdbe [Config] Make ifFalse() consistent between value and closure based checks
@fabpot fabpot mentioned this pull request May 2, 2025
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.

6 participants