Skip to content

Commit 4c82ad4

Browse files
committed
Merge branch '7.1' into 7.2
* 7.1: [Security] Update web-token/jwt-library version and adjust checker parameters [Validator] Add Catalan and Spanish translation for `WordCount` constraint" [DependencyInjection] Do not try to load default method name on interface fix tests [PropertyInfo] Fix nullable value returned from extractFromMutator on CollectionType
2 parents a980a46 + 9846d78 commit 4c82ad4

File tree

5 files changed

+26
-5
lines changed

5 files changed

+26
-5
lines changed

src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ public static function getDefault(ContainerBuilder $container, string $serviceId
133133
return null;
134134
}
135135

136+
if ($r->isInterface()) {
137+
return null;
138+
}
139+
136140
if (null !== $indexAttribute) {
137141
$service = $class !== $serviceId ? \sprintf('service "%s"', $serviceId) : 'on the corresponding service';
138142
$message = [\sprintf('Either method "%s::%s()" should ', $class, $defaultMethod), \sprintf(' or tag "%s" on %s is missing attribute "%s".', $tagName, $service, $indexAttribute)];

src/Symfony/Component/DependencyInjection/Tests/Compiler/PriorityTaggedServiceTraitTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,16 @@ public function testTheIndexedTagsByDefaultIndexMethod()
151151

152152
$container->register('service3', IntTagClass::class)->addTag('my_custom_tag');
153153

154+
$container->register('service4', HelloInterface::class)->addTag('my_custom_tag');
155+
154156
$priorityTaggedServiceTraitImplementation = new PriorityTaggedServiceTraitImplementation();
155157

156158
$tag = new TaggedIteratorArgument('my_custom_tag', 'foo', 'getFooBar');
157159
$expected = [
158160
'bar_tab_class_with_defaultmethod' => new TypedReference('service2', BarTagClass::class),
159161
'service1' => new TypedReference('service1', FooTagClass::class),
160162
'10' => new TypedReference('service3', IntTagClass::class),
163+
'service4' => new TypedReference('service4', HelloInterface::class),
161164
];
162165
$services = $priorityTaggedServiceTraitImplementation->test($tag, $container);
163166
$this->assertSame(array_keys($expected), array_keys($services));
@@ -247,3 +250,8 @@ class HelloNamedService extends \stdClass
247250
class HelloNamedService2
248251
{
249252
}
253+
254+
interface HelloInterface
255+
{
256+
public static function getFooBar(): string;
257+
}

src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ private function extractFromMutator(string $class, string $property): ?array
538538
$type = $this->extractFromReflectionType($reflectionType, $reflectionMethod->getDeclaringClass());
539539

540540
if (1 === \count($type) && \in_array($prefix, $this->arrayMutatorPrefixes, true)) {
541-
$type = [new LegacyType(LegacyType::BUILTIN_TYPE_ARRAY, false, null, true, new LegacyType(LegacyType::BUILTIN_TYPE_INT), $type[0])];
541+
$type = [new LegacyType(LegacyType::BUILTIN_TYPE_ARRAY, $this->isNullableProperty($class, $property), null, true, new LegacyType(LegacyType::BUILTIN_TYPE_INT), $type[0])];
542542
}
543543

544544
return $type;

src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use Symfony\Component\PropertyInfo\Tests\Fixtures\SnakeCaseDummy;
3434
use Symfony\Component\PropertyInfo\Type as LegacyType;
3535
use Symfony\Component\TypeInfo\Type;
36+
use Symfony\Component\TypeInfo\TypeResolver\PhpDocAwareReflectionTypeResolver;
3637

3738
/**
3839
* @author Kévin Dunglas <[email protected]>
@@ -548,6 +549,7 @@ public function testTypedPropertiesLegacy()
548549
$this->assertEquals([new LegacyType(LegacyType::BUILTIN_TYPE_ARRAY, false, null, true, new LegacyType(LegacyType::BUILTIN_TYPE_INT), new LegacyType(LegacyType::BUILTIN_TYPE_STRING))], $this->extractor->getTypes(Php74Dummy::class, 'stringCollection'));
549550
$this->assertEquals([new LegacyType(LegacyType::BUILTIN_TYPE_INT, true)], $this->extractor->getTypes(Php74Dummy::class, 'nullableWithDefault'));
550551
$this->assertEquals([new LegacyType(LegacyType::BUILTIN_TYPE_ARRAY, false, null, true)], $this->extractor->getTypes(Php74Dummy::class, 'collection'));
552+
$this->assertEquals([new LegacyType(LegacyType::BUILTIN_TYPE_ARRAY, true, null, true, new LegacyType(LegacyType::BUILTIN_TYPE_INT), new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, Dummy::class))], $this->extractor->getTypes(Php74Dummy::class, 'nullableTypedCollection'));
551553
}
552554

553555
/**
@@ -696,9 +698,9 @@ public function testExtractors(string $property, ?Type $type)
696698
*/
697699
public static function typesProvider(): iterable
698700
{
699-
yield ['a', null];
701+
yield ['a', class_exists(PhpDocAwareReflectionTypeResolver::class) ? Type::int() : null];
700702
yield ['b', Type::nullable(Type::object(ParentDummy::class))];
701-
yield ['e', null];
703+
yield ['e', class_exists(PhpDocAwareReflectionTypeResolver::class) ? Type::list(Type::resource()) : null];
702704
yield ['f', Type::list(Type::object(\DateTimeImmutable::class))];
703705
yield ['donotexist', null];
704706
yield ['staticGetter', null];
@@ -881,8 +883,8 @@ public function testExtractConstructorType(string $property, ?Type $type)
881883
public static function extractConstructorTypesProvider(): iterable
882884
{
883885
yield ['timezone', Type::object(\DateTimeZone::class)];
884-
yield ['date', null];
885-
yield ['dateObject', null];
886+
yield ['date', class_exists(PhpDocAwareReflectionTypeResolver::class) ? Type::int() : null];
887+
yield ['dateObject', class_exists(PhpDocAwareReflectionTypeResolver::class) ? Type::object(\DateTimeInterface::class) : null];
886888
yield ['dateTime', Type::object(\DateTimeImmutable::class)];
887889
yield ['ddd', null];
888890
}

src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php74Dummy.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,18 @@ class Php74Dummy
2323
private ?int $nullableWithDefault = 1;
2424
public array $collection = [];
2525

26+
/** @var Dummy[]|null */
27+
public ?array $nullableTypedCollection = null;
28+
2629
public function addStringCollection(string $string): void
2730
{
2831
}
2932

3033
public function removeStringCollection(string $string): void
3134
{
3235
}
36+
37+
public function addNullableTypedCollection(Dummy $dummy): void
38+
{
39+
}
3340
}

0 commit comments

Comments
 (0)