Skip to content

Commit

Permalink
Update bad entity name management
Browse files Browse the repository at this point in the history
  • Loading branch information
Fan2Shrek committed Mar 30, 2024
1 parent 07614b5 commit 8c49009
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/Maker/MakeEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,7 @@ public function configureCommand(Command $command, InputConfiguration $inputConf

public function interact(InputInterface $input, ConsoleStyle $io, Command $command): void
{
if ($input->getArgument('name')) {
if (!$this->verifyEntityName($input->getArgument('name'))) {
throw new \InvalidArgumentException('An entity can only have ASCII letters');
}

if (($entityClassName = $input->getArgument('name')) && empty($this->verifyEntityName($entityClassName))) {
return;
}

Expand All @@ -131,10 +127,13 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma

$argument = $command->getDefinition()->getArgument('name');
$question = $this->createEntityClassQuestion($argument->getDescription());
$entityClassName = $io->askQuestion($question);
$entityClassName ??= $io->askQuestion($question);

while ($dangerous = $this->verifyEntityName($entityClassName)) {
if ($io->confirm(sprintf('The %s character is non-ASCII, which are potentially problematic with some database. It is recommended to use only ASCII characters in entity names. Would you keep entered name ?', $dangerous[0]), false)) {
break;
}

while (!$this->verifyEntityName($entityClassName)) {
$io->error('An entity can only have ASCII letters');
$entityClassName = $io->askQuestion($question);
}

Expand Down Expand Up @@ -820,9 +819,11 @@ private function askRelationType(ConsoleStyle $io, string $entityClass, string $
return $io->askQuestion($question);
}

private function verifyEntityName(string $entityName): bool
private function verifyEntityName(string $entityName): array
{
return preg_match('/^[a-zA-Z\\\\]+$/', $entityName);
preg_match('/[^\x00-\x7F]/u', $entityName, $matches);

return $matches;
}

private function createClassManipulator(string $path, ConsoleStyle $io, bool $overwrite): ClassSourceManipulator
Expand Down
2 changes: 2 additions & 0 deletions tests/Maker/MakeEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public function getTestDetails(): \Generator
$runner->runMaker([
// entity class with accent
'Usé',
// Say no,
'n',
// entity class without accent
'User',
// no fields
Expand Down

0 comments on commit 8c49009

Please sign in to comment.