Skip to content

fix: new phpstan errors #273

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

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft

fix: new phpstan errors #273

wants to merge 10 commits into from

Conversation

taka-oyama
Copy link
Collaborator

@taka-oyama taka-oyama commented Apr 28, 2025

 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   Schema/Builder.php                                                                                                                                                                                                                                                       
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  48     Return type (list<array{name: string, type: string, parent: string}>) of method Colopl\Spanner\Schema\Builder::getTables() should be compatible with return type (list<array{name: string, schema: string|null, schema_qualified_name: string, size: int|null, comment:  
         string|null, collation: string|null, engine: string|null}>) of method Illuminate\Database\Schema\Builder::getTables()                                                                                                                                                    
         🪪  method.childReturnType                                                                                                                                                                                                                                               
  75     Call to function in_array() with arguments string, list<array{name: string, columns: list<string>, type: string, unique: bool, primary: bool}> and true will always evaluate to false.  
         🪪  function.impossibleType                                                                                                                                                             
         💡 Because the type is coming from a PHPDoc, you can turn off this check by setting treatPhpDocTypesAsCertain: false in your phpstan.neon.                                              
  150    Strict comparison using === between array{name: string, columns: list<string>, type: string, unique: bool, primary: bool} and 'PRIMARY_KEY' will always evaluate to false.              
         🪪  identical.alwaysFalse                                                                                                                                                               
         💡 Because the type is coming from a PHPDoc, you can turn off this check by setting treatPhpDocTypesAsCertain: false in your phpstan.neon.                                              
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 


Summary by CodeRabbit

  • New Features

    • Added support for processing and standardizing table metadata, including schema and size details.
    • Enhanced table retrieval to allow optional schema filtering.
  • Improvements

    • Table and column metadata now includes additional and more consistently formatted fields, including a new generation attribute for columns.
    • Table listing queries now support schema-based filtering for more precise results.
  • Documentation

    • Improved and simplified internal documentation for better clarity.

@taka-oyama taka-oyama added bug Something isn't working waiting for review labels Apr 28, 2025
@taka-oyama taka-oyama requested a review from a team April 28, 2025 06:25
@taka-oyama taka-oyama self-assigned this Apr 28, 2025
Copy link

coderabbitai bot commented Apr 28, 2025

## Walkthrough

This update introduces a new method for processing table metadata in the query processor and refines the handling of table and column metadata throughout the schema builder and grammar. The schema builder’s method for retrieving tables now accepts an optional schema parameter and processes results using the new processor method. The grammar’s table compilation logic is updated to support schema filtering and improved SQL generation. Docblocks across several methods are simplified, and minor adjustments are made to metadata key ordering, type casting, and SQL query formatting for consistency.

## Changes

| Files/Paths                  | Change Summary                                                                                                                                                                                                                  |
|-----------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| src/Query/Processor.php      | Added `processTables` method for standardizing table metadata; updated `processColumns` to swap order of `type` and `type_name`, add `generation` key, refine type casting; simplified docblocks for `processIndexes` and `processForeignKeys`. |
| src/Schema/Builder.php       | Modified `getTables` to accept optional `$schema`, use `compileTables` with schema, assert raw results as list, and process results with `processTables`; replaced `getIndexes` with `getIndexListing` in `dropIndexIfExist` and `dropAllTables`. |
| src/Schema/Grammar.php       | Updated `compileTables` to handle optional schema parameter by normalizing input; changed SQL to select `table_schema AS schema` alongside other columns; modified WHERE clause to filter by `table_type = 'BASE TABLE'` and `table_schema IN (...)`; adjusted SQL string concatenation formatting. |
| tests/Schema/BuilderTestLast.php | Adjusted expected column metadata in `test_getColumns()` to reorder keys and include new `generation` key with null value.                                                                                                    |

## Suggested labels

`waiting for review`

## Suggested reviewers

- kt81

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 424cc71 and 563d472.

📒 Files selected for processing (3)
  • src/Query/Processor.php (3 hunks)
  • src/Schema/Grammar.php (1 hunks)
  • tests/Schema/BuilderTestLast.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • tests/Schema/BuilderTestLast.php
  • src/Schema/Grammar.php
  • src/Query/Processor.php
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Run-PHPUnit
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 2

🔭 Outside diff range comments (3)
src/Schema/Grammar.php (3)

67-73: 🛠️ Refactor suggestion

Update compileIndexes method to use the schema parameter

The method accepts a schema parameter but doesn't use it in the SQL query. The table_schema filter is hardcoded to an empty string.

return sprintf(
-    'select index_name as `index_name` from information_schema.indexes where table_schema = \'\' and table_name = %s',
+    'select index_name as `index_name` from information_schema.indexes where table_schema = %s and table_name = %s',
+    $this->quoteString($schema ?? ''),
    $this->quoteString($table),
);

82-88: 🛠️ Refactor suggestion

Update compileForeignKeys method to use the schema parameter

The method accepts a schema parameter but doesn't use it in the SQL query. The table_schema filter is hardcoded to an empty string.

return sprintf(
-    'select constraint_name as `key_name` from information_schema.table_constraints where constraint_type = "FOREIGN KEY" and table_schema = \'\' and table_name = %s',
+    'select constraint_name as `key_name` from information_schema.table_constraints where constraint_type = "FOREIGN KEY" and table_schema = %s and table_name = %s',
+    $this->quoteString($schema ?? ''),
    $this->quoteString($table),
);

97-103: 🛠️ Refactor suggestion

Update compileColumns method to use the schema parameter

The method accepts a schema parameter but doesn't use it in the SQL query. The table_schema filter is hardcoded to an empty string.

return sprintf(
-    'select * from information_schema.columns where table_schema = \'\' and table_name = %s',
+    'select * from information_schema.columns where table_schema = %s and table_name = %s',
+    $this->quoteString($schema ?? ''),
    $this->quoteString($table),
);
🛑 Comments failed to post (2)
composer.json (1)

14-14: 💡 Verification agent

🧩 Analysis chain

Updated Laravel framework dependency to support version 12.

The package now requires Laravel 12.0 or higher, which aligns with the PHPStan fixes and schema builder return type compatibility changes mentioned in the PR objectives.


🏁 Script executed:

#!/bin/bash
# Verify that Laravel 12 requires PHP 8.2+
curl -s https://packagist.org/packages/laravel/framework.json | jq '.package.versions["12.0.0"].require.php'

Length of output: 115


🏁 Script executed:

#!/bin/bash
# Use Packagist API v2 to check the PHP requirement for Laravel 12.0.0
curl -s https://repo.packagist.org/p2/laravel/framework.json \
  | jq '.packages["laravel/framework"][] 
         | select(.version == "12.0.0") 
         | .require["php"]'

Length of output: 171


🏁 Script executed:

#!/bin/bash
# List PHP requirements for Laravel 12.x versions from Packagist v1
curl -s https://packagist.org/packages/laravel/framework.json | jq -r '
  .package.versions
  | to_entries[]
  | select(.key | test("^(v)?12\\."))
  | "\(.key): \(.value.require.php // \"none\")"
'

Length of output: 413


🏁 Script executed:

#!/bin/bash
# Fetch Laravel v12.0.0 composer.json directly from GitHub to inspect the PHP requirement
curl -s https://raw.githubusercontent.com/laravel/framework/12.0.0/composer.json \
  | jq -r '.require.php'

Length of output: 167


🏁 Script executed:

#!/bin/bash
# 1. Check PHP requirement for Laravel 12.0.0 via Packagist v2 API
echo "Packagist v2 API (version 12.0.0):"
curl -s https://repo.packagist.org/p2/laravel/framework.json \
  | jq -r '.packages["laravel/framework"][] 
      | select(.version == "12.0.0") 
      | .require.php // "not found"'

# 2. Inspect composer.json on GitHub for branch 12.x
echo "GitHub composer.json (branch 12.x):"
curl -s https://raw.githubusercontent.com/laravel/framework/12.x/composer.json \
  | jq -r '.require.php // "not found"'

Length of output: 464


Ensure PHP version requirement is updated to ^8.2

Laravel 12 requires PHP ^8.2. Please verify that your composer.json require.php entry is set accordingly to avoid compatibility issues.

  • composer.json (require → php): bump version constraint to ^8.2 if not already.
src/Schema/Grammar.php (1)

48-58: ⚠️ Potential issue

Fix SQL query syntax errors in compileTables method

There are several syntax errors in the SQL query that need to be fixed:

  1. Missing comma between parent and table_schema columns
  2. Missing AND between the table_type condition and table_schema condition
return
-    'select `table_name` as name, `table_type` as type, `parent_table_name` as parent `table_schema` as `schema` ' .
-    'from information_schema.tables where table_type = \'BASE TABLE\'' .
-    'table_schema in (' . $this->quoteString($schema) . ')';
+    'select `table_name` as name, `table_type` as type, `parent_table_name` as parent, `table_schema` as `schema` ' .
+    'from information_schema.tables where table_type = \'BASE TABLE\' AND ' .
+    'table_schema in (' . $this->quoteString($schema) . ')';
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

    public function compileTables($schema)
    {
        if ($schema === null || (is_array($schema) && count($schema) === 0)) {
            $schema = '';
        }

        return
            'select `table_name` as name, `table_type` as type, `parent_table_name` as parent, `table_schema` as `schema` ' .
            'from information_schema.tables where table_type = \'BASE TABLE\' AND ' .
            'table_schema in (' . $this->quoteString($schema) . ')';
    }

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 2c331d0 and fd54205.

📒 Files selected for processing (1)
  • src/Schema/Grammar.php (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Run-PHPUnit

@taka-oyama
Copy link
Collaborator Author

#274 needs to be fixed first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant