Skip to content

[PropertyInfo] Skip extractors that do not implement getType #57363

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ public function isInitializable(string $class, string $property, array $context
private function extract(iterable $extractors, string $method, array $arguments): mixed
{
foreach ($extractors as $extractor) {
if (!method_exists($extractor, $method)) {
trigger_deprecation('symfony/property-info', '7.1', 'Not implementing the "%s()" method in class "%s" is deprecated."', $method, $extractor::class);

continue;
Copy link
Member

Choose a reason for hiding this comment

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

This does not look like the right solution to me as it means that a formerly used extractor will now no longer be used leading to a (potentially) different result.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I completely agree. I tried to put a message somewhere several times, but I was undecided and thought to have the PR rolling to have more feedback / ideas.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, I thought about strictly checking for getType and have it default to getTypes and it would work for return values that have only 1 Type in the return array of getTypes. I think this change was done before: #54694. Most of the code in property-info thinks BIGINT is string and not this dual type scenario.

Copy link
Member

@xabbuh xabbuh Jun 19, 2024

Choose a reason for hiding this comment

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

see #57459 for another attempt

}

if (null !== $value = $extractor->{$method}(...$arguments)) {
return $value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Symfony\Component\PropertyInfo\PropertyInitializableExtractorInterface;
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyExtractor;
use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyLegacyExtractor;
use Symfony\Component\PropertyInfo\Tests\Fixtures\NullExtractor;
use Symfony\Component\PropertyInfo\Type as LegacyType;
use Symfony\Component\TypeInfo\Type;
Expand Down Expand Up @@ -57,7 +58,10 @@ public function testGetLongDescription()

public function testGetType()
{
$this->assertEquals(Type::int(), $this->propertyInfo->getType('Foo', 'bar', []));
$extractors = [new NullExtractor(), new DummyLegacyExtractor(), new DummyExtractor()];
$propertyInfo = new PropertyInfoExtractor($extractors, $extractors, $extractors, $extractors, $extractors);

$this->assertEquals(Type::int(), $propertyInfo->getType('Foo', 'bar', []));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\PropertyInfo\Tests\Fixtures;

use Symfony\Component\PropertyInfo\Extractor\ConstructorArgumentTypeExtractorInterface;
use Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface;
use Symfony\Component\PropertyInfo\PropertyDescriptionExtractorInterface;
use Symfony\Component\PropertyInfo\PropertyInitializableExtractorInterface;
use Symfony\Component\PropertyInfo\PropertyListExtractorInterface;
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
use Symfony\Component\PropertyInfo\Type as LegacyType;
use Symfony\Component\TypeInfo\Type;

class DummyLegacyExtractor implements PropertyListExtractorInterface, PropertyDescriptionExtractorInterface, PropertyTypeExtractorInterface, PropertyAccessExtractorInterface, PropertyInitializableExtractorInterface, ConstructorArgumentTypeExtractorInterface
{
public function getShortDescription($class, $property, array $context = []): ?string
{
return 'short';
}

public function getLongDescription($class, $property, array $context = []): ?string
{
return 'long';
}

public function getTypes($class, $property, array $context = []): ?array
{
return [new LegacyType(LegacyType::BUILTIN_TYPE_INT)];
}

public function getTypesFromConstructor(string $class, string $property): ?array
{
return [new LegacyType(LegacyType::BUILTIN_TYPE_STRING)];
}

public function getTypeFromConstructor(string $class, string $property): ?Type
{
return Type::string();
}

public function isReadable($class, $property, array $context = []): ?bool
{
return true;
}

public function isWritable($class, $property, array $context = []): ?bool
{
return true;
}

public function getProperties($class, array $context = []): ?array
{
return ['a', 'b'];
}

public function isInitializable(string $class, string $property, array $context = []): ?bool
{
return true;
}
}
Loading