Skip to content

feat: Add NestedSetsUpdateManager, QueryConditionBuilder, and UpdateExpressionBuilder for centralized database operations; refactor NestedSetsBehavior to utilize new managers and improve code maintainability. #47

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

Closed
wants to merge 4 commits into from

Conversation

terabytesoftw
Copy link
Member

@terabytesoftw terabytesoftw commented Jul 2, 2025

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

Summary by CodeRabbit

  • Refactor

    • Centralized and streamlined nested set tree update operations for improved maintainability and modularity.
    • Introduced new internal classes to handle query condition building and update expressions for nested set operations.
  • Tests

    • Updated tests to align with refactored internal logic and removed obsolete test methods.

terabytesoftw and others added 2 commits July 2, 2025 10:34
…dateExpressionBuilder` for centralized database operations; refactor `NestedSetsBehavior` to utilize new managers and improve code maintainability.
@terabytesoftw terabytesoftw added the enhancement New feature or request label Jul 2, 2025
Copy link

coderabbitai bot commented Jul 2, 2025

Walkthrough

The changes refactor nested set tree update logic by introducing a new NestedSetsUpdateManager class, along with supporting builder classes for query conditions and update expressions. The core behavior class delegates all update operations to the manager, removing duplicated logic. Related tests and subclass stubs are updated to reflect the new encapsulation.

Changes

File(s) Change Summary
src/NestedSetsBehavior.php Refactored to add a private $updateManager property and delegate all update logic to NestedSetsUpdateManager. Removed the shiftLeftRightAttribute method and added getUpdateManager().
src/NestedSetsUpdateManager.php Introduced new final class to centralize all nested set update operations, encapsulating logic for shifting, moving, and updating nodes.
src/QueryConditionBuilder.php, src/UpdateExpressionBuilder.php Added two new final classes to build query conditions and update expressions for nested set operations, supporting modular and reusable logic.
tests/NestedSetsBehaviorTest.php Removed tests that invoked the now-removed protected method shiftLeftRightAttribute through a subclass.
tests/support/stub/ExtendableNestedSetsBehavior.php Removed the method exposing the protected shiftLeftRightAttribute for testing purposes.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant NestedSetsBehavior
    participant NestedSetsUpdateManager
    participant QueryConditionBuilder
    participant UpdateExpressionBuilder
    participant DB

    Client->>NestedSetsBehavior: perform tree operation (insert, move, delete)
    NestedSetsBehavior->>NestedSetsUpdateManager: delegate operation (e.g. updateSubtreeForDeletion)
    NestedSetsUpdateManager->>QueryConditionBuilder: build query conditions
    NestedSetsUpdateManager->>UpdateExpressionBuilder: build update expressions
    NestedSetsUpdateManager->>DB: execute updateAll with conditions and expressions
Loading

Possibly related PRs

Suggested labels

bug

Poem

In the garden of trees, where the branches entwine,
A manager hops in, to keep order in line.
No more shifting alone—now helpers abound,
With builders and queries, the roots are sound.
The code is much neater, the logic more clear—
A rabbit’s delight as new structure appears! 🐇🌳

✨ 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 2, 2025

Codecov Report

Attention: Patch coverage is 80.89888% with 34 lines in your changes missing coverage. Please review.

Project coverage is 94.20%. Comparing base (60786a4) to head (6a4b1fe).

Files with missing lines Patch % Lines
src/NestedSetsUpdateManager.php 80.89% 17 Missing ⚠️
src/UpdateExpressionBuilder.php 63.33% 11 Missing ⚠️
src/QueryConditionBuilder.php 81.25% 6 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##                main      #47      +/-   ##
=============================================
- Coverage     100.00%   94.20%   -5.80%     
- Complexity       102      135      +33     
=============================================
  Files              3        6       +3     
  Lines            504      587      +83     
=============================================
+ Hits             504      553      +49     
- Misses             0       34      +34     

☔ 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: 6

🧹 Nitpick comments (2)
src/NestedSetsBehavior.php (1)

1389-1405: Consider aligning parameter order for clarity.

The parameter order differs between the method signature and the delegation call, which could cause confusion during maintenance.

 private function moveSubtreeToTargetTree(
-    mixed $targetNodeTreeValue,
-    mixed $currentOwnerTreeValue,
-    int $depth,
     int $leftValue,
+    int $rightValue,
     int $positionOffset,
-    int $rightValue,
+    int $depth,
+    mixed $currentOwnerTreeValue,
+    mixed $targetNodeTreeValue,
 ): void {
     $this->getUpdateManager()->moveSubtreeToTargetTree(
         $leftValue,
         $rightValue,
         $positionOffset,
         $depth,
         $currentOwnerTreeValue,
         $targetNodeTreeValue,
     );
 }
src/NestedSetsUpdateManager.php (1)

252-252: Fix formatting: remove extra space.

-        return  $this->leftValue;
+        return $this->leftValue;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 60786a4 and 0129580.

📒 Files selected for processing (6)
  • src/NestedSetsBehavior.php (9 hunks)
  • src/NestedSetsUpdateManager.php (1 hunks)
  • src/QueryConditionBuilder.php (1 hunks)
  • src/UpdateExpressionBuilder.php (1 hunks)
  • tests/NestedSetsBehaviorTest.php (0 hunks)
  • tests/support/stub/ExtendableNestedSetsBehavior.php (0 hunks)
💤 Files with no reviewable changes (2)
  • tests/support/stub/ExtendableNestedSetsBehavior.php
  • tests/NestedSetsBehaviorTest.php
🧰 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.839Z
Learning: The user terabytesoftw prefers to keep PRs focused and small, implementing enhancements in separate dedicated PRs rather than bundling multiple changes together.
🧬 Code Graph Analysis (2)
src/NestedSetsUpdateManager.php (4)
src/QueryConditionBuilder.php (5)
  • QueryConditionBuilder (26-163)
  • __construct (28-32)
  • createCrossTreeCondition (159-162)
  • createSubtreeCondition (127-130)
  • createMovementCondition (143-146)
src/UpdateExpressionBuilder.php (6)
  • UpdateExpressionBuilder (30-137)
  • __construct (32-38)
  • createSingleAttributeUpdate (119-124)
  • createSubtreeMovementAttributes (93-109)
  • createDepthUpdateAttributes (77-82)
  • createOffsetExpression (48-53)
src/NestedSetsBehavior.php (3)
  • moveSubtreeToTargetTree (1389-1405)
  • NestedSetsBehavior (47-1423)
  • getTreeValue (1363-1368)
tests/NestedSetsBehaviorTest.php (1)
  • primaryKey (1582-1585)
src/QueryConditionBuilder.php (2)
src/UpdateExpressionBuilder.php (1)
  • __construct (32-38)
src/NestedSetsUpdateManager.php (1)
  • __construct (65-85)
🪛 GitHub Check: codecov/patch
src/UpdateExpressionBuilder.php

[warning] 62-62: src/UpdateExpressionBuilder.php#L62
Added line #L62 was not covered by tests


[warning] 64-67: src/UpdateExpressionBuilder.php#L64-L67
Added lines #L64 - L67 were not covered by tests


[warning] 77-77: src/UpdateExpressionBuilder.php#L77
Added line #L77 was not covered by tests


[warning] 79-81: src/UpdateExpressionBuilder.php#L79-L81
Added lines #L79 - L81 were not covered by tests


[warning] 133-133: src/UpdateExpressionBuilder.php#L133
Added line #L133 was not covered by tests


[warning] 135-135: src/UpdateExpressionBuilder.php#L135
Added line #L135 was not covered by tests

src/NestedSetsUpdateManager.php

[warning] 136-136: src/NestedSetsUpdateManager.php#L136
Added line #L136 was not covered by tests


[warning] 138-141: src/NestedSetsUpdateManager.php#L138-L141
Added lines #L138 - L141 were not covered by tests


[warning] 152-152: src/NestedSetsUpdateManager.php#L152
Added line #L152 was not covered by tests


[warning] 154-157: src/NestedSetsUpdateManager.php#L154-L157
Added lines #L154 - L157 were not covered by tests


[warning] 169-169: src/NestedSetsUpdateManager.php#L169
Added line #L169 was not covered by tests


[warning] 176-176: src/NestedSetsUpdateManager.php#L176
Added line #L176 was not covered by tests


[warning] 178-182: src/NestedSetsUpdateManager.php#L178-L182
Added lines #L178 - L182 were not covered by tests

src/QueryConditionBuilder.php

[warning] 82-82: src/QueryConditionBuilder.php#L82
Added line #L82 was not covered by tests


[warning] 84-88: src/QueryConditionBuilder.php#L84-L88
Added lines #L84 - L88 were not covered by tests


[warning] 143-143: src/QueryConditionBuilder.php#L143
Added line #L143 was not covered by tests


[warning] 145-145: src/QueryConditionBuilder.php#L145
Added line #L145 was not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: phpunit-compatibility / PHP 8.3-ubuntu-latest
  • GitHub Check: mutation / PHP 8.4-ubuntu-latest
  • GitHub Check: mutation / PHP 8.4-ubuntu-latest
🔇 Additional comments (4)
src/UpdateExpressionBuilder.php (2)

30-38: LGTM! Well-structured constructor with immutable properties.

The use of readonly properties and proper type declarations ensures immutability and type safety.


48-53: Good implementation of SQL expression building.

The use of sprintf('%+d', $offset) ensures the sign is always included, and column names are properly quoted for SQL safety.

src/NestedSetsBehavior.php (2)

133-142: Good encapsulation of update operations.

The private property with proper PHPDoc and generic typing ensures type safety while maintaining encapsulation.


1412-1422: Well-implemented lazy initialization pattern.

The use of null coalescing assignment operator (??=) provides clean and efficient lazy initialization.

Comment on lines +62 to +68
public function createShiftUpdateAttributes(int $offset): array
{
return [
$this->leftAttribute => $this->createOffsetExpression($this->leftAttribute, $offset),
$this->rightAttribute => $this->createOffsetExpression($this->rightAttribute, $offset),
];
}
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

❓ Verification inconclusive

Add test coverage for boundary shift operations.

This method is critical for nested set integrity but lacks test coverage according to static analysis.


🏁 Script executed:

#!/bin/bash
# Check if there are any tests that might indirectly cover this method
rg -A 5 "createShiftUpdateAttributes|shiftLeftRightAttribute" tests/

Length of output: 70


Add unit tests for UpdateExpressionBuilder::createShiftUpdateAttributes

The createShiftUpdateAttributes method calculates boundary shifts for nested sets but isn’t covered by any existing tests. Please add focused unit tests to verify that, for a given offset, both left and right attributes produce the correct offset expressions.

Locations to address:

  • src/UpdateExpressionBuilder.php → createShiftUpdateAttributes
  • New or existing test file (e.g. tests/UpdateExpressionBuilderTest.php)
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 62-62: src/UpdateExpressionBuilder.php#L62
Added line #L62 was not covered by tests


[warning] 64-67: src/UpdateExpressionBuilder.php#L64-L67
Added lines #L64 - L67 were not covered by tests

🤖 Prompt for AI Agents
In src/UpdateExpressionBuilder.php around lines 62 to 68, the
createShiftUpdateAttributes method lacks unit test coverage. Add unit tests in a
new or existing test file such as tests/UpdateExpressionBuilderTest.php that
call createShiftUpdateAttributes with various offset values and assert that the
returned array correctly maps left and right attributes to their expected offset
expressions. Ensure tests cover typical and edge cases to verify correct
behavior.

Comment on lines +82 to +89
public function createLteCondition(string $attribute, int $value): array
{
return [
'<=',
$attribute,
$value,
];
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add test coverage for less-than-or-equal condition builder.

This basic condition builder lacks test coverage but is likely used in nested set operations.

Would you like me to generate unit tests for the condition builder methods?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 82-82: src/QueryConditionBuilder.php#L82
Added line #L82 was not covered by tests


[warning] 84-88: src/QueryConditionBuilder.php#L84-L88
Added lines #L84 - L88 were not covered by tests

🤖 Prompt for AI Agents
In src/QueryConditionBuilder.php around lines 82 to 89, the createLteCondition
method lacks test coverage. Add unit tests that verify the method returns the
correct array structure for less-than-or-equal conditions, ensuring it handles
various attribute names and integer values correctly. This will improve
reliability and maintainability of nested set operations using this condition
builder.

Comment on lines +229 to +233
$primaryKey = $this->owner::primaryKey();

if (isset($primaryKey[0]) === false) {
throw new Exception('"' . $this->modelClass . '" must have a primary key.');
}
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

❓ Verification inconclusive

Good error handling for missing primary key.

The check for primary key existence is crucial for data integrity. Consider verifying this scenario is tested.


🏁 Script executed:

#!/bin/bash
# Check if there are tests for models without primary keys
rg -B 5 -A 5 "primaryKey.*return \[\]|without.*primary.*key" tests/

Length of output: 69


Missing test for missing primary key scenario

There are currently no automated tests covering the case when a model has no primary key and updateTreeAttributeForRoot() throws its exception. Please add a unit test to simulate a model whose primaryKey() returns an empty array and assert that the following exception is raised:

  • File: src/NestedSetsUpdateManager.php (lines 229–233)
    if (isset($primaryKey[0]) === false) {
        throw new Exception('"' . $this->modelClass . '" must have a primary key.');
    }

This will ensure the error‐handling path is validated.

🤖 Prompt for AI Agents
In src/NestedSetsUpdateManager.php around lines 229 to 233, add a unit test that
mocks or simulates a model whose primaryKey() method returns an empty array. The
test should call updateTreeAttributeForRoot() and assert that it throws the
expected Exception with the message indicating the model must have a primary
key. This will cover the error-handling path when no primary key is defined.

Comment on lines 169 to 184
public function moveSameTreeNode(
int $leftValue,
int $rightValue,
int $depthOffset,
int $positionOffset,
mixed $treeValue,
): void {
$this->updateDepthInRange($leftValue, $rightValue, $depthOffset, $treeValue);

foreach ([$this->leftAttribute, $this->rightAttribute] as $attribute) {
$this->modelClass::updateAll(
$this->expressionBuilder->createSingleAttributeUpdate($attribute, $positionOffset),
$this->conditionBuilder->createMovementCondition($leftValue, $rightValue, $treeValue),
);
}
}
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

❓ Verification inconclusive

Add test coverage for same-tree node movement.

The moveSameTreeNode() method handles critical nested set operations but lacks test coverage.


🏁 Script executed:

#!/bin/bash
# Check for any tests that might cover node movement operations
rg -A 10 "moveSameTreeNode|moveNode.*same.*tree" tests/

Length of output: 57


Missing test coverage for moveSameTreeNode()

A search through the tests/ directory did not reveal any existing unit tests covering the moveSameTreeNode() method in src/NestedSetsUpdateManager.php (lines 169–184). This method drives critical nested-set logic and needs its behavior verified.

Please add tests that cover, at minimum:

  • Moving a node within the same tree
  • Correct calls to updateDepthInRange()
  • Correct attribute updates via the two updateAll() invocations

Suggested location:
• tests/NestedSetsUpdateManagerTest.php

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 169-169: src/NestedSetsUpdateManager.php#L169
Added line #L169 was not covered by tests


[warning] 176-176: src/NestedSetsUpdateManager.php#L176
Added line #L176 was not covered by tests


[warning] 178-182: src/NestedSetsUpdateManager.php#L178-L182
Added lines #L178 - L182 were not covered by tests

🤖 Prompt for AI Agents
In src/NestedSetsUpdateManager.php lines 169 to 184, the moveSameTreeNode()
method lacks unit test coverage. Add tests in
tests/NestedSetsUpdateManagerTest.php that verify moving a node within the same
tree, ensure updateDepthInRange() is called with correct parameters, and confirm
that updateAll() is invoked twice with the expected attribute updates and
conditions.

…stedSetsUpdateManager` and remove redundant method in `QueryConditionBuilder`.
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

