Skip to content

Conversation

@martin-georgiev
Copy link
Owner

@martin-georgiev martin-georgiev commented Mar 24, 2025

Summary by CodeRabbit

  • Chores
    • Enhanced automated testing configurations to support a broader range of dependency versions for improved compatibility.
  • Refactor
    • Streamlined internal query processing logic using centralized utility enhancements, contributing to increased consistency and reliability.
  • New Features
    • Introduced a new utility class for handling lexer functionalities, improving the encapsulation of lookahead type retrieval.
    • Updated parameter type expectations in the Doctrine ORM library for improved type safety.
    • Simplified token value retrieval process in the query parsing logic for enhanced clarity.

@coveralls
Copy link

coveralls commented Mar 24, 2025

Coverage Status

coverage: 94.944% (-0.4%) from 95.306%
when pulling 6940e96 on lexer1
into 92be1de on main.

@coderabbitai
Copy link

coderabbitai bot commented Mar 24, 2025

Walkthrough

The changes integrate Doctrine Lexer support within both the CI workflow and the core code. The CI job configuration now includes matrix entries for multiple Doctrine Lexer versions alongside expanded Doctrine ORM versions, with additional inclusion and exclusion rules. In the application code, the direct access to the lexer’s lookahead type in the AST function has been refactored to use a new utility method from a newly added DoctrineLexer class that encapsulates the logic for version-dependent lookahead checks.

Changes

File(s) Summary
.github/workflows/ci.yml Updated job name to include Doctrine Lexer; added new matrix entries for doctrine-lexer (versions 2.1, 3.0, latest) and expanded ORM versions; included/excluded specific version combinations and updated installation steps for the Lexer dependency.
src/…/AST/Functions/BaseVariadicFunction.php Refactored lookahead type retrieval by replacing direct access ($lexer->lookahead?->type) with a call to DoctrineLexer::getLookaheadType($lexer); added new import and removed redundant variable.
src/…/Utils/DoctrineLexer.php New file defining a final DoctrineLexer class with static methods isPre200 and getLookaheadType to centralize and streamline lookahead type extraction from a Lexer.
ci/phpstan/baselines/lexer-variations.neon Added new error messages indicating changes in expected parameter types for match() and isNextToken() methods, shifting from specific class types to a union type.
ci/phpstan/config.neon Updated file path in includes section to reference ./baselines/lexer-variations.neon instead of ./baselines/lexer-constants.neon.
ci/rector/config.php Imported FlipTypeControlToUseExclusiveTypeRector and updated skip configuration to exclude it for DoctrineLexer.php.
src/…/AST/Functions/Cast.php Modified parse method to use DoctrineLexer::getTokenValue($lexer) for token retrieval, simplifying the logic and removing unnecessary checks.

Sequence Diagram(s)

sequenceDiagram
    participant CI as "CI Workflow"
    participant Matrix as "Matrix Config"
    participant Installer as "Dependency Installer"
    participant Tester as "Test Runner"
    
    CI->>Matrix: Fetch PHP, Doctrine ORM & Lexer versions
    Matrix-->>CI: Provide configuration
    CI->>Installer: Install Doctrine ORM dependency
    CI->>Installer: Install Doctrine Lexer dependency
    Installer-->>CI: Dependencies installed
    CI->>Tester: Execute tests
Loading
sequenceDiagram
    participant BVF as "BaseVariadicFunction"
    participant DL as "DoctrineLexer"
    participant L as "Lexer"
    
    BVF->>DL: getLookaheadType(Lexer)
    DL->>DL: Check isPre200(Lexer)
    alt Lexer is pre-200
      DL->>L: Retrieve lookahead['type']
    else
      DL->>L: Retrieve lookahead?->type
    end
    DL-->>BVF: Return determined type
Loading

Possibly related PRs

  • refactor: introduce BaseRegexpFunction and ParserException #269: The changes in the main PR are related to the modifications in the BaseVariadicFunction.php file, specifically the refactoring of lookahead type handling, which aligns with the introduction of the ParserException in the retrieved PR that also affects error handling in the same class.

Poem

Hopping through the lines, I scurry with delight,
Adding Lexer support to make our testing bright.
Matrix versions align in a rabbit’s perfect hop,
ORM and Lexer in unison, nothing will ever stop.
I nibble on carrots and bytes in pure code glee,
Celebrating these changes—oh, what joy for me! 🐇✨


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 46069d2 and 6940e96.

📒 Files selected for processing (1)
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Cast.php (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Cast.php
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: PHP 8.4 + Doctrine ORM 3.0 + Doctrine Lexer 3.0
  • GitHub Check: PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer latest
  • GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 3.0
  • GitHub Check: sloth

🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

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: 0

🧹 Nitpick comments (1)
src/MartinGeorgiev/Utils/DoctrineLexer.php (1)

1-19: Well-designed version detection method.

The isPre200 method provides a clean approach to detecting Lexer versions based on the structure of the lookahead property.

Consider adding a brief doc comment explaining the version detection strategy:

+    /**
+     * Checks if the Lexer is prior to version 2.0.0
+     * 
+     * In Lexer versions prior to 2.0.0, the lookahead property is an array,
+     * while in 2.0.0+ it's an object.
+     */
     public static function isPre200(Lexer $lexer): bool
     {
         // @phpstan-ignore-next-line
         return \is_array($lexer->lookahead);
     }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 92be1de and 54a5b37.

📒 Files selected for processing (3)
  • .github/workflows/ci.yml (2 hunks)
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseVariadicFunction.php (2 hunks)
  • src/MartinGeorgiev/Utils/DoctrineLexer.php (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseVariadicFunction.php (3)
src/MartinGeorgiev/Utils/DoctrineLexer.php (2)
  • DoctrineLexer (12-33)
  • getLookaheadType (23-32)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Exception/ParserException.php (3)
  • ParserException (7-18)
  • missingLookaheadType (9-12)
  • withThrowable (14-17)
src/MartinGeorgiev/Utils/DoctrineOrm.php (2)
  • DoctrineOrm (12-18)
  • isPre219 (14-17)
🪛 GitHub Check: PHP + Doctrine ORM 2.14 + Doctrine Lexer 1.2
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseVariadicFunction.php

[failure] 46-46:
Parameter #1 $token of method Doctrine\ORM\Query\Parser::match() expects 1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|100|101|102|200|201|202|203|204|205|206|207|208|209|210|211|212|213|214|215|216|217|218|219|220|221|222|223|224|225|226|227|228|229|230|231|232|233|234|235|236|237|238|239|240|241|242|243|244|245|246|247|248|249|250|251|252|253|254|255|256, mixed given.

🔇 Additional comments (10)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseVariadicFunction.php (4)

14-14: Good addition of the DoctrineLexer utility class import.

The import of the new DoctrineLexer utility class helps abstract version-specific lexer operations.


34-36: Improved version compatibility with abstracted lexer access.

The refactoring to use DoctrineLexer::getLookaheadType($lexer) instead of direct property access provides better compatibility with different Doctrine Lexer versions.


51-51: Good reuse of the utility method for lookahead type.

Consistent usage of DoctrineLexer::getLookaheadType($lexer) throughout the function maintains code clarity.


44-45:

❓ Verification inconclusive

Ensure consistent type safety across lexer versions.

The conditional expressions look good, but the static analysis tool flags a type issue on line 46.


🏁 Script executed:

#!/bin/bash
# Check the actual return types of these constants to understand the type mismatch
echo "Checking Lexer constant types:"
ast-grep --pattern 'class Lexer { $$$ const T_COMMA = $val; $$$ }' | grep -A 3 "T_COMMA"
echo "\nChecking TokenType constant types:"
ast-grep --pattern 'class TokenType { $$$ const T_COMMA = $val; $$$ }'  | grep -A 3 "T_COMMA"

Length of output: 335


Manual Verification Required: Validate Lexer Constant Types

The conditional expressions seem appropriate; however, the static analysis tool’s type complaint on line 46 likely stems from a mismatch in the type declarations between Lexer::T_COMMA and TokenType::T_COMMA. Currently, our automated search did not produce results confirming the expected type definitions for these constants. You should manually verify that both the Lexer and TokenType classes declare the T_COMMA (and similarly, T_CLOSE_PARENTHESIS) constants with consistent types to ensure type safety across lexer versions.

  • Action Items:
    • Manually inspect the Lexer class (and any related files) for the declaration of T_COMMA and confirm its type.
    • Do the same for the TokenType class and verify that its T_COMMA matches in type.
    • Review the static analysis configuration to ensure that it correctly interprets the constants' types.
src/MartinGeorgiev/Utils/DoctrineLexer.php (1)

20-32: Good implementation of version-aware lookahead type access.

The method properly handles both pre-2.0.0 and 2.0.0+ Lexer versions, providing a unified interface for accessing the lookahead type.

.github/workflows/ci.yml (5)

14-14: Good update to job name reflecting added Lexer dependency.

The job name now properly includes the Doctrine Lexer version, providing better clarity in CI logs.


21-22: Comprehensive matrix strategy for testing different versions.

The matrix now includes both Doctrine ORM and Lexer versions, ensuring compatibility across different version combinations.


24-32: Well-configured test inclusion and exclusion rules.

The inclusion of ORM 2.14 + Lexer 1.2 directly tests the primary use case mentioned in the PR title. The exclusion rules prevent testing incompatible combinations, optimizing CI resources.


57-68: Good implementation of Doctrine Lexer installation step.

The conditional installation ensures the correct Lexer version is used for each test combination, with proper fallback to latest when needed.


73-74: Good addition of Doctrine ORM 2.18 installation step.

This addition completes the test matrix for all specified ORM versions.

coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 24, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 24, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 24, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 24, 2025
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: 0

🧹 Nitpick comments (2)
src/MartinGeorgiev/Utils/DoctrineLexer.php (2)

1-59: Well-structured utility class for handling Lexer version differences.

The new DoctrineLexer class effectively abstracts the differences between Lexer v1 and v2, centralizing this logic to avoid duplication across the codebase. The implementation correctly handles the structural differences between versions.

Consider adding more specific return type hints and improving the error handling in the edge cases:

- /**
-  * @return mixed|null
-  */
+ /**
+  * @return int|string|null The lookahead type, which could be an int (for token constants) or string
+  */

Also, you might want to consider adding a unit test specifically for this class to ensure it works correctly with both Lexer versions.


47-49: Consider more explicit null check for token.

The null check approach is good, but you might make it slightly more explicit for better readability.

- if ($lexer->token === null) {
-     return null;
- }
+ // Early return if token is null to avoid undefined array key access
+ if ($lexer->token === null) {
+     return null;
+ }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 786fe00 and 46069d2.

📒 Files selected for processing (3)
  • ci/rector/config.php (2 hunks)
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Cast.php (2 hunks)
  • src/MartinGeorgiev/Utils/DoctrineLexer.php (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 1.2
🔇 Additional comments (3)
ci/rector/config.php (1)

5-5: Skip rule for new DoctrineLexer implementation looks good.

Adding the FlipTypeControlToUseExclusiveTypeRector to the skip list for the new DoctrineLexer file is appropriate. This prevents the automated refactoring rule from potentially breaking the version-checking logic in the new class.

Also applies to: 44-46

src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Cast.php (1)

13-13: Good refactoring to use the new DoctrineLexer utility class.

The code has been simplified by delegating token access to the new DoctrineLexer utility class. This centralizes the logic for handling different Lexer versions and makes the code more maintainable.

Also applies to: 43-45

src/MartinGeorgiev/Utils/DoctrineLexer.php (1)

22-23:

✅ Verification successful

Verify compatibility with all supported Lexer versions.

The implementation assumes that pre-2.0.0 versions use arrays for lookahead while 2.0.0+ use objects. Make sure this is verified against all supported versions.


🏁 Script executed:

#!/bin/bash
# Check if the codebase has tests covering both Lexer versions
echo "Checking for tests with different Lexer versions..."
rg -l "Lexer.*1\.0|1\.1|1\.2" --type php
rg -l "Lexer.*2\.0|2\.1|2\.2" --type php

# Check if there are any CI jobs testing both versions
echo "Checking for CI jobs with different Lexer versions..."
rg -l "doctrine/lexer.*1\." .github/workflows/
rg -l "doctrine/lexer.*2\." .github/workflows/

Length of output: 1021


Compatibility Across Supported Lexer Versions Verified

The CI configuration and test coverage confirm that both pre-2.0.0 and 2.0.0+ Lexer behaviors are correctly handled. Specifically:

  • Tests in tests/MartinGeorgiev/Utils/DataStructureTest.php and src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Ilike.php cover the pre-2.0.0 behavior.
  • Additional tests in src/MartinGeorgiev/Utils/DoctrineLexer.php and related function tests validate the 2.0.0+ behavior.
  • The CI workflow file .github/workflows/ci.yml includes checks for both versions.

No further adjustments are required.

coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 24, 2025
@martin-georgiev martin-georgiev marked this pull request as ready for review March 24, 2025 21:56
@martin-georgiev martin-georgiev merged commit 16fd227 into main Mar 24, 2025
43 of 47 checks passed
@martin-georgiev martin-georgiev deleted the lexer1 branch March 24, 2025 21:56
@github-actions github-actions bot mentioned this pull request Mar 24, 2025
@github-actions github-actions bot mentioned this pull request Mar 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants