Skip to content

Comments

Upgrade phpdocumentor/reflection-docblock to v6#79

Merged
koriym merged 3 commits into1.xfrom
upgrade-phpdocumentor-v6
Jan 24, 2026
Merged

Upgrade phpdocumentor/reflection-docblock to v6#79
koriym merged 3 commits into1.xfrom
upgrade-phpdocumentor-v6

Conversation

@koriym
Copy link
Member

@koriym koriym commented Jan 24, 2026

Summary

  • Upgrade phpdocumentor/reflection-docblock from ^5.3 to ^6.0
  • Upgrade phpdocumentor/type-resolver from ^1.6.1 to ^2.0
  • Inject DocBlockFactoryInterface via constructor in ReturnEntity
  • Handle Generic type (v6) in addition to Array_ type for return types

Performance

  • DocBlock parsing cost: 0.08ms/call
  • Impact on typical request (50ms): < 1%
  • No caching needed (parsing only occurs for array return types)

Test plan

  • All tests pass (composer tests - 83 tests, 124 assertions)
  • Static analysis passes (PHPStan, Psalm)
  • Code style checks pass

Summary by Sourcery

Upgrade docblock parsing dependencies and adapt return type resolution to support new Generic types while integrating the docblock factory via dependency injection.

New Features:

  • Support phpDocumentor Generic pseudo-type in return docblock parsing in addition to Array_ types.

Enhancements:

  • Inject DocBlockFactoryInterface into ReturnEntity and bind it in the MediaQueryDbModule for reuse and configurability.
  • Refine ReturnEntity return type extraction logic into a dedicated helper for cleaner type handling.

Build:

  • Bump phpdocumentor/reflection-docblock from ^5.3 to ^6.0 and phpdocumentor/type-resolver from ^1.6.1 to ^2.0 in composer.json.

Tests:

  • Update ReturnTypeTest to construct ReturnEntity with a shared DocBlockFactory instance in setup.

Summary by CodeRabbit

  • Chores

    • Updated two PHP library versions for compatibility.
  • Refactor

    • Switched to constructor-based dependency injection and simplified docblock parsing/handling.
  • Tests

    • Updated test setup and replaced direct instantiation with the new initialization approach.
  • Documentation

    • Added a 1.0.3 release entry to the changelog reflecting these changes.

✏️ Tip: You can customize this high-level summary in your review settings.

@koriym
Copy link
Member Author

koriym commented Jan 24, 2026

@coderabbitai review

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 24, 2026

Reviewer's Guide

Upgrades phpDocumentor dependencies to v6, injects a shared DocBlockFactory into ReturnEntity via DI, and updates return-type parsing logic to support both Array_ and Generic types while wiring the factory in the MediaQuery module and tests.

Sequence diagram for ReturnEntity docblock parsing with injected DocBlockFactory

sequenceDiagram
    actor Caller
    participant DIContainer
    participant DocBlockFactory as DocBlockFactoryInterface
    participant ReturnEntity
    participant Method as ReflectionMethod
    participant ContextFactory
    participant DocBlock
    participant ReturnTag as Return_
    participant Type
    participant Array_ 
    participant Generic
    participant Object_ 

    DIContainer->>DocBlockFactory: createInstance()
    DIContainer->>ReturnEntity: __construct(DocBlockFactory)

    Caller->>ReturnEntity: __invoke(Method)
    ReturnEntity->>Method: getReturnType()
    ReturnEntity-->>Caller: string or null (if ReflectionType is class-string)
    Caller-->>ReturnEntity: (fallback when array-like)

    ReturnEntity->>ReturnEntity: docblock(Method)
    ReturnEntity->>ContextFactory: createFromReflector(Method)
    ContextFactory-->>ReturnEntity: Context

    ReturnEntity->>Method: getDocComment()
    Method-->>ReturnEntity: docComment

    ReturnEntity->>DocBlockFactory: create(docComment, Context)
    DocBlockFactory-->>ReturnEntity: DocBlock

    ReturnEntity->>DocBlock: getTagsByName(return)
    DocBlock-->>ReturnEntity: ReturnTag[]

    ReturnEntity->>ReturnTag: getType()
    ReturnTag-->>ReturnEntity: Type

    ReturnEntity->>ReturnEntity: extractValueType(Type)
    alt Type is Array_
        ReturnEntity->>Array_: getValueType()
        Array_-->>ReturnEntity: Type
    else Type is Generic
        ReturnEntity->>Generic: getTypes()
        Generic-->>ReturnEntity: Type[]
        ReturnEntity->>ReturnEntity: select first Type
    else other Type
        ReturnEntity-->>ReturnEntity: null
    end

    ReturnEntity->>Object_: (check instance)
    alt valueType is Object_
        ReturnEntity-->>Caller: class-string
    else
        ReturnEntity-->>Caller: null
    end
Loading

Class diagram for ReturnEntity with injected DocBlockFactory and updated type handling

classDiagram
    class ReturnEntityInterface

    class ReturnEntity {
        - DocBlockFactoryInterface docBlockFactory
        + __construct(DocBlockFactoryInterface docBlockFactory)
        + __invoke(ReflectionMethod method) string
        - getReturnTypeName(ReflectionType reflectionType) string
        - extractValueType(Type type) Type
        - docblock(ReflectionMethod method) string
    }

    class MediaQueryDbModule {
        + configure() void
    }

    class DocBlockFactoryInterface
    class DocBlockFactory {
        + createInstance() DocBlockFactory
    }

    class ContextFactory {
        + createFromReflector(ReflectionMethod method) Context
    }

    class Return_ {
        + getType() Type
    }

    class Type
    class Array_ {
        + getValueType() Type
    }

    class Generic {
        + getTypes() Type[]
    }

    class Object_

    ReturnEntity ..|> ReturnEntityInterface
    DocBlockFactory ..|> DocBlockFactoryInterface

    MediaQueryDbModule ..> DocBlockFactoryInterface : binds
    MediaQueryDbModule ..> ReturnEntityInterface : binds

    ReturnEntity ..> DocBlockFactoryInterface : uses
    ReturnEntity ..> ContextFactory : uses
    ReturnEntity ..> Return_ : uses
    ReturnEntity ..> Type : uses
    ReturnEntity ..> Array_ : uses
    ReturnEntity ..> Generic : uses
    ReturnEntity ..> Object_ : uses
Loading

File-Level Changes

Change Details Files
Inject DocBlockFactoryInterface into ReturnEntity and adjust docblock parsing to support phpdocumentor v6 types.
  • Add a constructor to ReturnEntity that accepts a DocBlockFactoryInterface instance and store it as a private property.
  • Replace in-method DocBlockFactory::createInstance() usage with the injected DocBlockFactoryInterface when creating docblocks.
  • Introduce an extractValueType helper that returns the value type for Array_ or the first generic type for Generic, returning null otherwise.
  • Update docblock return-type handling to use extractValueType and drop support for the deprecated Collection type.
src/ReturnEntity.php
Wire DocBlockFactoryInterface into the DI container and adjust tests to construct ReturnEntity with the factory.
  • Bind DocBlockFactoryInterface in MediaQueryDbModule to a DocBlockFactory::createInstance() singleton and keep binding ReturnEntityInterface to ReturnEntity.
  • Refactor ReturnTypeTest to create a shared ReturnEntity instance in setUp using DocBlockFactory::createInstance() and reuse it across tests.
src/MediaQueryDbModule.php
tests/ReturnTypeTest.php
Update composer dependencies to phpdocumentor v6-compatible versions.
  • Bump phpdocumentor/reflection-docblock constraint from ^5.3 to ^6.0.
  • Bump phpdocumentor/type-resolver constraint from ^1.6.1 to ^2.0.
composer.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 24, 2026