♻️ Duplicate comments (3)
src/QueryConditionBuilder.php (1)

82-89: Address the missing test coverage for less-than-or-equal condition builder.

This method lacks test coverage as indicated by the static analysis and previous review comments. The implementation is correct, but testing is essential for reliability.

Would you like me to generate unit tests for the createLteCondition method?

src/NestedSetsUpdateManager.php (2)

229-233: Missing test coverage for primary key validation.

The error handling for missing primary key scenarios lacks test coverage as noted in previous reviews. This is critical validation logic that should be tested.

Please add a unit test that mocks a model with an empty primaryKey() return value and verifies the exception is thrown correctly.


169-184: Missing test coverage for same-tree node movement.

The moveSameTreeNode() method handles critical nested set operations but lacks test coverage as noted in previous reviews.

Please add tests covering node movement within the same tree, including verification of the updateDepthInRange() call and the attribute updates.

🧹 Nitpick comments (1)
src/NestedSetsUpdateManager.php (1)

246-262: Consider caching optimization for attribute getters.

The lazy loading pattern for getLeftValue() and getRightValue() is good. However, there's a minor formatting issue with extra spaces before the return statements.

Apply this formatting fix:

-        return  $this->leftValue;
+        return $this->leftValue;
-        return  $this->rightValue;
+        return $this->rightValue;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0129580 and aa0d347.

