Skip to content
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

Fix type hint on OrderBy attribute #11779

Closed
wants to merge 1 commit into from
Closed

Conversation

curry684
Copy link

@curry684 curry684 commented Jan 6, 2025

PHPStan 2.0 does not accept a string backed enum as a string.

PHPStan 2.0 does not accept a string backed enum as a string.
@greg0ire
Copy link
Member

greg0ire commented Jan 6, 2025

Please retarget to 2.20.x, I think it also applies here.

@curry684
Copy link
Author

curry684 commented Jan 6, 2025

It was completely rewritten for 3.x so needs a different change: https://github.com/doctrine/orm/blob/2.20.x/src/Mapping/OrderBy.php

I doubt it's really worth targeting 2.x as the error only occurs when picking up on the deprecation of Criteria::ASC which tells you to upgrade to Order::Ascending, and then running PHPStan 2 on max level.

curry684 added a commit to curry684/orm that referenced this pull request Jan 6, 2025
@curry684
Copy link
Author

curry684 commented Jan 6, 2025

Created #11780 targetting 2.20.x

@greg0ire
Copy link
Member

greg0ire commented Jan 6, 2025

Given the static analysis error, I guess targeting 2 is indeed not worth it. Sorry for the confusion.

@derrabus
Copy link
Member

derrabus commented Jan 6, 2025

Do we really allow the Order enum here? I'm confused.

@curry684
Copy link
Author

curry684 commented Jan 6, 2025

The deprecation explicitly replaces the const string with a reference to Order::Ascending:

https://github.com/doctrine/collections/blob/2790cb57e6510e4404873bdca6688e447550d720/src/Criteria.php#L22-L26

Which is a backed enum:

https://github.com/doctrine/collections/blob/2790cb57e6510e4404873bdca6688e447550d720/src/Order.php#L7-L11

But, come to think of it, the deprecation may just be triggered horribly wrong here as I vaguely recall Doctrine ORM having major internal inconsistencies here and requiring the literal "ASC" string in anything relating to OrderBy instead of providing constants/enums for it, or relying on those in Collections despite it being a direct dependency, which historically just work because they're the same string anyway.

@derrabus
Copy link
Member

derrabus commented Jan 6, 2025

None of our test cases use the enum for this attribute which indeed still demands a string. This change is not correct, sorry.

@derrabus derrabus closed this Jan 6, 2025
@curry684
Copy link
Author

curry684 commented Jan 6, 2025

Yep, just checked and using the enum causes some horrible crashes, so closing the PR is correct ofc.

But erm, are we ever going to fix the horrible inconsistencies here? Because I don't see why we're insisting on using constant magic strings (a strict no-go in every software architecture book) instead of relying on a well defined predictable enum of a direct dependency.

@curry684 curry684 deleted the patch-1 branch January 6, 2025 20:14
@derrabus
Copy link
Member

derrabus commented Jan 6, 2025

There's a discussion on this somewhere in this tracker, but I'm on a phone and can't look this up right now.

@curry684
Copy link
Author

curry684 commented Jan 6, 2025

At #11313

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants