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

chore: better PHPStan support #244

Merged
merged 4 commits into from
Dec 25, 2024
Merged

chore: better PHPStan support #244

merged 4 commits into from
Dec 25, 2024

Conversation

zeriyoshi
Copy link
Contributor

@zeriyoshi zeriyoshi commented Dec 24, 2024

Add type definition for better PHPStan support

Checklist

  • CHANGELOG

Summary by CodeRabbit

  • New Features

    • Added a new method to the Query Builder for retrieving data in a structured collection format.
  • Documentation

    • Updated the changelog to reflect the new version entry for v8.3.1.
    • Enhanced documentation for the cursor method in the Connection class with clearer return type annotations.
  • Bug Fixes

    • Improved compatibility with PHPStan through updates to error handling parameters.

Copy link

coderabbitai bot commented Dec 24, 2024

Walkthrough

This 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 Connection class's cursor method has enhanced documentation with an explicit return type annotation. Additionally, a new get() method has been introduced in the Query\Builder class, allowing data retrieval in a structured collection format.

Changes

File Change Summary
CHANGELOG.md Updated version entry for v8.3.0 to 2024-12-25 and added new entry for v8.3.1 (2024-12-24) with PHPStan support improvement.
src/Connection.php Updated cursor method PHPDoc block and added explicit return type Generator<int, array<array-key, mixed>>.
src/Query/Builder.php Imported Collection class and added new get($columns = ['*']) method returning Collection<int, array<array-key, mixed>>.

Possibly related PRs

  • feat: consolidate schema options formatting #241: The changes in the CHANGELOG.md for version 8.3.0 include the addition of support for change streams, which is directly related to the main PR's updates regarding PHPStan support and changelog entries.
  • feat: IDENTITY column support #243: The changelog for version 8.3.0 also mentions support for IDENTITY columns, which aligns with the overall enhancements and updates noted in the main PR regarding versioning and changelog documentation.

Suggested labels

enhancement

Suggested reviewers

  • Uyan712
  • dkkoma

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c48659d and cdea69a.

📒 Files selected for processing (1)
  • phpstan.neon (1 hunks)

Comment on lines +16 to +18
- 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
Copy link

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() expects Generator<int, stdClass, mixed, mixed>
  • The current implementation in src/Connection.php returns Generator<int, array<array-key, mixed>> as seen in the executeQuery 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

@taka-oyama taka-oyama added the enhancement New feature or request label Dec 25, 2024
@taka-oyama taka-oyama merged commit c21ad52 into master Dec 25, 2024
1 check passed
@taka-oyama taka-oyama deleted the phpstan branch December 25, 2024 03:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request waiting for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants