Skip to content

refactor: Enhance QueryConditionBuilder with offset expression methods and simplify NestedSetsBehavior updates. #52

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

Merged
merged 4 commits into from
Jul 3, 2025

Conversation

terabytesoftw
Copy link
Member

@terabytesoftw terabytesoftw commented Jul 3, 2025

Q A
Is bugfix? ✔️
New feature?
Breaks BC?

Summary by CodeRabbit

  • Refactor

    • Improved clarity and modularity of nested sets operations for better maintainability and readability.
    • Reorganized logic for moving nodes within and across trees into dedicated methods.
  • New Features

    • Added new helper methods for generating SQL update expressions, streamlining bulk updates of tree attributes.
  • Chores

    • Removed unused imports and temporary variables to clean up the codebase.

@terabytesoftw terabytesoftw added the bug Something isn't working label Jul 3, 2025
Copy link

coderabbitai bot commented Jul 3, 2025

Walkthrough

This update refactors the NestedSetsBehavior and QueryConditionBuilder classes to improve code clarity and modularity. It introduces helper methods for building SQL offset expressions, splits complex node movement logic into dedicated methods, and removes unused variables and imports. No changes are made to the external API or method signatures.

Changes

File(s) Change Summary
src/NestedSetsBehavior.php Refactored node movement logic by splitting moveNode() into executeSameTreeMove() and executeCrossTreeMove(). Replaced manual SQL expressions with helper methods. Removed unused variables/imports. Improved code organization and readability.
src/QueryConditionBuilder.php Added createOffsetExpression() and createOffsetUpdates() static methods for generating SQL offset expressions for bulk updates. Included detailed docblocks and examples.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant NestedSetsBehavior
    participant QueryConditionBuilder
    participant Database

    Caller->>NestedSetsBehavior: moveNode(context, currentTree, targetTree)
    alt Same tree
        NestedSetsBehavior->>NestedSetsBehavior: executeSameTreeMove(context, currentTree)
        NestedSetsBehavior->>QueryConditionBuilder: createOffsetUpdates(...)
        QueryConditionBuilder-->>NestedSetsBehavior: offset updates
        NestedSetsBehavior->>Database: update nodes with offset updates
    else Cross tree
        NestedSetsBehavior->>NestedSetsBehavior: executeCrossTreeMove(context, treeAttr, currentTree, targetTree)
        NestedSetsBehavior->>QueryConditionBuilder: createOffsetUpdates(...)
        QueryConditionBuilder-->>NestedSetsBehavior: offset updates
        NestedSetsBehavior->>Database: update nodes for cross-tree move
    end
Loading

Possibly related PRs

Poem

In the garden of code where the node trees grow,
Rabbits refactor, letting clarity flow.
With helpers for offsets and methods anew,
The branches align and the queries flew.
Now the tree stands tall, its structure precise—
Hopping through logic, oh, isn’t that nice?
🐇🌳

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 PHPStan (2.1.15)

Note: Using configuration file /phpstan.neon.
Invalid configuration:
Unexpected item 'parameters › yii2'.


📜 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 f07b2a2 and c42e168.

📒 Files selected for processing (1)
  • src/QueryConditionBuilder.php (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/QueryConditionBuilder.php
⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: phpunit / PHP 8.4-windows-latest
  • GitHub Check: phpunit / PHP 8.1-ubuntu-latest
  • GitHub Check: phpunit / PHP 8.3-windows-latest
  • GitHub Check: phpunit / PHP 8.2-windows-latest
  • GitHub Check: phpunit / PHP 8.1-windows-latest
  • GitHub Check: phpunit / PHP 8.2-ubuntu-latest
  • GitHub Check: phpunit-compatibility / PHP 8.2-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.4-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.1-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.3-windows-latest
  • GitHub Check: mutation / PHP 8.4-ubuntu-latest
  • GitHub Check: mutation / PHP 8.4-ubuntu-latest
✨ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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

codecov bot commented Jul 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (bfd440c) to head (c42e168).
Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##                main       #52   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity       130       137    +7     
===========================================
  Files              4         4           
  Lines            525       554   +29     
===========================================
+ Hits             525       554   +29     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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 bfd440c and 09bd62a.

📒 Files selected for processing (2)
  • src/NestedSetsBehavior.php (15 hunks)
  • src/QueryConditionBuilder.php (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: terabytesoftw
PR: yii2-extensions/nested-sets-behavior#13
File: src/NestedSetsBehavior.php:145-145
Timestamp: 2025-06-29T11:22:41.889Z
Learning: The user terabytesoftw prefers to keep PRs focused and small, implementing enhancements in separate dedicated PRs rather than bundling multiple changes together.
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: phpunit / PHP 8.2-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.3-ubuntu-latest
  • GitHub Check: phpunit / PHP 8.3-windows-latest
  • GitHub Check: phpunit / PHP 8.1-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.1-windows-latest
  • GitHub Check: mutation / PHP 8.4-ubuntu-latest
  • GitHub Check: mutation / PHP 8.4-ubuntu-latest
🔇 Additional comments (14)
src/QueryConditionBuilder.php (3)

7-7: LGTM! Clean import statement update.

The addition of Connection and Expression imports is appropriate for the new offset expression methods.


214-250: Well-implemented SQL expression generator with proper security measures.

The method correctly:

  • Uses quoteColumnName() to prevent SQL injection
  • Handles positive and negative offsets appropriately
  • Returns proper Expression objects for safe SQL generation

251-292: Clean wrapper method for bulk offset expressions.

Good implementation that promotes code reuse and maintains consistency across multiple attribute updates.

src/NestedSetsBehavior.php (11)

170-186: Excellent refactoring using the new QueryConditionBuilder methods.

The changes improve code clarity and maintainability by replacing manual SQL expression construction with the standardized helper methods.


518-536: Clean refactoring with improved method chaining.

Good simplification that removes unnecessary temporary variables while maintaining functionality.


804-820: Consistent refactoring pattern applied.

Maintains the same clean approach as other query methods.


903-910: Clean simplification of sibling query.


947-966: Consistent refactoring maintains code quality.


1038-1045: Well-structured sibling query refactoring.


1068-1077: Simplified attribute assignment improves readability.


1099-1106: Consistent simplification in root node initialization.


1156-1166: Excellent separation of concerns in node movement logic.

The delegation to specialized methods for same-tree and cross-tree movements improves code clarity and maintainability.


1220-1232: Consistent use of QueryConditionBuilder for attribute shifting.


1467-1503: Well-structured refactoring with improved parameter ordering.

The changes make the method signature more intuitive by placing the current tree value before the target tree value, and the implementation consistently uses the new QueryConditionBuilder methods.

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.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy