Replace mpociot/reflection-docblock with barryvdh/reflection-docblock - #1085
Open
s-shiryaev wants to merge 2 commits into
Open
Replace mpociot/reflection-docblock with barryvdh/reflection-docblock#1085s-shiryaev wants to merge 2 commits into
mpociot/reflection-docblock with barryvdh/reflection-docblock#1085s-shiryaev wants to merge 2 commits into
Conversation
add backward-compatibility aliases.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Scribe's docblock parser,
mpociot/reflection-docblock, emitsImplicitly marking parameter $x as nullable is deprecatedon PHP 8.4+. This PR swaps it forbarryvdh/reflection-docblock, which is the same phpDocumentor 2.x codebase, actively maintained, and free of those deprecations.The old class names are kept working through aliases, so custom strategies do not break — see the section below.
This is the same move as #1049 (
erusev/parsedown→parsedown/parsedown), for the same reason.Motivation
The test suite reports two deprecations on PHP 8.4/8.5:
PHPUnit attributes them to
UseResponseFileTagTestonly because that is where the package's classes happen to be compiled first.This is a PHP 8.4 issue (Deprecate implicitly nullable parameter types).
In PHP 9 implicitly nullable parameters become a compile-time fatal error, at which point the package stops loading and Scribe stops working entirely.
Why
barryvdh/reflection-docblockIt is the same lineage — another fork of phpDocumentor's ReflectionDocBlock 2.x — but a live one, and it is what
barryvdh/laravel-ide-helperuses (which requires^2.4, so the constraint here matches).Diffing the two sources with the namespace normalized, the changes are purely additive plus the fixes we need:
?DocBlock/?Location/?Contexteverywhere — the deprecations this PR is aboutpreg_split($pattern, $subject, -1, ...)instead ofnullfor the limit argument — a separate PHP 8.1 deprecationContextFactory,TemplateTag,SuppressWarningsTag, generics support,DocBlock::deleteTag()Explicit nullable types landed in v2.2.0, so
--prefer-lowestbuilds are clean too.Scribe's strategy API exposes these classes to userland. Custom strategies in the wild type-hint them:
A bare namespace change would therefore break every custom strategy that does
use Mpociot\Reflection\DocBlock\Tag;, in a minor release. To avoid that,src/aliases.phpregisters an autoloader that aliases the five old class names to the new ones:Existing type hints,
instanceofchecks and subclasses keep working unchanged —tests/Unit/DocBlockAliasesTest.phpcovers all five names plus the type-hint case.It is deliberately an autoloader rather than an eager
class_alias()call: ifmpociot/reflection-docblockis still installed as some other package's dependency, Composer's own autoloader resolves those names first and this fallback is never reached, so we never shadow the real classes.📌 Important Notice
This shim is a compatibility measure for the 5.x line only. I'd recommend dropping
src/aliases.php(and its entry in thefilesautoload section) in 6.0, leavingBarryvdh\Reflection\DocBlock{,\Tag}as the only supported type hints.📝 This must be documented in the 6.0 upgrade guide — users will need to update their imports.
Changes
composer.json— replacedmpociot/reflection-docblock: ^1.0.1withbarryvdh/reflection-docblock: ^2.4; registeredsrc/aliases.phpin thefilesautoload section.src/aliases.php(new) — deprecated BC aliases for the fiveMpociot\Reflection\*class names, registered as a fallback autoloader.src/(12 files) —Mpociot\Reflection\…→Barryvdh\Reflection\…imports inRouteDocBlocker,ApiResourceResponseTools,GroupedEndpointsFromApp,Tools\Utils,TagStrategyWithFormRequestFallbackand theGetFromDocBlocks/GetFromHeaderTag/GetFromResponseFieldTag/UseResponseTag/UseResponseFileTag/UseApiResourceTags/UseTransformerTagsstrategies. Import-only changes; no logic touched.tests/(10 files) — the same import change.tests/Unit/DocBlockAliasesTest.php(new) — asserts the legacy class names still resolve to the new classes and that objects Scribe produces still satisfy the old type hints..github/copilot-instructions.md— updated the dependency reference.