Skip to content
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

Improve null checks in drivers with a delegate #1495

Merged
merged 1 commit into from
Jun 24, 2023
Merged
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
5 changes: 5 additions & 0 deletions src/Metadata/Driver/AbstractDoctrineTypeDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public function __construct(DriverInterface $delegate, ManagerRegistry $registry
public function loadMetadataForClass(\ReflectionClass $class): ?BaseClassMetadata
{
$classMetadata = $this->delegate->loadMetadataForClass($class);

if (null === $classMetadata) {
return null;
}

\assert($classMetadata instanceof ClassMetadata);

// Abort if the given class is not a mapped entity
Expand Down
3 changes: 2 additions & 1 deletion src/Metadata/Driver/DefaultValuePropertyDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ public function __construct(DriverInterface $delegate)
public function loadMetadataForClass(ReflectionClass $class): ?ClassMetadata
{
$classMetadata = $this->delegate->loadMetadataForClass($class);
\assert($classMetadata instanceof SerializerClassMetadata);

if (null === $classMetadata) {
return null;
}

\assert($classMetadata instanceof SerializerClassMetadata);

foreach ($classMetadata->propertyMetadata as $key => $propertyMetadata) {
\assert($propertyMetadata instanceof PropertyMetadata);
if (null !== $propertyMetadata->hasDefault) {
Expand Down
3 changes: 2 additions & 1 deletion src/Metadata/Driver/DocBlockDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ public function __construct(DriverInterface $delegate, ?ParserInterface $typePar
public function loadMetadataForClass(ReflectionClass $class): ?ClassMetadata
{
$classMetadata = $this->delegate->loadMetadataForClass($class);
\assert($classMetadata instanceof SerializerClassMetadata);

if (null === $classMetadata) {
return null;
}

\assert($classMetadata instanceof SerializerClassMetadata);

// We base our scan on the internal driver's property list so that we
// respect any internal allow/blocklist like in the AnnotationDriver
foreach ($classMetadata->propertyMetadata as $key => $propertyMetadata) {
Expand Down
3 changes: 2 additions & 1 deletion src/Metadata/Driver/EnumPropertiesDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ public function __construct(DriverInterface $delegate)
public function loadMetadataForClass(ReflectionClass $class): ?ClassMetadata
{
$classMetadata = $this->delegate->loadMetadataForClass($class);
\assert($classMetadata instanceof SerializerClassMetadata);

if (null === $classMetadata) {
return null;
}

\assert($classMetadata instanceof SerializerClassMetadata);

// We base our scan on the internal driver's property list so that we
// respect any internal allow/blocklist like in the AnnotationDriver
foreach ($classMetadata->propertyMetadata as $propertyMetadata) {
Expand Down
5 changes: 5 additions & 0 deletions src/Metadata/Driver/TypedPropertiesDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ private function getDefaultWhiteList(): array
public function loadMetadataForClass(ReflectionClass $class): ?ClassMetadata
{
$classMetadata = $this->delegate->loadMetadataForClass($class);

if (null === $classMetadata) {
return null;
}

\assert($classMetadata instanceof SerializerClassMetadata);

if (PHP_VERSION_ID <= 70400) {
Expand Down