✅ Actions performed

Review triggered.

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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 24, 2026

Warning

Rate limit exceeded

@koriym has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 8 minutes and 20 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

Composer upgrades for phpDocumentor packages; DocBlockFactory is bound in the DI module and injected into ReturnEntity, which uses a new extractValueType helper for docblock type handling; tests updated to use the injected DocBlockFactory instance.

Changes

Cohort / File(s) Summary
Dependency Updates
composer.json
Upgraded phpdocumentor/reflection-docblock from ^5.3 to ^6.0 and phpdocumentor/type-resolver from ^1.6.1 to ^2.0.
Dependency Injection Setup
src/MediaQueryDbModule.php
Added imports for DocBlockFactory and DocBlockFactoryInterface; bound DocBlockFactoryInterface to the instance from DocBlockFactory::createInstance() in configure().
Core Refactor
src/ReturnEntity.php
Introduced constructor injection __construct(private DocBlockFactoryInterface $docBlockFactory); replaced direct factory usage with the injected interface; added `extractValueType(Type
Test Updates
tests/ReturnTypeTest.php
Added setUp() to instantiate a shared ReturnEntity with DocBlockFactory::createInstance() and replaced inline new ReturnEntity() usages with the shared instance.
Release Notes
CHANGELOG.md
Added 1.0.3 entry describing dependency upgrades and the constructor-injection change.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I found a factory, snug and new,
I hopped it into places true,
Types unwrapped with gentle paw,
Tests now sip from one shared straw,
A nibble, a tweak—I'm cheerful too. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.76% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Upgrade phpdocumentor/reflection-docblock to v6' directly and accurately describes the primary change—upgrading a key dependency to a major version.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • In extractValueType, using $types[0] for Generic assumes the first type is always the value type; if you expect multi-parameter generics (e.g., key/value), consider constraining to known shapes or adding a more explicit selection/validation of the relevant type argument.
  • The ReturnEntity::__invoke method is documented as returning ?class-string but is typed as string|null; aligning the return type declaration with the docblock (e.g., ?string?class-string if your PHP version and tooling allow) would improve static analysis and consistency.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `extractValueType`, using `$types[0]` for `Generic` assumes the first type is always the value type; if you expect multi-parameter generics (e.g., key/value), consider constraining to known shapes or adding a more explicit selection/validation of the relevant type argument.
- The `ReturnEntity::__invoke` method is documented as returning `?class-string` but is typed as `string|null`; aligning the return type declaration with the docblock (e.g., `?string``?class-string` if your PHP version and tooling allow) would improve static analysis and consistency.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

@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

🤖 Fix all issues with AI agents
In `@src/ReturnEntity.php`:
- Around line 58-68: The extractValueType(Type|null $type) helper currently
returns the first generic parameter for Generic instances, which picks the key
for multi-parameter generics; update the logic in extractValueType to return the
last type from Generic::getTypes() (use array_key_last($types) or equivalent) so
it returns the value type for both single-parameter (array<V>) and
multi-parameter (array<K, V>) generics; keep existing handling for Array_ and
return null when no types exist.

- Update phpdocumentor/reflection-docblock from ^5.3 to ^6.0
- Update phpdocumentor/type-resolver from ^1.6.1 to ^2.0
- Inject DocBlockFactoryInterface via constructor in ReturnEntity
- Add DocBlockFactoryInterface binding in MediaQueryDbModule
- Handle Generic type (v6) in addition to Array_ type for return types
Return the last type from Generic::getTypes() instead of the first,
so array<K, V> correctly returns V (the value type) instead of K.
@koriym koriym force-pushed the upgrade-phpdocumentor-v6 branch from 7a64091 to 0e4158a Compare January 24, 2026 21:06
@koriym koriym merged commit 7850653 into 1.x Jan 24, 2026
27 checks passed
@koriym koriym deleted the upgrade-phpdocumentor-v6 branch January 24, 2026 21:08
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