Skip to content

Commit f8d45a6

Browse files
authored
feature #1474 Prevent entity name from having an accent
1 parent ef2ae8e commit f8d45a6

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/Maker/MakeEntity.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ public function configureCommand(Command $command, InputConfiguration $inputConf
103103
public function interact(InputInterface $input, ConsoleStyle $io, Command $command): void
104104
{
105105
if ($input->getArgument('name')) {
106+
if (!$this->verifyEntityName($input->getArgument('name'))) {
107+
throw new \InvalidArgumentException('An entity can only have ASCII letters');
108+
}
109+
106110
return;
107111
}
108112

@@ -122,6 +126,11 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma
122126
$question = $this->createEntityClassQuestion($argument->getDescription());
123127
$entityClassName = $io->askQuestion($question);
124128

129+
while (!$this->verifyEntityName($entityClassName)) {
130+
$io->error('An entity can only have ASCII letter")');
131+
$entityClassName = $io->askQuestion($question);
132+
}
133+
125134
$input->setArgument('name', $entityClassName);
126135

127136
if (
@@ -805,6 +814,11 @@ private function askRelationType(ConsoleStyle $io, string $entityClass, string $
805814
return $io->askQuestion($question);
806815
}
807816

817+
private function verifyEntityName(string $entityName): bool
818+
{
819+
return preg_match('/^[a-zA-Z\\\\]+$/', $entityName);
820+
}
821+
808822
private function createClassManipulator(string $path, ConsoleStyle $io, bool $overwrite): ClassSourceManipulator
809823
{
810824
$manipulator = new ClassSourceManipulator(

tests/Maker/MakeEntityTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,21 @@ public function getTestDetails(): \Generator
102102
}),
103103
];
104104

105+
yield 'it_does_not_validate_entity_name_with_accent' => [$this->createMakeEntityTest()
106+
->run(function (MakerTestRunner $runner) {
107+
$runner->runMaker([
108+
// entity class with accent
109+
'Usé',
110+
// entity class without accent
111+
'User',
112+
// no fields
113+
'',
114+
]);
115+
116+
$this->runEntityTest($runner);
117+
}),
118+
];
119+
105120
yield 'it_creates_a_new_class_and_api_resource' => [$this->createMakeEntityTest()
106121
->addExtraDependencies('api')
107122
->run(function (MakerTestRunner $runner) {

0 commit comments

Comments
 (0)