Skip to content

[PropertyInfo] Extract public properties first in ReflectionExtractor #59430

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

Open
wants to merge 1 commit into
base: 7.4
Choose a base branch
from

Conversation

tBibaut
Copy link
Contributor

@tBibaut tBibaut commented Jan 8, 2025

Q A
Branch? 7.3
Bug fix? yes/no
New feature? yes
Deprecations? yes
Issues Fix #57719
License MIT

@carsonbot
Copy link

Hey!

To help keep things organized, we don't allow "Draft" pull requests. Could you please click the "ready for review" button or close this PR and open a new one when you are done?

Note that a pull request does not have to be "perfect" or "ready for merge" when you first open it. We just want it to be ready for a first review.

Cheers!

Carsonbot

@tBibaut tBibaut force-pushed the feat/reflectionextractor_property-first branch from 2ee42e8 to 77e76ee Compare January 8, 2025 08:37
@tBibaut tBibaut marked this pull request as ready for review January 8, 2025 08:38
@tBibaut tBibaut requested a review from dunglas as a code owner January 8, 2025 08:38
@carsonbot carsonbot added this to the 7.3 milestone Jan 8, 2025
@@ -987,7 +987,7 @@ private function getType(string $currentClass, string $attribute): Type|array|nu
private function getPropertyType(string $className, string $property): Type|array|null
{
if (class_exists(Type::class) && method_exists($this->propertyTypeExtractor, 'getType')) {
return $this->propertyTypeExtractor->getType($className, $property);
return $this->propertyTypeExtractor->getType($className, $property, context: ['extract_public_properties_first' => true]);
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if the context should instead be given by the user instead?

IMO it should be given from the normalize/denormalize context argument. Then we can leverage the default context (and update the recipe) to reduce the impact of that depreciation. WDYT?

@tBibaut tBibaut force-pushed the feat/reflectionextractor_property-first branch from 77e76ee to 406655d Compare January 8, 2025 09:40
Comment on lines +211 to +213
$extractPublicPropertiesFirst = \array_key_exists('extract_public_properties_first', $context);
if (!$extractPublicPropertiesFirst) {
trigger_deprecation('symfony/property-info', '7.3', 'Not setting "extract_public_properties_first" context key is deprecated, it will default to "true" in 8.0.');
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
$extractPublicPropertiesFirst = \array_key_exists('extract_public_properties_first', $context);
if (!$extractPublicPropertiesFirst) {
trigger_deprecation('symfony/property-info', '7.3', 'Not setting "extract_public_properties_first" context key is deprecated, it will default to "true" in 8.0.');
$extractPublicPropertiesFirst = $context['extract_public_properties_first'] ?? false;
if (!$extractPublicPropertiesFirst) {
trigger_deprecation('symfony/property-info', '7.3', 'Not setting "extract_public_properties_first" context value to "true" is deprecated, it will always be considered as "true" in 8.0.');

@@ -207,6 +207,29 @@ public function getTypesFromConstructor(string $class, string $property): ?array

public function getType(string $class, string $property, array $context = []): ?Type
{
// BC layer, remove context key in 8.0
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you update the CHANGELOG.md of PropertyInfo and UPGRADE-7.3.md as well?

{
if (class_exists(Type::class) && method_exists($this->propertyTypeExtractor, 'getType')) {
return $this->propertyTypeExtractor->getType($className, $property);
return $this->propertyTypeExtractor->getType($className, $property, $context);
Copy link
Contributor

Choose a reason for hiding this comment

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

Default context must be handled here

@@ -1674,6 +1674,30 @@ public function testPartialDenormalizationWithInvalidVariadicParameter()
DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS => true,
]);
}

public function testExtractPublicPropertiesFirst()
Copy link
Contributor

Choose a reason for hiding this comment

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

This test must be long to the AbstractObjectNormalizerTest instead.
Also, you might add a test in the ReflectionExtractorTest as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ReflectionExtractor::getTypes prioritizes unreliable sources to determine the type
4 participants