-
-
Notifications
You must be signed in to change notification settings - Fork 863
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
CONSTANT_SCALAR_UNION_THRESHOLD makes phpDoc enums unreliable #3555
Comments
PHPStan is about 33% slower if we remove this limit. We could do some performance improvements and benchmarking so that CONSTANT_SCALAR_UNION_THRESHOLD isn't needed at all. |
BTW this scenario could be solved by changing the union |
I'm sure this is no surprise, but the same thing occurs when using strings rather than integers: https://phpstan.org/r/14792d1b-caba-4453-bb2f-5dfdd305cc40. That particular example is quite contrived; in my actual codebase I've got a list of 40-odd strings that correspond to edge labels in a graph database, so something along the lines of Unfortunately I didn't discover this limitation until the very end of a gigantic refactor (replacing all hardcoded strings with constants in the codebase), which negated the majority of the change :( Oh well, these things happen. I'd be happy to investigate some alternative implementations to address the performance concerns, though I'll admit I'm not entirely sure where to begin ( |
The place in question is Another issue related to this is #3530. |
If performance is the only reason why CONSTANT_SCALAR_UNION_THRESHOLD exists, why don't you do the normal check (with the threshold) and if phpstan detects that the limit is reached (and therefore the verification will fail), re-do the check of that input-file without limit? This way only a few input files would be slower in processing while all other checks are fast. |
I managed to solve this. * Removed CONSTANT_SCALAR_UNION_THRESHOLD: phpstan/phpstan-src@c56d866
Look forward to the next release (0.12.95) :) |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Bug report
Specifying type to be from specific enumeration based on class constants is extremely useful feature. But current limitation to 8 items only can also lead to false negative rendering the feature unreliable and rather dangerous.
Code snippet that reproduces the problem
https://phpstan.org/r/d08f913e-0ad8-4fd6-9b26-fba163dddd6a
Expected output
Error detected:
Solution
Do you have vision on how this should be further improved? I can imagine:
I think each of these solutions would allow user to depend on this feature to work reliably.
The text was updated successfully, but these errors were encountered: