Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit df8f3b1

Browse filesBrowse files
committed
fix(property-info): make sure that SerializerExtractor returns null for invalid class metadata
1 parent 8529b41 commit df8f3b1
Copy full SHA for df8f3b1

File tree

2 files changed

+9
-2
lines changed
Filter options

2 files changed

+9
-2
lines changed

‎src/Symfony/Component/PropertyInfo/Extractor/SerializerExtractor.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyInfo/Extractor/SerializerExtractor.php
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\PropertyInfo\Extractor;
1313

1414
use Symfony\Component\PropertyInfo\PropertyListExtractorInterface;
15+
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
1516
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
1617

1718
/**
@@ -34,12 +35,13 @@ public function getProperties(string $class, array $context = []): ?array
3435
return null;
3536
}
3637

37-
if (!$this->classMetadataFactory->getMetadataFor($class)) {
38+
try {
39+
$serializerClassMetadata = $this->classMetadataFactory->getMetadataFor($class);
40+
} catch (InvalidArgumentException) {
3841
return null;
3942
}
4043

4144
$properties = [];
42-
$serializerClassMetadata = $this->classMetadataFactory->getMetadataFor($class);
4345

4446
foreach ($serializerClassMetadata->getAttributesMetadata() as $serializerAttributeMetadata) {
4547
if (!$serializerAttributeMetadata->isIgnored() && (null === $context['serializer_groups'] || array_intersect($context['serializer_groups'], $serializerAttributeMetadata->getGroups()))) {

‎src/Symfony/Component/PropertyInfo/Tests/Extractor/SerializerExtractorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyInfo/Tests/Extractor/SerializerExtractorTest.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,9 @@ public function testGetPropertiesWithAnyGroup()
5555
{
5656
$this->assertSame(['analyses', 'feet'], $this->extractor->getProperties(AdderRemoverDummy::class, ['serializer_groups' => null]));
5757
}
58+
59+
public function testGetPropertiesWithNonExistentClassReturnsNull()
60+
{
61+
$this->assertSame(null, $this->extractor->getProperties('NonExistent'));
62+
}
5863
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.