From e8e7bcfc9675c720ac667256f1bbf389bc708632 Mon Sep 17 00:00:00 2001 From: Jan Skrasek Date: Tue, 2 Apr 2024 18:10:15 +0200 Subject: [PATCH] check for invalid values for file dependencies --- src/Entity/Reflection/IMetadataParser.php | 2 +- src/Entity/Reflection/MetadataParser.php | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Entity/Reflection/IMetadataParser.php b/src/Entity/Reflection/IMetadataParser.php index 293cfb8f..09388988 100644 --- a/src/Entity/Reflection/IMetadataParser.php +++ b/src/Entity/Reflection/IMetadataParser.php @@ -10,5 +10,5 @@ interface IMetadataParser * @param class-string $entityClass * @param list|null $fileDependencies */ - public function parseMetadata(string $entityClass, ?array &$fileDependencies): EntityMetadata; + public function parseMetadata(string $entityClass, array|null &$fileDependencies): EntityMetadata; } diff --git a/src/Entity/Reflection/MetadataParser.php b/src/Entity/Reflection/MetadataParser.php index bc1afe38..24ca2bcc 100644 --- a/src/Entity/Reflection/MetadataParser.php +++ b/src/Entity/Reflection/MetadataParser.php @@ -91,7 +91,7 @@ public function addModifier(string $modifier, callable $processor) } - public function parseMetadata(string $entityClass, ?array &$fileDependencies): EntityMetadata + public function parseMetadata(string $entityClass, array|null &$fileDependencies): EntityMetadata { $this->reflection = new ReflectionClass($entityClass); $this->metadata = new EntityMetadata($entityClass); @@ -99,16 +99,17 @@ public function parseMetadata(string $entityClass, ?array &$fileDependencies): E $this->loadProperties($fileDependencies); $this->initPrimaryKey(); - $fileDependencies = array_unique($fileDependencies); + if ($fileDependencies !== null) { + $fileDependencies = array_values(array_unique($fileDependencies)); + } return $this->metadata; } /** - * @param string[] $fileDependencies - * @param list $fileDependencies + * @param list|null $fileDependencies */ - protected function loadProperties(?array &$fileDependencies): void + protected function loadProperties(array|null &$fileDependencies): void { $classTree = [$current = $this->reflection->name]; while (($current = get_parent_class($current)) !== false) { @@ -126,13 +127,15 @@ protected function loadProperties(?array &$fileDependencies): void foreach ($traits !== false ? $traits : [] as $traitName) { assert(trait_exists($traitName)); $reflectionTrait = new ReflectionClass($traitName); - $fileDependencies[] = $reflectionTrait->getFileName(); + $file = $reflectionTrait->getFileName(); + if ($file !== false) $fileDependencies[] = $file; $this->currentReflection = $reflectionTrait; $this->classPropertiesCache[$traitName] = $this->parseAnnotations($reflectionTrait, $methods); } $reflection = new ReflectionClass($class); - $fileDependencies[] = $reflection->getFileName(); + $file = $reflection->getFileName(); + if ($file !== false) $fileDependencies[] = $file; $this->currentReflection = $reflection; $this->classPropertiesCache[$class] = $this->parseAnnotations($reflection, $methods); }