Skip to content

Consolidate internal URI template, command target, and body request helpers - #329

Merged
koriym merged 2 commits into
1.xfrom
consolidate-internal-helpers
Nov 28, 2026
Merged

koriym merged 2 commits into
1.xfrom
consolidate-internal-helpers

Conversation

@koriym

@koriym koriym commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Summary

Pure internal refactoring to consolidate duplicated logic and tighten boundaries across @internal classes (no public API or behavior changes):

  • Extract stateless UriTemplates (src/UriTemplates.php, bound without Scope::SINGLETON in CacheableModule): consolidates RFC 6570 URI template parsing and expansion shared by DependsOnExpansion, DependsOnTags, RefreshAnnotatedCommand, and RefreshTemplateValidator. Removes duplicated variableNames() from RefreshTemplateValidator and narrows DependsOnTemplates to #[DependsOn] reflection caching (ofOnGet()).
  • Introduce CommandTargets value object (src/CommandTargets.php): replaces the raw array{list<Uri>, list<Uri>} tuple returned by RefreshAnnotatedCommand::declared() and simplifies CommandInterceptor (removes refreshDeclared() and intermediate array reshaping).
  • Extract stateless EmbeddedRequests (src/EmbeddedRequests.php): EmbeddedRequests::of($ro) iterates the top-level embedded requests of a body, moved from DependsOnTags. CacheDependencyCollector and Dependencies no longer take a ResourceBodyEvaluator; DependsOnTagsTest becomes EmbeddedRequestsTest.
  • Naming & binding hygiene:
    • Rename Dependencies $etags parameter to $dependencies in ResourceDonut.
    • Remove duplicate concrete DonutRepository::class singleton binding in DonutCacheModule.
    • Remove unnecessary Scope::SINGLETON from stateless GlobalServerContext in QueryRepositoryModule.
    • Inline 1-line forwarding QueryRepository::setCacheDependency() and update stale docblock references to CacheDependencyCollector::collect().
    • Fix minor internal typos (initializePools -> initializePool, prifix -> prefix in ResourceStorage; $dns -> $dsn in RedisDsnProvider).

Test plan

  • ./vendor/bin/phpmd src text ./phpmd.xml — 0 violations
  • composer cs — 71/71 pass
  • composer sa — Psalm 0 errors, PHPStan 266/266 OK
  • composer test — 941 tests, 3117 assertions, 0 failures
  • Local PCOV coverage — 100.00% (0 uncovered lines in src/)
  • Runtime verification with xstep on CommandInterceptor, RefreshTemplateValidator and EmbeddedRequests
  • Reviewed by Fable 5.2 and Kimi K3.1 (LGTM, 0 blocking findings)

Summary by CodeRabbit

  • Improvements
    • Cache dependency tracking now includes embedded requests, helping cached responses reflect changes in embedded resources.
    • Purge and refresh annotations now apply their declared URI targets, with collection links included in cache purges.
    • URI-template handling is consistent across dependency tags and refresh validation, including templates with exploded query values.

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 40 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 677b04c and 328d9e4.

Files selected for processing: 23

  • src/CacheDependencyCollector.php
  • src/CacheableModule.php
  • src/CommandInterceptor.php
  • src/CommandTargets.php
  • src/Dependencies.php
  • src/DependsOnExpansion.php
  • src/DependsOnTags.php
  • src/DependsOnTemplates.php
  • src/DonutCacheModule.php
  • src/EmbeddedRequests.php
  • src/QueryRepository.php
  • src/QueryRepositoryModule.php
  • src/RedisDsnProvider.php
  • src/RefreshAnnotatedCommand.php
  • src/RefreshTemplateValidator.php
  • src/ResourceBodyEvaluator.php
  • src/ResourceDonut.php
  • src/ResourceStorage.php
  • src/UriTemplates.php
  • tests/CacheDependencyCollectorTest.php
  • tests/DonutMaterialDependencyTest.php
  • tests/EmbeddedChildMaterializationTest.php
  • tests/EmbeddedRequestsTest.php

No actionable comments were generated in the recent review.

Walkthrough

The change adds shared URI-template handling, separates refresh command purge and refresh targets, and moves embedded-request enumeration into EmbeddedRequests. It also updates cache dependency paths, module bindings, and several storage and naming details.

Changes: Cache dependency and refresh processing

