-
Notifications
You must be signed in to change notification settings - Fork 16
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
chore: better PHPStan support #244
Conversation
WalkthroughThis pull request updates the changelog for version 8.3.1, reflecting a date change for version 8.3.0 and the addition of PHPStan support improvements. The Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
- message: "#^Return type \\(Generator\\<int, array, mixed, mixed\\>\\) of method Colopl\\\\Spanner\\\\Connection\\:\\:cursor\\(\\) should be compatible with return type \\(Generator\\<int, stdClass, mixed, mixed\\>\\) of method Illuminate\\\\Database\\\\Connection\\:\\:cursor\\(\\)$#" | ||
count: 1 | ||
path: src/Connection.php |
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.
💡 Codebase verification
Return type mismatch between parent and child class requires attention
The verification confirms there is indeed a type compatibility issue:
- The parent class
Illuminate\Database\Connection::cursor()
expectsGenerator<int, stdClass, mixed, mixed>
- The current implementation in
src/Connection.php
returnsGenerator<int, array<array-key, mixed>>
as seen in theexecuteQuery
method's return type documentation
This is a legitimate type mismatch that needs to be addressed in one of two ways:
- Modify the implementation to convert the array entries to
stdClass
objects before yielding - Document the intentional deviation and suppress this specific PHPStan error if returning arrays is the desired behavior
🔗 Analysis chain
Confirm compatibility of the updated return type requirement.
With this new error message asserting that cursor()
must return stdClass
entries rather than array
entries, ensure that the actual return type in src/Connection.php
matches the expected Generator<int, stdClass, mixed, mixed>
signature. If the intention is to return arrays, this rule might require further refinement or an added suppression/exclusion in phpstan.neon
to accurately reflect the design.
Below is an optional script to locate the cursor()
method in src/Connection.php
and confirm its documented return type:
Let me gather more information about the return type implementation.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the documented return type for Connection::cursor in src/Connection.php.
# Search for the cursor method signature and nearby doc comments to confirm consistency
rg -A 5 "function cursor" src/Connection.php
Length of output: 580
Script:
#!/bin/bash
# Check the executeQuery method to see the actual return type implementation
rg -B 2 -A 10 "executeQuery" src/Connection.php
Length of output: 1401
Add type definition for better PHPStan support
Checklist
Summary by CodeRabbit
New Features
Documentation
cursor
method in the Connection class with clearer return type annotations.Bug Fixes