-
-
Notifications
You must be signed in to change notification settings - Fork 84
Fix entity query count() to return non-negative-int type #910
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
base: main
Are you sure you want to change the base?
Conversation
@mglaman 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs. I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review. |
…rations Co-authored-by: mglaman <3698644+mglaman@users.noreply.github.com>
@copilot can you fix lint job and test fails |
Co-authored-by: mglaman <3698644+mglaman@users.noreply.github.com>
Fixed the lint and test issues. The main problem was trying to call a private constructor on Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
final class EntityQueryExecuteWithoutAccessCheckCountType extends IntegerType | ||
{ | ||
|
||
public function describe(VerbosityLevel $level = null): string | ||
{ | ||
return 'int<0, max>'; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this should extend IntegerRangeType
instead of IntegerType
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot can this class extend IntegerRangeType and not override describe
, instead just ensure the minimum is always 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the class to extend IntegerRangeType
and removed the custom describe()
method. The constructor now initializes with parent::__construct(0, null)
to ensure the minimum is always 0, creating a non-negative integer range. Commit 9e073fc.
…rRangeType with minimum 0 Co-authored-by: mglaman <3698644+mglaman@users.noreply.github.com>
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Entity query count operations now return
non-negative-int
(int<0, max>
) instead of the genericint
type, making PHPStan's type analysis more precise and eliminating false positives when methods expect non-negative integers.Problem
Previously, entity query count operations would return a generic
int
type:This would trigger PHPStan errors:
Solution
Updated the type system to recognize that entity query counts can never be negative:
EntityQueryDynamicReturnTypeExtension: Count queries with access checks now return
IntegerRangeType::createAllGreaterThanOrEqualTo(0)
instead ofIntegerType
EntityQueryExecuteWithoutAccessCheckCountType: Now extends
IntegerRangeType
directly with constructor ensuring minimum value is always 0, eliminating the need for customdescribe()
override while maintaining the distinct class needed for rule detectionTest expectations: Updated to expect
int<0, max>
for all count operationsImpact
int<0, max>
(non-negative-int)@return non-negative-int
work without PHPStan errorsint<0, max>
is a subset ofint
The change is minimal and surgical, affecting only the return types of count operations to be more semantically accurate.
Fixes #909.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.