Layer / File(s) Summary
URI-template expansion and dependency tags
src/UriTemplates.php, src/DependsOnTemplates.php, src/DependsOnExpansion.php, src/DependsOnTags.php, src/RefreshTemplateValidator.php, src/CacheableModule.php, tests/DonutMaterialDependencyTest.php
UriTemplates provides template variable extraction, list expansion, URI expansion, and tag generation. Dependency expansion and refresh-template validation now use this service.
Refresh target collection and processing
src/CommandTargets.php, src/RefreshAnnotatedCommand.php, src/CommandInterceptor.php
RefreshAnnotatedCommand::declared() returns separate purge and refresh URI lists. CommandInterceptor purges its own and declared purge URIs, rebuilds the stored resource when applicable, then refreshes declared refresh URIs.
Embedded request enumeration and dependency collection
src/EmbeddedRequests.php, src/CacheDependencyCollector.php, src/Dependencies.php, src/DependsOnTags.php, src/QueryRepository.php, src/ResourceDonut.php, src/ResourceBodyEvaluator.php, tests/CacheDependencyCollectorTest.php, tests/EmbeddedRequestsTest.php, tests/EmbeddedChildMaterializationTest.php
EmbeddedRequests yields immediate requests from a resource body in order, including duplicates. Cache dependency paths use it for request enumeration. QueryRepository calls the collector directly; ResourceDonut renames dependency parameters.
Cache runtime and storage adjustments
src/DonutCacheModule.php, src/QueryRepositoryModule.php, src/RedisDsnProvider.php, src/ResourceStorage.php
The direct DonutRepository binding and explicit singleton scope on the server-context binding are removed. The Redis DSN property and resource storage pool helper are renamed; the KEY_RO documentation typo is corrected.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant CommandInterceptor
  participant RefreshAnnotatedCommand
  participant MethodInvocation
  participant ResourceObject
  CommandInterceptor->>RefreshAnnotatedCommand: declared(invocation, resource object)
  RefreshAnnotatedCommand->>MethodInvocation: inspect command annotations
  RefreshAnnotatedCommand->>ResourceObject: inspect collection links
  RefreshAnnotatedCommand-->>CommandInterceptor: return CommandTargets(purge, refresh)
  CommandInterceptor->>CommandInterceptor: purge own and declared purge URIs
  CommandInterceptor->>CommandInterceptor: rebuild stored resource when applicable
  CommandInterceptor->>CommandInterceptor: refresh declared refresh URIs
Loading

Possibly related PRs

Merge Risk: Minimal · previous review 677b0

This is an internal refactor that is not intended to change public behavior. No concrete defect was identified in the supplied changes, and merge risk appears minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "Consolidate internal URI template, command target, and body request helpers" is specific and matches the changeset. The diff adds UriTemplates and CommandTargets, removes DependsOnTemplates…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title "Consolidate internal URI template, command target, and body request helpers" is specific and matches the changeset. The diff adds UriTemplates and CommandTargets, removes DependsOnTemplates' expansion API, and moves embedded request enumeration into EmbeddedRequests. The title is not vague and does not describe unrelated work. It names three of the main groups of change, so it does not cover every detail, which is acceptable.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 19b7451 and 677b04c.

Files selected for processing: 8

  • src/CacheDependencyCollector.php
  • src/CommandTargets.php
  • src/Dependencies.php
  • src/EmbeddedRequests.php
  • src/ResourceBodyEvaluator.php
  • tests/CacheDependencyCollectorTest.php
  • tests/DonutMaterialDependencyTest.php
  • tests/EmbeddedRequestsTest.php
Files with no reviewable changes: 1

  • src/ResourceBodyEvaluator.php
Files skipped from review as they are similar to previous changes: 1

  • src/CommandTargets.php

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@codecov

codecov Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (3074b6a) to head (328d9e4).

Additional details and impacted files
@@             Coverage Diff             @@
##                 1.x      #329   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
+ Complexity       882       878    -4     
===========================================
  Files            118       121    +3     
  Lines           1973      1965    -8     
===========================================
- Hits            1973      1965    -8     

☔ View full report in Codecov by Harness.
📢 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.

@koriym

koriym commented Nov 28, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

ResourceBodyEvaluator transforms a body for storage and never enumerated
requests itself, so the enumeration moves to a stateless iterable built by
EmbeddedRequests::of(). CacheDependencyCollector and Dependencies no longer
take a ResourceBodyEvaluator. The CommandTargets $purge docblock now states
that collection link URIs follow the #[Purge]/#[Refresh] ones.
@koriym
koriym force-pushed the consolidate-internal-helpers branch from 677b04c to 328d9e4 Compare November 28, 2026 13:25
@koriym
koriym merged commit bb8fe79 into 1.x Nov 28, 2026
44 checks passed
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.

1 participant