Skip to content

Commit

Permalink
check for invalid values for file dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Apr 2, 2024
1 parent 3738063 commit e8e7bcf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Entity/Reflection/IMetadataParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ interface IMetadataParser
* @param class-string $entityClass
* @param list<string>|null $fileDependencies
*/
public function parseMetadata(string $entityClass, ?array &$fileDependencies): EntityMetadata;
public function parseMetadata(string $entityClass, array|null &$fileDependencies): EntityMetadata;
}
17 changes: 10 additions & 7 deletions src/Entity/Reflection/MetadataParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,25 @@ 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);

$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<string> $fileDependencies
* @param list<string>|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) {
Expand All @@ -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);
}
Expand Down

0 comments on commit e8e7bcf

Please sign in to comment.