Skip to content

Commit 8920a8a

Browse files
committed
Merge branch 'antalaron-issue-322'
* antalaron-issue-322: reformatting code - not as slick, but more readable for the edge case
2 parents 7229acf + f8ce844 commit 8920a8a

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/Maker/MakeEntity.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -466,18 +466,22 @@ private function askRelationDetails(ConsoleStyle $io, string $generatedEntityCla
466466
while (null === $targetEntityClass) {
467467
$question = $this->createEntityClassQuestion('What class should this entity be related to?');
468468

469-
$targetEntityClass = $io->askQuestion($question);
470-
471-
if (!class_exists($designatedTargetClass = $this->getEntityNamespace().'\\'.$targetEntityClass)) {
472-
if (!class_exists($designatedTargetClass = $targetEntityClass)) {
473-
$io->error(sprintf('Unknown class "%s"', $targetEntityClass));
474-
$targetEntityClass = null;
469+
$answeredEntityClass = $io->askQuestion($question);
470+
471+
// find the correct class name - but give priority over looking
472+
// in the Entity namespace versus just checking the full class
473+
// name to avoid issues with classes like "Directory" that exist
474+
// in PHP's core.
475+
if (class_exists($this->getEntityNamespace().'\\'.$answeredEntityClass)) {
476+
$targetEntityClass = $this->getEntityNamespace().'\\'.$answeredEntityClass;
477+
} elseif (class_exists($answeredEntityClass)) {
478+
$targetEntityClass = $answeredEntityClass;
479+
} else {
480+
$io->error(sprintf('Unknown class "%s"', $targetEntityClass));
481+
$targetEntityClass = null;
475482

476-
continue;
477-
}
483+
continue;
478484
}
479-
480-
$targetEntityClass = $designatedTargetClass;
481485
}
482486

483487
// help the user select the type

0 commit comments

Comments
 (0)