diff --git a/src/Maker/MakeEntity.php b/src/Maker/MakeEntity.php
index df2653952..8b12b4a7f 100644
--- a/src/Maker/MakeEntity.php
+++ b/src/Maker/MakeEntity.php
@@ -430,27 +430,14 @@ private function printAvailableTypes(ConsoleStyle $io): void
{
$allTypes = $this->getTypesMap();
- if ('Hyper' === getenv('TERM_PROGRAM')) {
- $wizard = 'wizard 🧙';
- } else {
- $wizard = '\\' === \DIRECTORY_SEPARATOR ? 'wizard' : 'wizard 🧙';
- }
-
$typesTable = [
'main' => [
- 'string' => [],
+ 'string' => ['ascii_string'],
'text' => [],
'boolean' => [],
'integer' => ['smallint', 'bigint'],
'float' => [],
],
- 'relation' => [
- 'relation' => 'a '.$wizard.' will help you build the relation',
- EntityRelation::MANY_TO_ONE => [],
- EntityRelation::ONE_TO_MANY => [],
- EntityRelation::MANY_TO_MANY => [],
- EntityRelation::ONE_TO_ONE => [],
- ],
'array_object' => [
'array' => ['simple_array'],
'json' => [],
@@ -469,19 +456,30 @@ private function printAvailableTypes(ConsoleStyle $io): void
$printSection = static function (array $sectionTypes) use ($io, &$allTypes) {
foreach ($sectionTypes as $mainType => $subTypes) {
+ if (!\array_key_exists($mainType, $allTypes)) {
+ // The type is not a valid DBAL Type - don't show it as an option
+ continue;
+ }
+
+ foreach ($subTypes as $key => $potentialType) {
+ if (!\array_key_exists($potentialType, $allTypes)) {
+ // The type is not a valid DBAL Type - don't show it as an "or" option
+ unset($subTypes[$key]);
+ }
+
+ // Remove type as not to show it again in "Other Types"
+ unset($allTypes[$potentialType]);
+ }
+
+ // Remove type as not to show it again in "Other Types"
unset($allTypes[$mainType]);
+
$line = sprintf(' * %s', $mainType);
- if (\is_string($subTypes) && $subTypes) {
- $line .= sprintf(' or %s', $subTypes);
- } elseif (\is_array($subTypes) && !empty($subTypes)) {
+ if (!empty($subTypes)) {
$line .= sprintf(' or %s', implode(' or ', array_map(
static fn ($subType) => sprintf('%s', $subType), $subTypes))
);
-
- foreach ($subTypes as $subType) {
- unset($allTypes[$subType]);
- }
}
$io->writeln($line);
@@ -490,11 +488,30 @@ private function printAvailableTypes(ConsoleStyle $io): void
$io->writeln('');
};
+ $printRelationsSection = static function () use ($io) {
+ if ('Hyper' === getenv('TERM_PROGRAM')) {
+ $wizard = 'wizard 🧙';
+ } else {
+ $wizard = '\\' === \DIRECTORY_SEPARATOR ? 'wizard' : 'wizard 🧙';
+ }
+
+ $io->writeln(sprintf(' * relation a %s will help you build the relation', $wizard));
+
+ $relations = [EntityRelation::MANY_TO_ONE, EntityRelation::ONE_TO_MANY, EntityRelation::MANY_TO_MANY, EntityRelation::ONE_TO_ONE];
+ foreach ($relations as $relation) {
+ $line = sprintf(' * %s', $relation);
+
+ $io->writeln($line);
+ }
+
+ $io->writeln('');
+ };
+
$io->writeln('Main Types');
$printSection($typesTable['main']);
$io->writeln('Relationships/Associations');
- $printSection($typesTable['relation']);
+ $printRelationsSection();
$io->writeln('Array/Object Types');
$printSection($typesTable['array_object']);
diff --git a/tests/Maker/MakeEntityTest.php b/tests/Maker/MakeEntityTest.php
index 1b5156318..fbe885990 100644
--- a/tests/Maker/MakeEntityTest.php
+++ b/tests/Maker/MakeEntityTest.php
@@ -74,6 +74,40 @@ public function getTestDetails(): \Generator
}),
];
+ yield 'it_only_shows_supported_types' => [$this->createMakeEntityTest()
+ ->run(function (MakerTestRunner $runner) {
+ $output = $runner->runMaker([
+ // entity class name
+ 'Developer',
+ // property name
+ 'keyboards',
+ // field type
+ '?',
+ // use default type
+ '',
+ // default length
+ '',
+ // nullable
+ '',
+ // no more properties
+ '',
+ ]);
+
+ self::assertStringContainsString('Main Types', $output);
+ self::assertStringContainsString('* string or ascii_string', $output);
+ self::assertStringContainsString('* ManyToOne', $output);
+
+ // get the dependencies installed in the test project (tmp/cache/TEST)
+ $installedVersions = require $runner->getPath('vendor/composer/installed.php');
+
+ if (!str_starts_with($installedVersions['versions']['doctrine/dbal']['version'], '3.')) {
+ self::assertStringNotContainsString('* object', $output);
+ } else {
+ self::assertStringContainsString('* object', $output);
+ }
+ }),
+ ];
+
yield 'it_creates_a_new_class_and_api_resource' => [$this->createMakeEntityTest()
->addExtraDependencies('api')
->run(function (MakerTestRunner $runner) {