📒 Files selected for processing (2)
  • src/NestedSetsUpdateManager.php (1 hunks)
  • src/QueryConditionBuilder.php (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: terabytesoftw
PR: yii2-extensions/nested-sets-behavior#13
File: src/NestedSetsBehavior.php:145-145
Timestamp: 2025-06-29T11:22:41.839Z
Learning: The user terabytesoftw prefers to keep PRs focused and small, implementing enhancements in separate dedicated PRs rather than bundling multiple changes together.
src/QueryConditionBuilder.php (1)
Learnt from: terabytesoftw
PR: yii2-extensions/nested-sets-behavior#13
File: src/NestedSetsBehavior.php:145-145
Timestamp: 2025-06-29T11:22:41.839Z
Learning: The user terabytesoftw prefers to keep PRs focused and small, implementing enhancements in separate dedicated PRs rather than bundling multiple changes together.
🧬 Code Graph Analysis (2)
src/NestedSetsUpdateManager.php (4)
src/QueryConditionBuilder.php (4)
  • QueryConditionBuilder (26-147)
  • __construct (28-32)
  • createCrossTreeCondition (143-146)
  • createSubtreeCondition (127-130)
src/UpdateExpressionBuilder.php (6)
  • UpdateExpressionBuilder (30-137)
  • __construct (32-38)
  • createSingleAttributeUpdate (119-124)
  • createSubtreeMovementAttributes (93-109)
  • createDepthUpdateAttributes (77-82)
  • createOffsetExpression (48-53)
src/NestedSetsBehavior.php (3)
  • moveSubtreeToTargetTree (1389-1405)
  • NestedSetsBehavior (47-1423)
  • getTreeValue (1363-1368)
tests/NestedSetsBehaviorTest.php (1)
  • primaryKey (1582-1585)
src/QueryConditionBuilder.php (2)
src/UpdateExpressionBuilder.php (1)
  • __construct (32-38)
src/NestedSetsUpdateManager.php (1)
  • __construct (65-85)
🪛 GitHub Check: codecov/patch
src/NestedSetsUpdateManager.php

[warning] 136-136: src/NestedSetsUpdateManager.php#L136
Added line #L136 was not covered by tests


[warning] 138-141: src/NestedSetsUpdateManager.php#L138-L141
Added lines #L138 - L141 were not covered by tests


[warning] 152-152: src/NestedSetsUpdateManager.php#L152
Added line #L152 was not covered by tests


[warning] 154-157: src/NestedSetsUpdateManager.php#L154-L157
Added lines #L154 - L157 were not covered by tests


[warning] 169-169: src/NestedSetsUpdateManager.php#L169
Added line #L169 was not covered by tests


[warning] 176-176: src/NestedSetsUpdateManager.php#L176
Added line #L176 was not covered by tests


[warning] 178-182: src/NestedSetsUpdateManager.php#L178-L182
Added lines #L178 - L182 were not covered by tests

src/QueryConditionBuilder.php

[warning] 82-82: src/QueryConditionBuilder.php#L82
Added line #L82 was not covered by tests


[warning] 84-88: src/QueryConditionBuilder.php#L84-L88
Added lines #L84 - L88 were not covered by tests

🪛 GitHub Check: mutation / PHP 8.4-ubuntu-latest
src/NestedSetsUpdateManager.php

[failure] 181-181:
Parameter #2 $condition of static method yii\db\ActiveRecord::updateAll() expects array|string, mixed given.


[failure] 181-181:
Call to an undefined method yii2\extensions\nestedsets\QueryConditionBuilder::reateSubtreeCondition().

🪛 GitHub Check: phpstan / PHP 8.4-ubuntu-latest
src/NestedSetsUpdateManager.php

[failure] 181-181:
Parameter #2 $condition of static method yii\db\ActiveRecord::updateAll() expects array|string, mixed given.


[failure] 181-181:
Call to an undefined method yii2\extensions\nestedsets\QueryConditionBuilder::reateSubtreeCondition().

⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: codecov/project
  • GitHub Check: phpunit / PHP 8.2-windows-latest
  • GitHub Check: phpunit / PHP 8.4-windows-latest
  • GitHub Check: phpunit / PHP 8.2-ubuntu-latest
  • GitHub Check: phpunit / PHP 8.3-windows-latest
  • GitHub Check: phpunit / PHP 8.3-ubuntu-latest
  • GitHub Check: phpunit / PHP 8.4-ubuntu-latest
  • GitHub Check: phpunit-compatibility / PHP 8.2-windows-latest
  • GitHub Check: phpunit / PHP 8.1-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.1-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.1-windows-latest
🔇 Additional comments (2)
src/QueryConditionBuilder.php (1)

28-32: Well-structured dependency injection.

The constructor cleanly accepts the necessary attributes for building nested sets conditions. The readonly properties ensure immutability and thread safety.

src/NestedSetsUpdateManager.php (1)

65-85: Excellent dependency composition and initialization.

The constructor properly initializes both the condition builder and expression builder with the required attributes. The use of readonly properties ensures immutability.

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

♻️ Duplicate comments (2)
src/NestedSetsUpdateManager.php (2)

169-184: Correct ordering in same-tree node movement.

The method appropriately calls updateDepthInRange first, then updates position attributes. This ordering is crucial for nested set integrity.


223-244: Good error handling for root tree updates.

The primary key validation is essential for data integrity when updating tree attributes for root nodes.

🧹 Nitpick comments (2)
src/NestedSetsUpdateManager.php (2)

252-252: Fix extra whitespace in return statement.

There's an extra space before the variable in the return statement.

-        return  $this->leftValue;
+        return $this->leftValue;

261-261: Fix extra whitespace in return statement.

There's an extra space before the variable in the return statement.

-        return  $this->rightValue;
+        return $this->rightValue;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between aa0d347 and 6a4b1fe.

📒 Files selected for processing (1)
  • src/NestedSetsUpdateManager.php (1 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.839Z
Learning: The user terabytesoftw prefers to keep PRs focused and small, implementing enhancements in separate dedicated PRs rather than bundling multiple changes together.
🪛 GitHub Check: codecov/patch
src/NestedSetsUpdateManager.php

[warning] 136-136: src/NestedSetsUpdateManager.php#L136
Added line #L136 was not covered by tests


[warning] 138-141: src/NestedSetsUpdateManager.php#L138-L141
Added lines #L138 - L141 were not covered by tests


[warning] 152-152: src/NestedSetsUpdateManager.php#L152
Added line #L152 was not covered by tests


[warning] 154-157: src/NestedSetsUpdateManager.php#L154-L157
Added lines #L154 - L157 were not covered by tests


[warning] 169-169: src/NestedSetsUpdateManager.php#L169
Added line #L169 was not covered by tests


[warning] 176-176: src/NestedSetsUpdateManager.php#L176
Added line #L176 was not covered by tests


[warning] 178-182: src/NestedSetsUpdateManager.php#L178-L182
Added lines #L178 - L182 were not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: mutation / PHP 8.4-ubuntu-latest
  • GitHub Check: phpunit / PHP 8.2-windows-latest
  • GitHub Check: phpunit / PHP 8.2-windows-latest
  • GitHub Check: mutation / PHP 8.4-ubuntu-latest
🔇 Additional comments (10)
src/NestedSetsUpdateManager.php (10)

1-30: Well-structured class with comprehensive documentation.

The class design follows solid principles with proper final declaration and detailed PHPDoc. The documentation clearly explains the purpose and key features.


32-57: Good property design with appropriate type safety.

Properties are well-typed with readonly modifiers where appropriate. The use of nullable types and mixed type for tree value accommodates the flexible nature of nested sets.


65-85: Solid dependency injection pattern in constructor.

The constructor properly initializes dependencies and creates the required builder instances. PHPStan annotations provide excellent type safety.


94-102: Efficient bulk update implementation.

The method correctly iterates over both left and right attributes to apply shifts, using the builder pattern for consistency.


114-126: Proper subtree movement logic.

The method correctly handles cross-tree movement with both position and depth adjustments in a single operation for efficiency.


136-142: Correct depth update implementation.

The method properly updates depth within a range using the builder pattern for condition and expression generation.


152-158: Clean attribute adjustment method.

The method provides a focused interface for adjusting specific attributes from a given value, maintaining the builder pattern consistency.


189-210: Robust deletion handling logic.

The method correctly calculates delta based on operation type and handles both leaf nodes and delete-with-children scenarios appropriately.


264-275: Consistent tree value caching logic.

The method properly handles both single-tree and multi-tree scenarios with appropriate null checks.


292-295: Clean delegation to boundary shifting method.

The method provides a clean interface that delegates to the more generic shiftBoundaryAttributes method with the current tree value.

@terabytesoftw terabytesoftw deleted the feat-mini-4 branch July 3, 2025 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
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