fix(metadata): stop emitting withBuiltinTypes deprecation from internal callers#8228
Closed
soyuka wants to merge 2 commits into
Closed
fix(metadata): stop emitting withBuiltinTypes deprecation from internal callers#8228soyuka wants to merge 2 commits into
soyuka wants to merge 2 commits into
Conversation
…al callers ApiProperty::withBuiltinTypes() and getBuiltinTypes() were deprecated in 4.2 in favor of withNativeType()/getNativeType(), but API Platform's own factories and normalizers still call them on the legacy symfony/property-info code path. On Symfony 6.4 this yields hundreds of deprecation entries per request even though no userland code calls the deprecated API. Introduce two @internal methods on ApiProperty (internalGetBuiltinTypes() and internalWithBuiltinTypes()) that perform the same storage/conversion without triggering the deprecation, and route every internal caller through them. The public withBuiltinTypes()/getBuiltinTypes() methods keep emitting the deprecation for external callers. Fixes api-platform#8173
CI for api-platform#8228 failed on multiple split-package suites because the new internal*BuiltinTypes() helpers are only available on the metadata HEAD; "lowest" dependency builds resolve api-platform/metadata to a released 4.3.x that does not have them yet. - Guard every cross-package caller with method_exists() and fall back to the public getBuiltinTypes() so old metadata installs still work (the legacy deprecation re-emerges only on those old installs, i.e. pre-existing behaviour). - Filter the regression test to ApiProperty-targeted deprecations so the unrelated Symfony\Component\PropertyInfo\Type class deprecation (symfony/property-info 7.3+) no longer trips the assertion. - Drop unused imports flagged by php-cs-fixer. - Add narrow PHPStan ignores for function.alreadyNarrowedType in the guarded files (the methods are always defined on the monorepo HEAD, so the runtime guards look redundant to static analysis).
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
ApiProperty::withBuiltinTypes()/getBuiltinTypes()were deprecated in 4.2 in favor of the native-type equivalents, but API Platform's own factories and normalizers still call them on the legacysymfony/property-infocode path. On Symfony 6.4 this produced ~600 deprecation entries per request even though no userland code touches the deprecated API.This PR adds two
@internalmethods onApiProperty(internalGetBuiltinTypes()/internalWithBuiltinTypes()) that perform the same storage/conversion without emitting the deprecation, and routes every internal call site through them. The public methods keep emitting the deprecation for external callers, preserving the existing BC promise.Reproduction
On Symfony < 7.1 (or any property-info without
getType())vendor/api-platform/metadata/ApiProperty.php:551fireswithBuiltinTypes()deprecations fromExtractorPropertyMetadataFactory,AttributePropertyMetadataFactory,PropertyInfoPropertyMetadataFactory, and several normalizers/restrictions during normal property metadata building.Test plan
src/Metadata/Tests/Property/,src/JsonSchema/Tests/,src/Hal/Tests/,src/JsonApi/Tests/,src/Hydra/Tests/,src/Serializer/Tests/,src/GraphQl/Tests/,src/Elasticsearch/Tests/,src/Symfony/Tests/Validator/Metadata/Property/Restriction/). The two pre-existing failures inResourceMetadataCompatibilityTestand three insrc/Hal/Tests/reproduce onupstream/4.3and are unrelated to this change.Fixes #8173